mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
* refactor: stream records through sqlitex and the collector A row that failed to scan was logged at debug and dropped, so it never counted toward partial; it now reaches Collector.Fail. Every SQLite open goes through sqlitex with options instead of a bool, and extractors add records as they read them. * refactor: read SQLite rows with plain loops EachRow hid each extractor's loop and its skip rule behind two callbacks; every extractor now opens, queries, and walks its own rows, so the control flow reads top to bottom. * refactor(browser): drop the memoizing key closures Firefox derives its key once before the login loop, and Yandex loads its data key at the first row, so the state sits in plain variables where the loop uses it instead of inside a closure. * fix(safari): report unreadable localStorage origins A broken origin, database or row was only logged at debug level, so it never counted toward a partial result.
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package firefox
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/browser"
|
|
"github.com/moond4rk/hackbrowserdata/internal/crypto"
|
|
"github.com/moond4rk/hackbrowserdata/internal/record"
|
|
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
|
)
|
|
|
|
func decryptPBE(encoded string, masterKey []byte) ([]byte, error) {
|
|
raw, err := base64.StdEncoding.DecodeString(encoded)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("base64 decode: %w", err)
|
|
}
|
|
pbe, err := crypto.NewASN1PBE(raw)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("parse asn1 pbe: %w", err)
|
|
}
|
|
plaintext, err := pbe.Decrypt(masterKey)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("decrypt: %w", err)
|
|
}
|
|
return plaintext, nil
|
|
}
|
|
|
|
// extractPasswords derives the key only when there is a login; without one the logins export with empty secrets.
|
|
func extractPasswords(masterKey func() ([]byte, error), path string, out browser.Collector) error {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
logins := gjson.GetBytes(data, "logins").Array()
|
|
if len(logins) == 0 {
|
|
return nil
|
|
}
|
|
key, err := masterKey()
|
|
if err != nil {
|
|
out.Fail(fmt.Errorf("master key: %w", err))
|
|
}
|
|
|
|
for _, value := range logins {
|
|
url := value.Get("formSubmitURL").String()
|
|
if url == "" {
|
|
url = value.Get("hostname").String()
|
|
}
|
|
|
|
user, err := decryptPBE(value.Get("encryptedUsername").String(), key)
|
|
if err != nil {
|
|
out.Fail(fmt.Errorf("decrypt username for %s: %w", url, err))
|
|
}
|
|
password, err := decryptPBE(value.Get("encryptedPassword").String(), key)
|
|
if err != nil {
|
|
out.Fail(fmt.Errorf("decrypt password for %s: %w", url, err))
|
|
}
|
|
|
|
out.Add(&record.Login{
|
|
URL: url,
|
|
Username: string(user),
|
|
Password: string(password),
|
|
CreatedAt: timeconv.UnixMilli(value.Get("timeCreated").Int()),
|
|
Store: record.StoreLocal,
|
|
})
|
|
}
|
|
return nil
|
|
}
|