mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
1ec2781131
* feat: add Firefox extract methods and complete data model fields Firefox extract methods: - extractPasswords: JSON + ASN1PBE decryption via decryptPBE helper - extractCookies: SQLite, plaintext (no encryption), journalOff - extractHistories: SQLite, visit count ASC sort (matches old behavior) - extractDownloads: SQLite, moz_annos JOIN with JSON content parsing - extractBookmarks: SQLite, moz_bookmarks JOIN moz_places - extractExtensions: JSON, filter by location=app-profile - extractLocalStorage: SQLite webappsstore2, reversed originKey parsing Complete data model fields (union of Chromium and Firefox): - CookieEntry: add HasExpire, IsPersistent - DownloadEntry: add MimeType - CreditCardEntry: add NickName, Address - ExtensionEntry: add HomepageURL, Enabled Update Chromium extractors to populate new fields: - extract_cookie.go: fill HasExpire, IsPersistent - extract_download.go: SELECT and fill mime_type - extract_creditcard.go: SELECT nickname, billing_address_id - extract_extension.go: fill HomepageURL, Enabled (state==1) Tests: - Full test coverage for all 7 Firefox extract functions - Password test uses known ASN1PBE test vectors from crypto package - Table-driven tests for parseOriginKey - Updated Chromium tests for new fields * fix: add COALESCE for nullable bookmark title in Firefox query Firefox moz_bookmarks.title can be NULL (PR #500 fixed this in old code). Add COALESCE to handle NULL gracefully in SQL instead of relying on driver-specific NULL→string conversion behavior. * fix: enable journalOff for all Firefox SQLite extractors and populate cookie flags - Set journalOff=true for extract_history, extract_download, extract_bookmark (Firefox databases require PRAGMA journal_mode=off to avoid lock errors) - Populate HasExpire and IsPersistent for Firefox cookies (derived from expiry>0) - Add test assertions for HasExpire/IsPersistent in both Chromium and Firefox
91 lines
2.3 KiB
Go
91 lines
2.3 KiB
Go
package chromium
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestExtractCookies(t *testing.T) {
|
|
path := createTestDB(t, "Cookies", cookiesSchema,
|
|
insertCookie("session", ".old.com", "/", "", 13340000000000000, 13350000000000000, 1, 1),
|
|
insertCookie("token", ".new.com", "/api", "", 13360000000000000, 13370000000000000, 1, 0),
|
|
)
|
|
|
|
got, err := extractCookies(nil, path)
|
|
require.NoError(t, err)
|
|
require.Len(t, got, 2)
|
|
|
|
// Verify sort order: creation time descending (newest first)
|
|
assert.Equal(t, ".new.com", got[0].Host)
|
|
assert.Equal(t, ".old.com", got[1].Host)
|
|
|
|
// Verify field mapping
|
|
assert.Equal(t, "token", got[0].Name)
|
|
assert.Equal(t, "/api", got[0].Path)
|
|
assert.True(t, got[0].IsSecure)
|
|
assert.False(t, got[0].IsHTTPOnly)
|
|
assert.True(t, got[0].HasExpire)
|
|
assert.True(t, got[0].IsPersistent)
|
|
assert.False(t, got[0].CreatedAt.IsZero())
|
|
assert.True(t, got[0].ExpireAt.After(got[0].CreatedAt))
|
|
assert.True(t, got[1].IsHTTPOnly)
|
|
}
|
|
|
|
func TestStripCookieHash(t *testing.T) {
|
|
googleHash := sha256.Sum256([]byte(".google.com"))
|
|
shopifyHash := sha256.Sum256([]byte(".shopify.com"))
|
|
|
|
tests := []struct {
|
|
name string
|
|
value []byte
|
|
hostKey string
|
|
want string
|
|
}{
|
|
{
|
|
name: "Chrome 130+ strips SHA256 prefix",
|
|
value: append(googleHash[:], []byte("GA1.3.240937927.1770097858")...),
|
|
hostKey: ".google.com",
|
|
want: "GA1.3.240937927.1770097858",
|
|
},
|
|
{
|
|
name: "Chrome 130+ empty original value",
|
|
value: shopifyHash[:],
|
|
hostKey: ".shopify.com",
|
|
want: "",
|
|
},
|
|
{
|
|
name: "older Chrome no prefix",
|
|
value: []byte("plain_cookie_value"),
|
|
hostKey: ".example.com",
|
|
want: "plain_cookie_value",
|
|
},
|
|
{
|
|
name: "short value unchanged",
|
|
value: []byte("short"),
|
|
hostKey: ".example.com",
|
|
want: "short",
|
|
},
|
|
{
|
|
name: "host mismatch not stripped",
|
|
value: append(googleHash[:], []byte("value")...),
|
|
hostKey: ".other.com",
|
|
want: string(append(googleHash[:], []byte("value")...)),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := stripCookieHash(tt.value, tt.hostKey)
|
|
assert.Equal(t, tt.want, string(got))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestStripCookieHash_NilValue(t *testing.T) {
|
|
got := stripCookieHash(nil, ".example.com")
|
|
assert.Nil(t, got)
|
|
}
|