mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
dump, dumpkeys, archive, restore, and list now run on the app stages, so cmd's old path goes away. archive writes manifest.json and restore reads it, falling back to today's layout for older archives. Windows and macOS smoke matched today's output apart from the planned changes.
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/browser"
|
|
"github.com/moond4rk/hackbrowserdata/internal/browser/chromium"
|
|
"github.com/moond4rk/hackbrowserdata/internal/log"
|
|
"github.com/moond4rk/hackbrowserdata/internal/masterkey"
|
|
"github.com/moond4rk/hackbrowserdata/internal/snapshot"
|
|
)
|
|
|
|
// DumpKeys retrieves each Chromium user data dir's keys for keys.json, capturing only its Local State. A dir whose
|
|
// keys partly fail keeps the rest, because a v20 failure must not cost a usable v10 key; a dir with none is left out.
|
|
func DumpKeys(ctx context.Context, d Discovery, req Request) masterkey.Dump {
|
|
return dumpKeysWith(ctx, d, machineKeys(loginKeychain(req)))
|
|
}
|
|
|
|
func dumpKeysWith(ctx context.Context, d Discovery, keys keySource) masterkey.Dump {
|
|
dump := masterkey.NewDump()
|
|
for _, dir := range d.Dirs {
|
|
if dir.Def.Base != browser.Chromium {
|
|
continue
|
|
}
|
|
set, err := retrieveKeys(ctx, dir, keys)
|
|
if err != nil {
|
|
status := "partial"
|
|
if len(set) == 0 {
|
|
status = "failed"
|
|
}
|
|
log.Warnf("dump-keys: %s %s: %v", dir.Def.Name, status, err)
|
|
}
|
|
if len(set) == 0 {
|
|
continue
|
|
}
|
|
v := masterkey.Vault{
|
|
Browser: dir.Def.ID,
|
|
Kind: chromium.VaultKind(dir.Def),
|
|
UserDataDir: dir.Path,
|
|
Profiles: profileNames(dir),
|
|
Keys: set,
|
|
}
|
|
if string(dir.ID) != dir.Def.ID {
|
|
v.ID = string(dir.ID)
|
|
}
|
|
dump.Vaults = append(dump.Vaults, v)
|
|
}
|
|
return dump
|
|
}
|
|
|
|
func retrieveKeys(ctx context.Context, dir browser.UserDataDir, keys keySource) (masterkey.Set, error) {
|
|
d, err := snapshot.Temp()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer closeSnapshot(d)
|
|
var files []snapshot.File
|
|
for _, src := range chromium.KeySources(dir) {
|
|
if f, ok := firstOnDisk(dir, browser.Profile{}, src); ok {
|
|
files = append(files, f)
|
|
}
|
|
}
|
|
if err := d.Capture(ctx, files); err != nil {
|
|
return nil, err
|
|
}
|
|
return keys(ctx, dir, d.Snapshot(string(dir.ID)))
|
|
}
|
|
|
|
func profileNames(dir browser.UserDataDir) []string {
|
|
names := make([]string, 0, len(dir.Profiles))
|
|
for _, p := range dir.Profiles {
|
|
names = append(names, p.Name)
|
|
}
|
|
return names
|
|
}
|