mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
refactor: redesign logging system for CLI-friendly output (#561)
* refactor: redesign logging system for CLI-friendly output * refactor: remove ANSI color support from logger * fix: address PR review feedback
This commit is contained in:
@@ -187,7 +187,6 @@ func (b *Browser) extractCategory(data *types.BrowserData, cat types.Category, m
|
||||
func discoverProfiles(userDataDir string, sources map[types.Category][]sourcePath) []string {
|
||||
entries, err := os.ReadDir(userDataDir)
|
||||
if err != nil {
|
||||
log.Debugf("read user data dir %s: %v", userDataDir, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ const defaultCookieQuery = `SELECT name, encrypted_value, host_key, path,
|
||||
has_expires, is_persistent FROM cookies`
|
||||
|
||||
func extractCookies(masterKey []byte, path string) ([]types.CookieEntry, error) {
|
||||
var decryptFails int
|
||||
var lastErr error
|
||||
cookies, err := sqliteutil.QueryRows(path, false, defaultCookieQuery,
|
||||
func(rows *sql.Rows) (types.CookieEntry, error) {
|
||||
var (
|
||||
@@ -33,7 +35,8 @@ func extractCookies(masterKey []byte, path string) ([]types.CookieEntry, error)
|
||||
|
||||
value, err := decryptValue(masterKey, encryptedValue)
|
||||
if err != nil {
|
||||
log.Debugf("decrypt cookie %s on %s: %v", name, host, err)
|
||||
decryptFails++
|
||||
lastErr = err
|
||||
}
|
||||
value = stripCookieHash(value, host)
|
||||
return types.CookieEntry{
|
||||
@@ -52,6 +55,9 @@ func extractCookies(masterKey []byte, path string) ([]types.CookieEntry, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if decryptFails > 0 {
|
||||
log.Debugf("decrypt cookies: %d failed: %v", decryptFails, lastErr)
|
||||
}
|
||||
|
||||
sort.Slice(cookies, func(i, j int) bool {
|
||||
return cookies[i].CreatedAt.After(cookies[j].CreatedAt)
|
||||
|
||||
@@ -12,7 +12,9 @@ const defaultCreditCardQuery = `SELECT COALESCE(guid, ''), name_on_card, expirat
|
||||
card_number_encrypted, COALESCE(nickname, ''), COALESCE(billing_address_id, '') FROM credit_cards`
|
||||
|
||||
func extractCreditCards(masterKey []byte, path string) ([]types.CreditCardEntry, error) {
|
||||
return sqliteutil.QueryRows(path, false, defaultCreditCardQuery,
|
||||
var decryptFails int
|
||||
var lastErr error
|
||||
cards, err := sqliteutil.QueryRows(path, false, defaultCreditCardQuery,
|
||||
func(rows *sql.Rows) (types.CreditCardEntry, error) {
|
||||
var guid, name, month, year, nickname, address string
|
||||
var encNumber []byte
|
||||
@@ -21,7 +23,8 @@ func extractCreditCards(masterKey []byte, path string) ([]types.CreditCardEntry,
|
||||
}
|
||||
number, err := decryptValue(masterKey, encNumber)
|
||||
if err != nil {
|
||||
log.Debugf("decrypt credit card for %s: %v", name, err)
|
||||
decryptFails++
|
||||
lastErr = err
|
||||
}
|
||||
return types.CreditCardEntry{
|
||||
GUID: guid,
|
||||
@@ -33,4 +36,11 @@ func extractCreditCards(masterKey []byte, path string) ([]types.CreditCardEntry,
|
||||
Address: address,
|
||||
}, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if decryptFails > 0 {
|
||||
log.Debugf("decrypt credit cards: %d failed: %v", decryptFails, lastErr)
|
||||
}
|
||||
return cards, nil
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ func extractPasswords(masterKey []byte, path string) ([]types.LoginEntry, error)
|
||||
}
|
||||
|
||||
func extractPasswordsWithQuery(masterKey []byte, path, query string) ([]types.LoginEntry, error) {
|
||||
var decryptFails int
|
||||
var lastErr error
|
||||
logins, err := sqliteutil.QueryRows(path, false, query,
|
||||
func(rows *sql.Rows) (types.LoginEntry, error) {
|
||||
var url, username string
|
||||
@@ -26,7 +28,8 @@ func extractPasswordsWithQuery(masterKey []byte, path, query string) ([]types.Lo
|
||||
}
|
||||
password, err := decryptValue(masterKey, pwd)
|
||||
if err != nil {
|
||||
log.Debugf("decrypt password for %s: %v", url, err)
|
||||
decryptFails++
|
||||
lastErr = err
|
||||
}
|
||||
return types.LoginEntry{
|
||||
URL: url,
|
||||
@@ -38,6 +41,9 @@ func extractPasswordsWithQuery(masterKey []byte, path, query string) ([]types.Lo
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if decryptFails > 0 {
|
||||
log.Debugf("decrypt passwords: %d failed: %v", decryptFails, lastErr)
|
||||
}
|
||||
|
||||
sort.Slice(logins, func(i, j int) bool {
|
||||
return logins[i].CreatedAt.After(logins[j].CreatedAt)
|
||||
|
||||
@@ -37,6 +37,8 @@ func extractPasswords(masterKey []byte, path string) ([]types.LoginEntry, error)
|
||||
}
|
||||
|
||||
var logins []types.LoginEntry
|
||||
var decryptFails int
|
||||
var lastErr error
|
||||
for _, v := range gjson.GetBytes(data, "logins").Array() {
|
||||
url := v.Get("formSubmitURL").String()
|
||||
if url == "" {
|
||||
@@ -45,11 +47,13 @@ func extractPasswords(masterKey []byte, path string) ([]types.LoginEntry, error)
|
||||
|
||||
user, err := decryptPBE(v.Get("encryptedUsername").String(), masterKey)
|
||||
if err != nil {
|
||||
log.Debugf("decrypt firefox username for %s: %v", url, err)
|
||||
decryptFails++
|
||||
lastErr = err
|
||||
}
|
||||
pwd, err := decryptPBE(v.Get("encryptedPassword").String(), masterKey)
|
||||
if err != nil {
|
||||
log.Debugf("decrypt firefox password for %s: %v", url, err)
|
||||
decryptFails++
|
||||
lastErr = err
|
||||
}
|
||||
|
||||
logins = append(logins, types.LoginEntry{
|
||||
@@ -59,6 +63,9 @@ func extractPasswords(masterKey []byte, path string) ([]types.LoginEntry, error)
|
||||
CreatedAt: timestamp(v.Get("timeCreated").Int() / 1000),
|
||||
})
|
||||
}
|
||||
if decryptFails > 0 {
|
||||
log.Debugf("decrypt firefox login fields: %d failed: %v", decryptFails, lastErr)
|
||||
}
|
||||
|
||||
sort.Slice(logins, func(i, j int) bool {
|
||||
return logins[i].CreatedAt.After(logins[j].CreatedAt)
|
||||
|
||||
@@ -188,7 +188,6 @@ type resolvedPath struct {
|
||||
func discoverProfiles(userDataDir string, sources map[types.Category][]sourcePath) []string {
|
||||
entries, err := os.ReadDir(userDataDir)
|
||||
if err != nil {
|
||||
log.Debugf("read user data dir %s: %v", userDataDir, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user