mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
feat(masterkey): decrypt Chromium v12 portal keys (#707)
This commit is contained in:
1 parent
066dd15be1
commit
fe8a1bbabb
11 files changed
+398
-27
No files matched your search
@@ -32,6 +32,7 @@ const (
|
||||
type Platform struct {
|
||||
UserDataDirs []string // slash-separated, relative to the home directory; globs allowed
|
||||
SecretLabel string // macOS Keychain account / Linux Secret Service label; "" = none
|
||||
PortalAppID string // Linux: the app id whose XDG portal secret decrypts v12 values; "" = none
|
||||
Executable string // Windows: the program the ABE payload is injected into
|
||||
ExecutableFallbacks []string // Windows: program paths tried when the registry has no App Paths entry
|
||||
ABE masterkey.ABEKind
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/browser"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/masterkey"
|
||||
@@ -164,6 +165,7 @@ func KeyLocator(dir browser.UserDataDir, dirSnapshot snapshot.Snapshot) (masterk
|
||||
platform := dir.Browser.Platform()
|
||||
locator := masterkey.Locator{
|
||||
SecretLabel: platform.SecretLabel, Executable: platform.Executable, ExecutableFallbacks: platform.ExecutableFallbacks, ABE: platform.ABE,
|
||||
PortalAppID: portalAppID(dir.Path, platform.PortalAppID),
|
||||
}
|
||||
path, err := dirSnapshot.Path(localState.Path)
|
||||
switch {
|
||||
@@ -175,6 +177,25 @@ func KeyLocator(dir browser.UserDataDir, dirSnapshot snapshot.Snapshot) (masterk
|
||||
return locator, nil
|
||||
}
|
||||
|
||||
// portalAppID is the v12 app id for a dir: a Flatpak install's id is fixed by its sandbox, taken from the
|
||||
// .var/app/<id>/ path, so it wins outright; otherwise the browser's registered id applies.
|
||||
func portalAppID(dirPath, registeredID string) string {
|
||||
if flatpak := flatpakAppID(dirPath); flatpak != "" {
|
||||
return flatpak
|
||||
}
|
||||
return registeredID
|
||||
}
|
||||
|
||||
// flatpakAppID returns the Flatpak application id in a path like ".../.var/app/<id>/config/...", or "" if absent.
|
||||
func flatpakAppID(dirPath string) string {
|
||||
_, after, found := strings.Cut(filepath.ToSlash(dirPath), ".var/app/")
|
||||
if !found {
|
||||
return ""
|
||||
}
|
||||
id, _, _ := strings.Cut(after, "/")
|
||||
return id
|
||||
}
|
||||
|
||||
// KeySources are the files KeyLocator reads from a snapshot.
|
||||
func KeySources() []browser.Source {
|
||||
return []browser.Source{localState}
|
||||
|
||||
@@ -166,3 +166,27 @@ func TestKeyLocator(t *testing.T) {
|
||||
require.NoError(t, err, "a user data dir without Local State still has keys on macOS and Linux")
|
||||
assert.Empty(t, locator.LocalState)
|
||||
}
|
||||
|
||||
func TestPortalAppID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
dirPath string
|
||||
registeredID string
|
||||
want string
|
||||
}{
|
||||
{name: "deb install uses the registered id", dirPath: "/home/u/.config/google-chrome", registeredID: "com.google.Chrome", want: "com.google.Chrome"},
|
||||
{
|
||||
// a Flatpak sandbox fixes the app id, so the path id wins over the table id and never falls back to it.
|
||||
name: "flatpak id overrides the registered id", registeredID: "org.chromium.Chromium",
|
||||
dirPath: "/home/u/.var/app/io.github.ungoogled_software.ungoogled_chromium/config/chromium",
|
||||
want: "io.github.ungoogled_software.ungoogled_chromium",
|
||||
},
|
||||
{name: "no registered id leaves only the flatpak id", dirPath: "/home/u/.var/app/com.brave.Browser/config/BraveSoftware/Brave-Browser", want: "com.brave.Browser"},
|
||||
{name: "no portal id for a browser without one", dirPath: "/home/u/.config/microsoft-edge", want: ""},
|
||||
}
|
||||
for _, testCase := range tests {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
assert.Equal(t, testCase.want, portalAppID(testCase.dirPath, testCase.registeredID))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,10 @@ func decryptValue(masterKeys masterkey.Set, ciphertext []byte) ([]byte, error) {
|
||||
return decryptCBC(masterKeys[masterkey.V10], ciphertext)
|
||||
case masterkey.V11:
|
||||
return decryptCBC(masterKeys[masterkey.V11], ciphertext)
|
||||
case masterkey.V12:
|
||||
return decryptGCM(masterKeys[masterkey.V12], ciphertext)
|
||||
case masterkey.V20:
|
||||
return decryptGCM(masterKeys[masterkey.V20], ciphertext)
|
||||
case versionV12:
|
||||
return nil, fmt.Errorf("unsupported cipher version v12 (Chromium SecretPortal / Flatpak; not yet implemented)")
|
||||
case unversioned:
|
||||
return masterkey.DecryptDPAPI(ciphertext)
|
||||
default:
|
||||
@@ -40,8 +40,6 @@ func decryptValue(masterKeys masterkey.Set, ciphertext []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
const (
|
||||
// versionV12 is recognized only to report a known gap: v12 is not implemented yet.
|
||||
versionV12 masterkey.Version = "v12"
|
||||
// unversioned is a value without a version prefix, which Chromium on Windows sealed with DPAPI.
|
||||
unversioned masterkey.Version = ""
|
||||
|
||||
@@ -53,7 +51,7 @@ func detectVersion(ciphertext []byte) masterkey.Version {
|
||||
return unversioned
|
||||
}
|
||||
switch version := masterkey.Version(ciphertext[:versionPrefixLength]); version {
|
||||
case masterkey.V10, masterkey.V11, masterkey.V20, versionV12:
|
||||
case masterkey.V10, masterkey.V11, masterkey.V12, masterkey.V20:
|
||||
return version
|
||||
default:
|
||||
return unversioned
|
||||
|
||||
@@ -68,6 +68,33 @@ func TestDecryptValue_V10_CrossHostGCM(t *testing.T) {
|
||||
assert.Equal(t, plaintext, got)
|
||||
}
|
||||
|
||||
// TestDecryptValue_V12 seals a value as Chromium's SecretPortalKeyProvider does and decrypts it via the V12 slot.
|
||||
func TestDecryptValue_V12(t *testing.T) {
|
||||
key := []byte("0123456789abcdef0123456789abcdef") // 32-byte HKDF-SHA256 output
|
||||
plaintext := []byte("portal_cookie_value")
|
||||
nonce := []byte("v12_nonce_12")
|
||||
gcm, err := crypto.AESGCMEncrypt(key, nonce, plaintext)
|
||||
require.NoError(t, err)
|
||||
ciphertext := append([]byte("v12"), append(nonce, gcm...)...)
|
||||
|
||||
t.Run("decrypts via the V12 slot", func(t *testing.T) {
|
||||
got, err := decryptValue(masterkey.Set{masterkey.V12: key}, ciphertext)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, plaintext, got)
|
||||
})
|
||||
|
||||
t.Run("v12 routes to its own key, not V20", func(t *testing.T) {
|
||||
wrong := bytes.Repeat([]byte{0x99}, 32)
|
||||
_, err := decryptValue(masterkey.Set{masterkey.V12: wrong, masterkey.V20: key}, ciphertext)
|
||||
require.Error(t, err, "the GCM tag must fail when the V12 slot holds the wrong key")
|
||||
})
|
||||
|
||||
t.Run("missing V12 key errors", func(t *testing.T) {
|
||||
_, err := decryptValue(masterkey.Set{masterkey.V10: key}, ciphertext)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
// TestDecryptValue_V10_V11_SlotSeparation is #578 on Linux: v10 and v11 values each route to their own key.
|
||||
func TestDecryptValue_V10_V11_SlotSeparation(t *testing.T) {
|
||||
v10Key := bytes.Repeat([]byte{0x10}, 16) // V10 slot key (peanuts-derived kV10Key)
|
||||
@@ -160,7 +187,7 @@ func TestDetectVersion(t *testing.T) {
|
||||
}{
|
||||
{"v10 prefix", []byte("v10" + "encrypted_data"), masterkey.V10},
|
||||
{"v11 prefix", []byte("v11" + "encrypted_data"), masterkey.V11},
|
||||
{"v12 prefix", []byte("v12" + "encrypted_data"), versionV12},
|
||||
{"v12 prefix", []byte("v12" + "encrypted_data"), masterkey.V12},
|
||||
{"v20 prefix", []byte("v20" + "encrypted_data"), masterkey.V20},
|
||||
{"no prefix (DPAPI)", []byte{0x01, 0x00, 0x00, 0x00}, unversioned},
|
||||
{"short input", []byte{0x01, 0x02}, unversioned},
|
||||
|
||||
@@ -15,6 +15,7 @@ var browsers = []Browser{
|
||||
Linux: Platform{
|
||||
UserDataDirs: []string{".config/google-chrome"},
|
||||
SecretLabel: "Chrome Safe Storage",
|
||||
PortalAppID: "com.google.Chrome",
|
||||
},
|
||||
Windows: Platform{
|
||||
UserDataDirs: []string{"AppData/Local/Google/Chrome/User Data"},
|
||||
@@ -60,6 +61,7 @@ var browsers = []Browser{
|
||||
Linux: Platform{
|
||||
UserDataDirs: []string{".config/chromium"},
|
||||
SecretLabel: "Chromium Safe Storage",
|
||||
PortalAppID: "org.chromium.Chromium",
|
||||
},
|
||||
Windows: Platform{
|
||||
UserDataDirs: []string{"AppData/Local/Chromium/User Data"},
|
||||
@@ -76,6 +78,7 @@ var browsers = []Browser{
|
||||
Linux: Platform{
|
||||
UserDataDirs: []string{".config/google-chrome-beta"},
|
||||
SecretLabel: "Chrome Safe Storage",
|
||||
PortalAppID: "com.google.Chrome.beta",
|
||||
},
|
||||
Windows: Platform{
|
||||
UserDataDirs: []string{"AppData/Local/Google/Chrome Beta/User Data"},
|
||||
@@ -170,6 +173,7 @@ var browsers = []Browser{
|
||||
Linux: Platform{
|
||||
UserDataDirs: []string{".config/BraveSoftware/Brave-Browser"},
|
||||
SecretLabel: "Brave Safe Storage",
|
||||
PortalAppID: "com.brave.Browser",
|
||||
},
|
||||
Windows: Platform{
|
||||
UserDataDirs: []string{"AppData/Local/BraveSoftware/Brave-Browser/User Data"},
|
||||
|
||||
Reference in new issue
Block a user