mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
refactor: merge the browser tables into internal/browser (#654)
One Def per browser carries every OS's user data dirs, keychain label, and Windows ABE target, so the per-OS lists and the abeTargets join go away and today's configs derive from it; a test parsing com_iid.c keeps the payload's table in step with the ABE rows.
This commit is contained in:
1 parent
0b8cc23216
commit
b655afd054
17 files changed
+432
-424
No files matched your search
@@ -0,0 +1,54 @@
|
||||
// Package browser describes the browsers HBD knows: one Def per browser, with how it appears on each OS.
|
||||
package browser
|
||||
|
||||
import "github.com/moond4rk/hackbrowserdata/internal/masterkey"
|
||||
|
||||
// Def is one browser HBD knows. ID is the -b value and the keys.json vault key; Name is stamped on every record.
|
||||
type Def struct {
|
||||
ID string
|
||||
Name string
|
||||
Base Base
|
||||
|
||||
Darwin Platform
|
||||
Linux Platform
|
||||
Windows Platform
|
||||
}
|
||||
|
||||
// Base is what a browser is built on; it selects the base package and the key path.
|
||||
type Base int
|
||||
|
||||
const (
|
||||
Chromium Base = iota + 1
|
||||
Firefox
|
||||
Safari
|
||||
)
|
||||
|
||||
// Platform is how one browser appears on one OS; a Platform without UserDataDirs means the OS is not supported.
|
||||
type Platform struct {
|
||||
UserDataDirs []string // slash-separated, relative to the home directory; globs allowed
|
||||
KeychainLabel string // macOS Keychain account / Linux Secret Service label; "" = none
|
||||
Exe string // Windows: the program the ABE payload is injected into
|
||||
ExeFallbacks []string // Windows: program paths tried when the registry has no App Paths entry
|
||||
ABE masterkey.ABEKind
|
||||
}
|
||||
|
||||
// Supported returns the browsers of the running OS, in table order.
|
||||
func Supported() []Def {
|
||||
var out []Def
|
||||
for _, d := range defs {
|
||||
if len(d.Platform().UserDataDirs) > 0 {
|
||||
out = append(out, d)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Lookup finds a browser by ID in the whole table, whatever the running OS, so restore resolves another host's vaults.
|
||||
func Lookup(id string) (Def, bool) {
|
||||
for _, d := range defs {
|
||||
if d.ID == id {
|
||||
return d, true
|
||||
}
|
||||
}
|
||||
return Def{}, false
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package browser
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/masterkey"
|
||||
)
|
||||
|
||||
var platformOf = map[string]func(Def) Platform{
|
||||
"darwin": func(d Def) Platform { return d.Darwin },
|
||||
"linux": func(d Def) Platform { return d.Linux },
|
||||
"windows": func(d Def) Platform { return d.Windows },
|
||||
}
|
||||
|
||||
func idsOn(platform func(Def) Platform) []string {
|
||||
var ids []string
|
||||
for _, d := range defs {
|
||||
if len(platform(d).UserDataDirs) > 0 {
|
||||
ids = append(ids, d.ID)
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Discovery order is output order: reordering the table reorders the records in every output file.
|
||||
func TestTableOrderPerOS(t *testing.T) {
|
||||
want := map[string][]string{
|
||||
"darwin": {
|
||||
"chrome", "edge", "chromium", "chrome-beta", "opera", "opera-gx", "vivaldi", "coccoc", "brave", "yandex", "arc",
|
||||
"firefox", "safari",
|
||||
},
|
||||
"linux": {"chrome", "edge", "chromium", "chrome-beta", "opera", "vivaldi", "brave", "firefox"},
|
||||
"windows": {
|
||||
"chrome", "edge", "chromium", "chrome-beta", "opera", "opera-gx", "vought", "vivaldi", "coccoc", "brave", "yandex",
|
||||
"360x", "360", "qq", "dc", "sogou", "arc", "duckduckgo", "firefox",
|
||||
},
|
||||
}
|
||||
for goos, platform := range platformOf {
|
||||
assert.Equal(t, want[goos], idsOn(platform), goos)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupported_ListsThisOSRowsInTableOrder(t *testing.T) {
|
||||
var ids []string
|
||||
for _, d := range Supported() {
|
||||
ids = append(ids, d.ID)
|
||||
}
|
||||
assert.Equal(t, idsOn(Def.Platform), ids)
|
||||
}
|
||||
|
||||
func TestLookup_FindsEveryRowWhateverTheOS(t *testing.T) {
|
||||
for _, want := range defs {
|
||||
got, ok := Lookup(want.ID)
|
||||
require.True(t, ok, want.ID)
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
_, ok := Lookup("netscape")
|
||||
assert.False(t, ok)
|
||||
}
|
||||
|
||||
func TestTableRows(t *testing.T) {
|
||||
seen := make(map[string]bool)
|
||||
for _, d := range defs {
|
||||
assert.NotEmpty(t, d.ID)
|
||||
assert.Falsef(t, seen[d.ID], "duplicate ID %q", d.ID)
|
||||
seen[d.ID] = true
|
||||
assert.NotEmpty(t, d.Name, d.ID)
|
||||
assert.Contains(t, []Base{Chromium, Firefox, Safari}, d.Base, d.ID)
|
||||
|
||||
for goos, platform := range platformOf {
|
||||
for _, dir := range platform(d).UserDataDirs {
|
||||
assert.Truef(t, dir != "" && !path.IsAbs(dir) && !strings.Contains(dir, `\`),
|
||||
"%s %s: user data dir %q must be slash-separated and relative to the home dir", d.ID, goos, dir)
|
||||
}
|
||||
}
|
||||
|
||||
w := d.Windows
|
||||
if w.ABE == masterkey.ABENone {
|
||||
assert.Emptyf(t, w.Exe, "%s: an executable is only used by ABE", d.ID)
|
||||
assert.Emptyf(t, w.ExeFallbacks, "%s: executable fallbacks are only used by ABE", d.ID)
|
||||
continue
|
||||
}
|
||||
assert.Equal(t, Chromium, d.Base, d.ID)
|
||||
assert.NotEmpty(t, w.Exe, d.ID)
|
||||
for _, fallback := range w.ExeFallbacks {
|
||||
assert.Truef(t, strings.HasSuffix(strings.ToLower(fallback), `\`+strings.ToLower(w.Exe)),
|
||||
"%s: fallback %q does not name %s", d.ID, fallback, w.Exe)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The payload looks a browser up by its executable inside the browser process, so its C table is the other half of each
|
||||
// ABE row. It may list browsers the Go table does not.
|
||||
func TestABERowsMatchPayloadTable(t *testing.T) {
|
||||
src, err := os.ReadFile("../../crypto/windows/abe_native/com_iid.c")
|
||||
require.NoError(t, err)
|
||||
|
||||
kinds := map[string]masterkey.ABEKind{
|
||||
"BROWSER_CHROME_BASE": masterkey.ABEChromeBase,
|
||||
"BROWSER_EDGE": masterkey.ABEEdge,
|
||||
"BROWSER_AVAST": masterkey.ABEAvast,
|
||||
}
|
||||
payload := make(map[string]masterkey.ABEKind)
|
||||
for _, m := range regexp.MustCompile(`"([^"]+\.exe)",\s*(BROWSER_\w+)`).FindAllStringSubmatch(string(src), -1) {
|
||||
kind, ok := kinds[m[2]]
|
||||
require.Truef(t, ok, "unknown payload browser kind %s", m[2])
|
||||
exe := strings.ToLower(m[1])
|
||||
if _, dup := payload[exe]; !dup {
|
||||
payload[exe] = kind
|
||||
}
|
||||
}
|
||||
require.NotEmpty(t, payload, "no rows parsed from com_iid.c")
|
||||
|
||||
for _, d := range defs {
|
||||
w := d.Windows
|
||||
if w.ABE == masterkey.ABENone {
|
||||
continue
|
||||
}
|
||||
kind, ok := payload[strings.ToLower(w.Exe)]
|
||||
if assert.Truef(t, ok, "%s: com_iid.c has no row for %s", d.ID, w.Exe) {
|
||||
assert.Equalf(t, w.ABE, kind, "%s: com_iid.c dispatches %s as another ABE kind", d.ID, w.Exe)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
//go:build darwin
|
||||
|
||||
package browser
|
||||
|
||||
// Platform returns the running OS's entry.
|
||||
func (d Def) Platform() Platform { return d.Darwin }
|
||||
@@ -0,0 +1,6 @@
|
||||
//go:build linux
|
||||
|
||||
package browser
|
||||
|
||||
// Platform returns the running OS's entry.
|
||||
func (d Def) Platform() Platform { return d.Linux }
|
||||
@@ -0,0 +1,6 @@
|
||||
//go:build windows
|
||||
|
||||
package browser
|
||||
|
||||
// Platform returns the running OS's entry.
|
||||
func (d Def) Platform() Platform { return d.Windows }
|
||||
@@ -0,0 +1,151 @@
|
||||
package browser
|
||||
|
||||
import "github.com/moond4rk/hackbrowserdata/internal/masterkey"
|
||||
|
||||
// defs is in discovery order, which is also the order records reach the output files.
|
||||
var defs = []Def{
|
||||
{
|
||||
ID: "chrome", Name: "Chrome", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Google/Chrome"}, KeychainLabel: "Chrome"},
|
||||
Linux: Platform{UserDataDirs: []string{".config/google-chrome"}, KeychainLabel: "Chrome Safe Storage"},
|
||||
Windows: Platform{
|
||||
UserDataDirs: []string{"AppData/Local/Google/Chrome/User Data"},
|
||||
Exe: "chrome.exe",
|
||||
ExeFallbacks: []string{
|
||||
`%ProgramFiles%\Google\Chrome\Application\chrome.exe`,
|
||||
`%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe`,
|
||||
`%LocalAppData%\Google\Chrome\Application\chrome.exe`,
|
||||
},
|
||||
ABE: masterkey.ABEChromeBase,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "edge", Name: "Microsoft Edge", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Microsoft Edge"}, KeychainLabel: "Microsoft Edge"},
|
||||
Linux: Platform{UserDataDirs: []string{".config/microsoft-edge"}, KeychainLabel: "Chromium Safe Storage"},
|
||||
Windows: Platform{
|
||||
UserDataDirs: []string{"AppData/Local/Microsoft/Edge/User Data"},
|
||||
Exe: "msedge.exe",
|
||||
ExeFallbacks: []string{
|
||||
`%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe`,
|
||||
`%ProgramFiles%\Microsoft\Edge\Application\msedge.exe`,
|
||||
},
|
||||
ABE: masterkey.ABEEdge,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "chromium", Name: "Chromium", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Chromium"}, KeychainLabel: "Chromium"},
|
||||
Linux: Platform{UserDataDirs: []string{".config/chromium"}, KeychainLabel: "Chromium Safe Storage"},
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/Chromium/User Data"}},
|
||||
},
|
||||
{
|
||||
ID: "chrome-beta", Name: "Chrome Beta", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Google/Chrome Beta"}, KeychainLabel: "Chrome"},
|
||||
Linux: Platform{UserDataDirs: []string{".config/google-chrome-beta"}, KeychainLabel: "Chrome Safe Storage"},
|
||||
Windows: Platform{
|
||||
UserDataDirs: []string{"AppData/Local/Google/Chrome Beta/User Data"},
|
||||
Exe: "chrome.exe",
|
||||
ExeFallbacks: []string{
|
||||
`%ProgramFiles%\Google\Chrome Beta\Application\chrome.exe`,
|
||||
`%ProgramFiles(x86)%\Google\Chrome Beta\Application\chrome.exe`,
|
||||
`%LocalAppData%\Google\Chrome Beta\Application\chrome.exe`,
|
||||
},
|
||||
ABE: masterkey.ABEChromeBase,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "opera", Name: "Opera", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/com.operasoftware.Opera"}, KeychainLabel: "Opera"},
|
||||
Linux: Platform{UserDataDirs: []string{".config/opera"}, KeychainLabel: "Chromium Safe Storage"},
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Roaming/Opera Software/Opera Stable"}},
|
||||
},
|
||||
{
|
||||
ID: "opera-gx", Name: "OperaGX", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/com.operasoftware.OperaGX"}, KeychainLabel: "Opera"},
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Roaming/Opera Software/Opera GX Stable"}},
|
||||
},
|
||||
{
|
||||
ID: "vought", Name: "Browser from Vought", Base: Chromium,
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Roaming/Browser from Vought"}},
|
||||
},
|
||||
{
|
||||
ID: "vivaldi", Name: "Vivaldi", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Vivaldi"}, KeychainLabel: "Vivaldi"},
|
||||
Linux: Platform{UserDataDirs: []string{".config/vivaldi"}, KeychainLabel: "Chrome Safe Storage"},
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/Vivaldi/User Data"}},
|
||||
},
|
||||
{
|
||||
ID: "coccoc", Name: "CocCoc", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Coccoc"}, KeychainLabel: "CocCoc"},
|
||||
Windows: Platform{
|
||||
UserDataDirs: []string{"AppData/Local/CocCoc/Browser/User Data"},
|
||||
Exe: "browser.exe",
|
||||
ExeFallbacks: []string{
|
||||
`%ProgramFiles%\CocCoc\Browser\Application\browser.exe`,
|
||||
`%ProgramFiles(x86)%\CocCoc\Browser\Application\browser.exe`,
|
||||
`%LocalAppData%\CocCoc\Browser\Application\browser.exe`,
|
||||
},
|
||||
ABE: masterkey.ABEChromeBase,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "brave", Name: "Brave", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/BraveSoftware/Brave-Browser"}, KeychainLabel: "Brave"},
|
||||
Linux: Platform{UserDataDirs: []string{".config/BraveSoftware/Brave-Browser"}, KeychainLabel: "Brave Safe Storage"},
|
||||
Windows: Platform{
|
||||
UserDataDirs: []string{"AppData/Local/BraveSoftware/Brave-Browser/User Data"},
|
||||
Exe: "brave.exe",
|
||||
ExeFallbacks: []string{
|
||||
`%ProgramFiles%\BraveSoftware\Brave-Browser\Application\brave.exe`,
|
||||
`%ProgramFiles(x86)%\BraveSoftware\Brave-Browser\Application\brave.exe`,
|
||||
`%LocalAppData%\BraveSoftware\Brave-Browser\Application\brave.exe`,
|
||||
},
|
||||
ABE: masterkey.ABEChromeBase,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "yandex", Name: "Yandex", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Yandex/YandexBrowser"}, KeychainLabel: "Yandex"},
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/Yandex/YandexBrowser/User Data"}},
|
||||
},
|
||||
{
|
||||
ID: "360x", Name: "360 Speed X", Base: Chromium,
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/360ChromeX/Chrome/User Data"}},
|
||||
},
|
||||
{
|
||||
ID: "360", Name: "360 Speed", Base: Chromium,
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/360chrome/Chrome/User Data"}},
|
||||
},
|
||||
{
|
||||
ID: "qq", Name: "QQ", Base: Chromium,
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/Tencent/QQBrowser/User Data"}},
|
||||
},
|
||||
{
|
||||
ID: "dc", Name: "DC", Base: Chromium,
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/DCBrowser/User Data"}},
|
||||
},
|
||||
{
|
||||
ID: "sogou", Name: "Sogou", Base: Chromium,
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/Sogou/SogouExplorer/User Data"}},
|
||||
},
|
||||
{
|
||||
ID: "arc", Name: "Arc", Base: Chromium,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Arc/User Data"}, KeychainLabel: "Arc"},
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/Packages/TheBrowserCompany.Arc_*/LocalCache/Local/Arc/User Data"}},
|
||||
},
|
||||
{
|
||||
ID: "duckduckgo", Name: "DuckDuckGo", Base: Chromium,
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Local/Packages/DuckDuckGo.DesktopBrowser_*/LocalState/EBWebView"}},
|
||||
},
|
||||
{
|
||||
ID: "firefox", Name: "Firefox", Base: Firefox,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Firefox/Profiles"}},
|
||||
Linux: Platform{UserDataDirs: []string{".mozilla/firefox"}},
|
||||
Windows: Platform{UserDataDirs: []string{"AppData/Roaming/Mozilla/Firefox/Profiles"}},
|
||||
},
|
||||
{
|
||||
ID: "safari", Name: "Safari", Base: Safari,
|
||||
Darwin: Platform{UserDataDirs: []string{"Library/Safari"}},
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user