chrome-tools 1.1.12 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/chrome_abe_decrypt.exe +0 -0
- package/dist/bin/chrome_abe_decrypt.exe +0 -0
- package/dist/src/core/crypto.d.ts +14 -0
- package/dist/src/core/crypto.js +39 -0
- package/dist/src/core/platform/types.d.ts +12 -2
- package/dist/src/core/platform/win32.d.ts +3 -2
- package/dist/src/core/platform/win32.js +147 -12
- package/package.json +3 -1
- package/src/native/build.bat +31 -0
- package/src/native/chrome_abe_decrypt.c +336 -0
- package/src/native/chrome_abe_decrypt.exe +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -28,6 +28,20 @@ export declare function decryptValueBuffer(encryptedBlob: Buffer | Uint8Array |
|
|
|
28
28
|
* @returns The decrypted plaintext bytes, or a placeholder string.
|
|
29
29
|
*/
|
|
30
30
|
export declare function decryptValueBufferGcm(encryptedBlob: Buffer | Uint8Array | null | undefined, key: Buffer): Buffer | string;
|
|
31
|
+
/**
|
|
32
|
+
* Decrypts a Windows Chrome 127+ `v20` blob using AES-256-GCM.
|
|
33
|
+
*
|
|
34
|
+
* App-Bound Encryption uses the same AES-256-GCM layout as `v10`/`v11` but
|
|
35
|
+
* with a `"v20"` prefix and a key obtained from Chrome's Elevation Service
|
|
36
|
+
* (IElevator COM) instead of plain DPAPI.
|
|
37
|
+
*
|
|
38
|
+
* Layout: "v20" (3 bytes) + 12-byte nonce + ciphertext + 16-byte GCM tag
|
|
39
|
+
*
|
|
40
|
+
* @param encryptedBlob - The encrypted blob from the database.
|
|
41
|
+
* @param key - The 32-byte AES-256 key from ABE decryption.
|
|
42
|
+
* @returns The decrypted plaintext bytes, or a placeholder string.
|
|
43
|
+
*/
|
|
44
|
+
export declare function decryptValueBufferGcmV20(encryptedBlob: Buffer | Uint8Array | null | undefined, key: Buffer): Buffer | string;
|
|
31
45
|
/**
|
|
32
46
|
* Converts a Chrome/Webkit timestamp (microseconds since 1601-01-01)
|
|
33
47
|
* to a readable local Date string.
|
package/dist/src/core/crypto.js
CHANGED
|
@@ -83,6 +83,45 @@ export function decryptValueBufferGcm(encryptedBlob, key) {
|
|
|
83
83
|
return "<decryption failed>";
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Decrypts a Windows Chrome 127+ `v20` blob using AES-256-GCM.
|
|
88
|
+
*
|
|
89
|
+
* App-Bound Encryption uses the same AES-256-GCM layout as `v10`/`v11` but
|
|
90
|
+
* with a `"v20"` prefix and a key obtained from Chrome's Elevation Service
|
|
91
|
+
* (IElevator COM) instead of plain DPAPI.
|
|
92
|
+
*
|
|
93
|
+
* Layout: "v20" (3 bytes) + 12-byte nonce + ciphertext + 16-byte GCM tag
|
|
94
|
+
*
|
|
95
|
+
* @param encryptedBlob - The encrypted blob from the database.
|
|
96
|
+
* @param key - The 32-byte AES-256 key from ABE decryption.
|
|
97
|
+
* @returns The decrypted plaintext bytes, or a placeholder string.
|
|
98
|
+
*/
|
|
99
|
+
export function decryptValueBufferGcmV20(encryptedBlob, key) {
|
|
100
|
+
if (!encryptedBlob || encryptedBlob.length === 0) {
|
|
101
|
+
return Buffer.alloc(0);
|
|
102
|
+
}
|
|
103
|
+
const blob = Buffer.isBuffer(encryptedBlob)
|
|
104
|
+
? encryptedBlob
|
|
105
|
+
: Buffer.from(encryptedBlob);
|
|
106
|
+
const prefix = blob.subarray(0, 3).toString("utf-8");
|
|
107
|
+
if (prefix !== "v20") {
|
|
108
|
+
return "<unsupported encryption format>";
|
|
109
|
+
}
|
|
110
|
+
if (blob.length < 3 + GCM_NONCE_LENGTH + GCM_TAG_LENGTH) {
|
|
111
|
+
return "<decryption failed>";
|
|
112
|
+
}
|
|
113
|
+
const nonce = blob.subarray(3, 3 + GCM_NONCE_LENGTH);
|
|
114
|
+
const tag = blob.subarray(blob.length - GCM_TAG_LENGTH);
|
|
115
|
+
const ciphertext = blob.subarray(3 + GCM_NONCE_LENGTH, blob.length - GCM_TAG_LENGTH);
|
|
116
|
+
try {
|
|
117
|
+
const decipher = createDecipheriv("aes-256-gcm", key, nonce);
|
|
118
|
+
decipher.setAuthTag(tag);
|
|
119
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return "<decryption failed>";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
86
125
|
/**
|
|
87
126
|
* Converts a Chrome/Webkit timestamp (microseconds since 1601-01-01)
|
|
88
127
|
* to a readable local Date string.
|
|
@@ -23,8 +23,18 @@ export interface ChromePlatform {
|
|
|
23
23
|
*/
|
|
24
24
|
getDecryptionKey(chromeDir?: string, browser?: BrowserDescriptor): Buffer;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
26
|
+
* Returns the App-Bound Encryption key for Chrome 127+ on Windows.
|
|
27
|
+
* Only the win32 backend implements this; others return `undefined`.
|
|
28
|
+
*
|
|
29
|
+
* @param chromeDir - User Data dir containing the `Local State` file.
|
|
30
|
+
* @param browser - Browser to target (needed to select the COM CLSID).
|
|
31
|
+
* @returns The decrypted 32-byte AES key, or `undefined` if ABE is
|
|
32
|
+
* unavailable or unsupported on this platform.
|
|
33
|
+
*/
|
|
34
|
+
getAppBoundKey?(chromeDir?: string, browser?: BrowserDescriptor): Buffer | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Decrypts a single Chrome `v10`/`v11`/`v20` blob using this platform's
|
|
37
|
+
* scheme (AES-128-CBC on macOS/Linux, AES-256-GCM on Windows).
|
|
28
38
|
*
|
|
29
39
|
* @returns The plaintext bytes, or a `<...>` placeholder string on a
|
|
30
40
|
* recognized but undecryptable blob (never throws).
|
|
@@ -6,7 +6,8 @@ import type { ChromePlatform } from "./types.js";
|
|
|
6
6
|
* unprotected via DPAPI into a raw 32-byte AES-256 key (no PBKDF2 on Windows).
|
|
7
7
|
* Cipher: AES-256-GCM (nonce + tag carried in each blob).
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Chrome 127+ adds `os_crypt.app_bound_encrypted_key` — base64, "APPB"-prefixed.
|
|
10
|
+
* After DPAPI unprotection, the result is fed to Chrome's IElevator COM service
|
|
11
|
+
* via the native helper to obtain the real 32-byte AES key for "v20" blobs.
|
|
11
12
|
*/
|
|
12
13
|
export declare const win32: ChromePlatform;
|
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
import { decryptValueBufferGcm } from "../crypto.js";
|
|
4
|
+
import { decryptValueBufferGcm, decryptValueBufferGcmV20 } from "../crypto.js";
|
|
5
5
|
import { getActiveBrowser } from "../browsers.js";
|
|
6
6
|
// Chrome base64-encodes the DPAPI-protected AES key in Local State, prefixed
|
|
7
7
|
// with the ASCII bytes "DPAPI".
|
|
8
8
|
const DPAPI_PREFIX = Buffer.from("DPAPI", "ascii");
|
|
9
|
+
// Chrome 127+ uses App-Bound Encryption. The key in Local State is prefixed
|
|
10
|
+
// with "APPB" and requires the IElevator COM service to decrypt.
|
|
11
|
+
const APPB_PREFIX = Buffer.from("APPB", "ascii");
|
|
9
12
|
// Keyed by User Data dir so different browsers (each with its own Local State)
|
|
10
13
|
// cache independently (e.g. under `--all-browsers`).
|
|
11
14
|
const _cachedKeys = new Map();
|
|
15
|
+
const _cachedABEKeys = new Map();
|
|
16
|
+
// Maps browser ids to the COM service identifier used by the native helper.
|
|
17
|
+
const ABE_BROWSER_MAP = {
|
|
18
|
+
chrome: "chrome",
|
|
19
|
+
"chrome-beta": "chrome-beta",
|
|
20
|
+
"chrome-canary": "chrome",
|
|
21
|
+
chromium: "chrome",
|
|
22
|
+
brave: "brave",
|
|
23
|
+
edge: "edge",
|
|
24
|
+
vivaldi: "chrome",
|
|
25
|
+
comet: "chrome",
|
|
26
|
+
opera: "chrome",
|
|
27
|
+
};
|
|
12
28
|
/**
|
|
13
29
|
* Unprotects a DPAPI blob for the current user.
|
|
14
30
|
*
|
|
@@ -37,6 +53,77 @@ function dpapiDecrypt(encrypted) {
|
|
|
37
53
|
}
|
|
38
54
|
return Buffer.from(out.trim(), "base64");
|
|
39
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Resolves the Local State directory from a profile/chromeDir path.
|
|
58
|
+
* `profilePath` may point directly at .../Default. Local State belongs to
|
|
59
|
+
* the parent User Data directory.
|
|
60
|
+
*/
|
|
61
|
+
function resolveLocalStateDir(requestedDir) {
|
|
62
|
+
const parentDir = dirname(requestedDir);
|
|
63
|
+
return existsSync(join(requestedDir, "Local State"))
|
|
64
|
+
? requestedDir
|
|
65
|
+
: parentDir !== requestedDir && existsSync(join(parentDir, "Local State"))
|
|
66
|
+
? parentDir
|
|
67
|
+
: requestedDir;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Finds the chrome_abe_decrypt helper executable.
|
|
71
|
+
* Searches in order:
|
|
72
|
+
* 1. Next to this module (dist/src/core/platform/)
|
|
73
|
+
* 2. In the package bin/ directory
|
|
74
|
+
* 3. In src/native/ (development)
|
|
75
|
+
* 4. On PATH
|
|
76
|
+
*/
|
|
77
|
+
function findABEHelper() {
|
|
78
|
+
const base = import.meta.dirname ?? "";
|
|
79
|
+
const candidates = [
|
|
80
|
+
join(base, "..", "..", "..", "bin", "chrome_abe_decrypt.exe"),
|
|
81
|
+
join(base, "..", "..", "..", "..", "bin", "chrome_abe_decrypt.exe"),
|
|
82
|
+
join(base, "..", "..", "..", "..", "src", "native", "chrome_abe_decrypt.exe"),
|
|
83
|
+
];
|
|
84
|
+
for (const p of candidates) {
|
|
85
|
+
if (existsSync(p))
|
|
86
|
+
return p;
|
|
87
|
+
}
|
|
88
|
+
// Try on PATH
|
|
89
|
+
try {
|
|
90
|
+
execFileSync("where", ["chrome_abe_decrypt.exe"], { encoding: "utf-8", stdio: "pipe" });
|
|
91
|
+
return "chrome_abe_decrypt.exe";
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
let _abeHelperPath;
|
|
98
|
+
let _abeWarningShown = false;
|
|
99
|
+
/**
|
|
100
|
+
* Decrypts an app_bound_encrypted_key using Chrome's IElevator COM service
|
|
101
|
+
* via the native helper binary.
|
|
102
|
+
*
|
|
103
|
+
* The key from Local State is already DPAPI-decrypted at this point. This
|
|
104
|
+
* function passes it to the COM service for the second decryption layer.
|
|
105
|
+
*/
|
|
106
|
+
function abeDecrypt(dpapiDecrypted, browserId) {
|
|
107
|
+
if (_abeHelperPath === undefined) {
|
|
108
|
+
_abeHelperPath = findABEHelper();
|
|
109
|
+
}
|
|
110
|
+
if (!_abeHelperPath) {
|
|
111
|
+
if (!_abeWarningShown) {
|
|
112
|
+
_abeWarningShown = true;
|
|
113
|
+
process.stderr.write("[chrome-tools] chrome_abe_decrypt.exe not found. Chrome 127+ v20-encrypted\n" +
|
|
114
|
+
"cookies/passwords cannot be decrypted. See src/native/README for build instructions.\n");
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const comBrowser = ABE_BROWSER_MAP[browserId] || "chrome";
|
|
119
|
+
try {
|
|
120
|
+
const out = execFileSync(_abeHelperPath, [comBrowser], { input: dpapiDecrypted.toString("base64"), encoding: "utf-8", timeout: 30000, stdio: ["pipe", "pipe", "pipe"] });
|
|
121
|
+
return Buffer.from(out.trim(), "base64");
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
40
127
|
/**
|
|
41
128
|
* Windows backend.
|
|
42
129
|
*
|
|
@@ -44,8 +131,9 @@ function dpapiDecrypt(encrypted) {
|
|
|
44
131
|
* unprotected via DPAPI into a raw 32-byte AES-256 key (no PBKDF2 on Windows).
|
|
45
132
|
* Cipher: AES-256-GCM (nonce + tag carried in each blob).
|
|
46
133
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
134
|
+
* Chrome 127+ adds `os_crypt.app_bound_encrypted_key` — base64, "APPB"-prefixed.
|
|
135
|
+
* After DPAPI unprotection, the result is fed to Chrome's IElevator COM service
|
|
136
|
+
* via the native helper to obtain the real 32-byte AES key for "v20" blobs.
|
|
49
137
|
*/
|
|
50
138
|
export const win32 = {
|
|
51
139
|
name: "win32",
|
|
@@ -67,15 +155,7 @@ export const win32 = {
|
|
|
67
155
|
},
|
|
68
156
|
getDecryptionKey(chromeDir, browser = getActiveBrowser()) {
|
|
69
157
|
const requestedDir = chromeDir || this.getDefaultChromeDir(browser);
|
|
70
|
-
|
|
71
|
-
// the parent User Data directory, so use it when the supplied path does not
|
|
72
|
-
// contain its own Local State file.
|
|
73
|
-
const parentDir = dirname(requestedDir);
|
|
74
|
-
const dir = existsSync(join(requestedDir, "Local State"))
|
|
75
|
-
? requestedDir
|
|
76
|
-
: parentDir !== requestedDir && existsSync(join(parentDir, "Local State"))
|
|
77
|
-
? parentDir
|
|
78
|
-
: requestedDir;
|
|
158
|
+
const dir = resolveLocalStateDir(requestedDir);
|
|
79
159
|
const cached = _cachedKeys.get(dir);
|
|
80
160
|
if (cached !== undefined) {
|
|
81
161
|
return cached;
|
|
@@ -105,10 +185,65 @@ export const win32 = {
|
|
|
105
185
|
_cachedKeys.set(dir, key);
|
|
106
186
|
return key;
|
|
107
187
|
},
|
|
188
|
+
getAppBoundKey(chromeDir, browser = getActiveBrowser()) {
|
|
189
|
+
const requestedDir = chromeDir || this.getDefaultChromeDir(browser);
|
|
190
|
+
const dir = resolveLocalStateDir(requestedDir);
|
|
191
|
+
const cached = _cachedABEKeys.get(dir);
|
|
192
|
+
if (cached !== undefined) {
|
|
193
|
+
return cached;
|
|
194
|
+
}
|
|
195
|
+
const localStatePath = join(dir, "Local State");
|
|
196
|
+
if (!existsSync(localStatePath))
|
|
197
|
+
return undefined;
|
|
198
|
+
let appBoundKeyB64;
|
|
199
|
+
try {
|
|
200
|
+
const raw = readFileSync(localStatePath, "utf-8");
|
|
201
|
+
appBoundKeyB64 = JSON.parse(raw)?.os_crypt?.app_bound_encrypted_key;
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
if (!appBoundKeyB64)
|
|
207
|
+
return undefined;
|
|
208
|
+
const appBoundKey = Buffer.from(appBoundKeyB64, "base64");
|
|
209
|
+
if (!appBoundKey.subarray(0, APPB_PREFIX.length).equals(APPB_PREFIX)) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
// Step 1: DPAPI-decrypt the key (strip the "APPB" prefix first)
|
|
213
|
+
let dpapiResult;
|
|
214
|
+
try {
|
|
215
|
+
dpapiResult = dpapiDecrypt(appBoundKey.subarray(APPB_PREFIX.length));
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
// Step 2: Use the IElevator COM service to decrypt the ABE layer
|
|
221
|
+
const abeKey = abeDecrypt(dpapiResult, browser.id);
|
|
222
|
+
if (!abeKey)
|
|
223
|
+
return undefined;
|
|
224
|
+
// The COM service returns a key that may have a 4-byte header; the last 32
|
|
225
|
+
// bytes are the actual AES-256 key. If the result is exactly 32 bytes, use
|
|
226
|
+
// it as-is.
|
|
227
|
+
const key = abeKey.length > 32 ? abeKey.subarray(abeKey.length - 32) : abeKey;
|
|
228
|
+
_cachedABEKeys.set(dir, key);
|
|
229
|
+
return key;
|
|
230
|
+
},
|
|
108
231
|
decrypt(blob, key) {
|
|
232
|
+
const prefix = blob.subarray(0, 3).toString("utf-8");
|
|
233
|
+
// v20 = App-Bound Encryption (Chrome 127+)
|
|
234
|
+
if (prefix === "v20") {
|
|
235
|
+
// Try to get the ABE key for this profile
|
|
236
|
+
const abeKey = this.getAppBoundKey?.();
|
|
237
|
+
if (!abeKey) {
|
|
238
|
+
return "<v20 app-bound encryption - requires chrome_abe_decrypt.exe>";
|
|
239
|
+
}
|
|
240
|
+
return decryptValueBufferGcmV20(blob, abeKey);
|
|
241
|
+
}
|
|
242
|
+
// v10/v11 = standard DPAPI + AES-256-GCM
|
|
109
243
|
return decryptValueBufferGcm(blob, key);
|
|
110
244
|
},
|
|
111
245
|
clearCache() {
|
|
112
246
|
_cachedKeys.clear();
|
|
247
|
+
_cachedABEKeys.clear();
|
|
113
248
|
},
|
|
114
249
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrome-tools",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"description": "CLI & Node.js library for chrome",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"dist/src",
|
|
25
25
|
"dist/bin",
|
|
26
|
+
"bin/chrome_abe_decrypt.exe",
|
|
27
|
+
"src/native",
|
|
26
28
|
"README.md",
|
|
27
29
|
"LICENSE"
|
|
28
30
|
],
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM Build chrome_abe_decrypt.exe with MSVC
|
|
3
|
+
REM Run from a Visual Studio Developer Command Prompt or after calling vcvarsall.bat
|
|
4
|
+
|
|
5
|
+
where cl.exe >nul 2>nul
|
|
6
|
+
if %ERRORLEVEL% neq 0 (
|
|
7
|
+
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" (
|
|
8
|
+
call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
|
|
9
|
+
) else if exist "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" (
|
|
10
|
+
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
|
|
11
|
+
) else if exist "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat" (
|
|
12
|
+
call "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat" x64
|
|
13
|
+
) else if exist "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" (
|
|
14
|
+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
cl.exe /nologo /O2 /W3 /Fe:chrome_abe_decrypt.exe chrome_abe_decrypt.c ole32.lib oleaut32.lib crypt32.lib advapi32.lib
|
|
19
|
+
|
|
20
|
+
if %ERRORLEVEL% neq 0 (
|
|
21
|
+
echo Build failed.
|
|
22
|
+
exit /b 1
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
echo.
|
|
26
|
+
echo Built: chrome_abe_decrypt.exe
|
|
27
|
+
echo.
|
|
28
|
+
echo Usage: chrome_abe_decrypt.exe ^<browser^>
|
|
29
|
+
echo Reads base64 app_bound_encrypted_key from stdin
|
|
30
|
+
echo Writes base64 decrypted key to stdout
|
|
31
|
+
echo browser: chrome, chrome-beta, brave, edge
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* chrome_abe_decrypt.c — Minimal Chrome App-Bound Encryption key decryptor.
|
|
3
|
+
*
|
|
4
|
+
* Calls Chrome's IElevator COM service to decrypt an app_bound_encrypted_key.
|
|
5
|
+
* Derived from xaitax/Chrome-App-Bound-Encryption-Decryption (MIT License).
|
|
6
|
+
*
|
|
7
|
+
* Usage: chrome_abe_decrypt.exe <browser> < base64_encrypted_key
|
|
8
|
+
* Outputs: base64-encoded decrypted key to stdout
|
|
9
|
+
*
|
|
10
|
+
* <browser> is one of: chrome, chrome-beta, brave, edge
|
|
11
|
+
*
|
|
12
|
+
* Build: cl.exe /O2 chrome_abe_decrypt.c ole32.lib oleaut32.lib advapi32.lib
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2024 Alexander 'xaitax' Hagenah (original COM logic)
|
|
15
|
+
* MIT License
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#define WIN32_LEAN_AND_MEAN
|
|
19
|
+
#define COBJMACROS
|
|
20
|
+
#include <windows.h>
|
|
21
|
+
#include <objbase.h>
|
|
22
|
+
#include <oleauto.h>
|
|
23
|
+
#include <stdio.h>
|
|
24
|
+
#include <stdlib.h>
|
|
25
|
+
#include <string.h>
|
|
26
|
+
|
|
27
|
+
/* ---------- base64 helpers (Windows CryptBinaryToStringA) ---------- */
|
|
28
|
+
#pragma comment(lib, "crypt32.lib")
|
|
29
|
+
#include <wincrypt.h>
|
|
30
|
+
|
|
31
|
+
static int b64_decode(const char *b64, unsigned char **out, DWORD *outLen) {
|
|
32
|
+
DWORD len = 0;
|
|
33
|
+
if (!CryptStringToBinaryA(b64, 0, CRYPT_STRING_BASE64, NULL, &len, NULL, NULL))
|
|
34
|
+
return -1;
|
|
35
|
+
*out = (unsigned char *)malloc(len);
|
|
36
|
+
if (!*out) return -1;
|
|
37
|
+
if (!CryptStringToBinaryA(b64, 0, CRYPT_STRING_BASE64, *out, &len, NULL, NULL)) {
|
|
38
|
+
free(*out);
|
|
39
|
+
return -1;
|
|
40
|
+
}
|
|
41
|
+
*outLen = len;
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static int b64_encode(const unsigned char *data, DWORD dataLen, char **out) {
|
|
46
|
+
DWORD len = 0;
|
|
47
|
+
if (!CryptBinaryToStringA(data, dataLen, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, NULL, &len))
|
|
48
|
+
return -1;
|
|
49
|
+
*out = (char *)malloc(len + 1);
|
|
50
|
+
if (!*out) return -1;
|
|
51
|
+
if (!CryptBinaryToStringA(data, dataLen, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, *out, &len)) {
|
|
52
|
+
free(*out);
|
|
53
|
+
return -1;
|
|
54
|
+
}
|
|
55
|
+
(*out)[len] = '\0';
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* ---------- IElevator COM interface (vtable-based, pure C) ---------- */
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* IElevator vtable layout (Chrome/Brave — 3 custom methods):
|
|
63
|
+
* [0] QueryInterface
|
|
64
|
+
* [1] AddRef
|
|
65
|
+
* [2] Release
|
|
66
|
+
* [3] RunRecoveryCRXElevated
|
|
67
|
+
* [4] EncryptData
|
|
68
|
+
* [5] DecryptData
|
|
69
|
+
*/
|
|
70
|
+
typedef struct IElevatorVtbl {
|
|
71
|
+
/* IUnknown */
|
|
72
|
+
HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *This, REFIID riid, void **ppv);
|
|
73
|
+
ULONG (STDMETHODCALLTYPE *AddRef)(void *This);
|
|
74
|
+
ULONG (STDMETHODCALLTYPE *Release)(void *This);
|
|
75
|
+
/* IElevator */
|
|
76
|
+
HRESULT (STDMETHODCALLTYPE *RunRecoveryCRXElevated)(void *This, const WCHAR*, const WCHAR*, const WCHAR*, const WCHAR*, DWORD, ULONG_PTR*);
|
|
77
|
+
HRESULT (STDMETHODCALLTYPE *EncryptData)(void *This, int protLevel, BSTR in, BSTR *out, DWORD *err);
|
|
78
|
+
HRESULT (STDMETHODCALLTYPE *DecryptData)(void *This, BSTR in, BSTR *out, DWORD *err);
|
|
79
|
+
} IElevatorVtbl;
|
|
80
|
+
|
|
81
|
+
typedef struct IElevator {
|
|
82
|
+
IElevatorVtbl *lpVtbl;
|
|
83
|
+
} IElevator;
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* Edge vtable layout — has 3 extra base methods before the IElevator methods:
|
|
87
|
+
* [0] QueryInterface
|
|
88
|
+
* [1] AddRef
|
|
89
|
+
* [2] Release
|
|
90
|
+
* [3] EdgeBaseMethod1
|
|
91
|
+
* [4] EdgeBaseMethod2
|
|
92
|
+
* [5] EdgeBaseMethod3
|
|
93
|
+
* [6] RunRecoveryCRXElevated
|
|
94
|
+
* [7] EncryptData
|
|
95
|
+
* [8] DecryptData
|
|
96
|
+
*/
|
|
97
|
+
typedef struct IEdgeElevatorVtbl {
|
|
98
|
+
/* IUnknown */
|
|
99
|
+
HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *This, REFIID riid, void **ppv);
|
|
100
|
+
ULONG (STDMETHODCALLTYPE *AddRef)(void *This);
|
|
101
|
+
ULONG (STDMETHODCALLTYPE *Release)(void *This);
|
|
102
|
+
/* IEdgeElevatorBase (3 unknown methods) */
|
|
103
|
+
HRESULT (STDMETHODCALLTYPE *EdgeBase1)(void *This);
|
|
104
|
+
HRESULT (STDMETHODCALLTYPE *EdgeBase2)(void *This);
|
|
105
|
+
HRESULT (STDMETHODCALLTYPE *EdgeBase3)(void *This);
|
|
106
|
+
/* IElevator */
|
|
107
|
+
HRESULT (STDMETHODCALLTYPE *RunRecoveryCRXElevated)(void *This, const WCHAR*, const WCHAR*, const WCHAR*, const WCHAR*, DWORD, ULONG_PTR*);
|
|
108
|
+
HRESULT (STDMETHODCALLTYPE *EncryptData)(void *This, int protLevel, BSTR in, BSTR *out, DWORD *err);
|
|
109
|
+
HRESULT (STDMETHODCALLTYPE *DecryptData)(void *This, BSTR in, BSTR *out, DWORD *err);
|
|
110
|
+
} IEdgeElevatorVtbl;
|
|
111
|
+
|
|
112
|
+
typedef struct IEdgeElevator {
|
|
113
|
+
IEdgeElevatorVtbl *lpVtbl;
|
|
114
|
+
} IEdgeElevator;
|
|
115
|
+
|
|
116
|
+
/* ---------- Browser COM identifiers ---------- */
|
|
117
|
+
/* From xaitax/Chrome-App-Bound-Encryption-Decryption/src/payload/browser_config.hpp */
|
|
118
|
+
|
|
119
|
+
typedef struct BrowserCOM {
|
|
120
|
+
const char *name;
|
|
121
|
+
CLSID clsid;
|
|
122
|
+
IID iid; /* IElevator v1 */
|
|
123
|
+
IID iid_v2; /* IElevator v2 (Chrome 144+), GUID_NULL if none */
|
|
124
|
+
int isEdge;
|
|
125
|
+
} BrowserCOM;
|
|
126
|
+
|
|
127
|
+
/* Chrome */
|
|
128
|
+
static const CLSID CLSID_Chrome = {0x708860E0, 0xF641, 0x4611, {0x88, 0x95, 0x7D, 0x86, 0x7D, 0xD3, 0x67, 0x5B}};
|
|
129
|
+
static const IID IID_IElevatorChrome = {0x463ABECF, 0x410D, 0x407F, {0x8A, 0xF5, 0x0D, 0xF3, 0x5A, 0x00, 0x5C, 0xC8}};
|
|
130
|
+
static const IID IID_IElevator2Chrome = {0x1BF5208B, 0x295F, 0x4992, {0xB5, 0xF4, 0x3A, 0x9B, 0xB6, 0x49, 0x48, 0x38}};
|
|
131
|
+
|
|
132
|
+
/* Chrome Beta */
|
|
133
|
+
static const CLSID CLSID_ChromeBeta = {0xDD2646BA, 0x3707, 0x4BF8, {0xB9, 0xA7, 0x03, 0x86, 0x91, 0xA6, 0x8F, 0xC2}};
|
|
134
|
+
static const IID IID_IElevatorChromeBeta = {0xA2721D66, 0x376E, 0x4D2F, {0x9F, 0x0F, 0x90, 0x70, 0xE9, 0xA4, 0x2B, 0x5F}};
|
|
135
|
+
static const IID IID_IElevator2ChromeBeta = {0xB96A14B8, 0xD0B0, 0x44D8, {0xBA, 0x68, 0x23, 0x85, 0xB2, 0xA0, 0x32, 0x54}};
|
|
136
|
+
|
|
137
|
+
/* Brave — reuses Chrome's IElevator IID */
|
|
138
|
+
static const CLSID CLSID_Brave = {0x576B31AF, 0x6369, 0x4B6B, {0x85, 0x60, 0xE4, 0xB2, 0x03, 0xA9, 0x7A, 0x8B}};
|
|
139
|
+
static const IID IID_IElevatorBrave = {0xF396861E, 0x0C8E, 0x4C71, {0x82, 0x56, 0x2F, 0xAE, 0x6D, 0x75, 0x9C, 0xE9}};
|
|
140
|
+
/* Brave reuses Chrome's v2 IID: IID_IElevator2Chrome */
|
|
141
|
+
|
|
142
|
+
/* Edge */
|
|
143
|
+
static const CLSID CLSID_Edge = {0x1FCBE96C, 0x1697, 0x43AF, {0x91, 0x40, 0x28, 0x97, 0xC7, 0xC6, 0x97, 0x67}};
|
|
144
|
+
static const IID IID_IElevatorEdge = {0xC9C2B807, 0x7731, 0x4F34, {0x81, 0xB7, 0x44, 0xFF, 0x77, 0x79, 0x52, 0x2B}};
|
|
145
|
+
static const IID IID_IElevator2Edge = {0x8F7B6792, 0x784D, 0x4047, {0x84, 0x5D, 0x17, 0x82, 0xEF, 0xBE, 0xF2, 0x05}};
|
|
146
|
+
|
|
147
|
+
static const BrowserCOM browsers[] = {
|
|
148
|
+
{"chrome", {0}, {0}, {0}, 0}, /* filled below */
|
|
149
|
+
{"chrome-beta", {0}, {0}, {0}, 0},
|
|
150
|
+
{"brave", {0}, {0}, {0}, 0},
|
|
151
|
+
{"edge", {0}, {0}, {0}, 1},
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
static int get_browser(const char *name, const CLSID **clsid, const IID **iid, const IID **iid_v2, int *isEdge) {
|
|
155
|
+
if (strcmp(name, "chrome") == 0) {
|
|
156
|
+
*clsid = &CLSID_Chrome; *iid = &IID_IElevatorChrome; *iid_v2 = &IID_IElevator2Chrome; *isEdge = 0;
|
|
157
|
+
} else if (strcmp(name, "chrome-beta") == 0) {
|
|
158
|
+
*clsid = &CLSID_ChromeBeta; *iid = &IID_IElevatorChromeBeta; *iid_v2 = &IID_IElevator2ChromeBeta; *isEdge = 0;
|
|
159
|
+
} else if (strcmp(name, "brave") == 0) {
|
|
160
|
+
*clsid = &CLSID_Brave; *iid = &IID_IElevatorBrave; *iid_v2 = &IID_IElevator2Chrome; *isEdge = 0;
|
|
161
|
+
} else if (strcmp(name, "edge") == 0) {
|
|
162
|
+
*clsid = &CLSID_Edge; *iid = &IID_IElevatorEdge; *iid_v2 = &IID_IElevator2Edge; *isEdge = 1;
|
|
163
|
+
} else {
|
|
164
|
+
return -1;
|
|
165
|
+
}
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* ---------- Decrypt via COM ---------- */
|
|
170
|
+
|
|
171
|
+
static HRESULT decrypt_via_com(
|
|
172
|
+
const CLSID *clsid,
|
|
173
|
+
const IID *iid,
|
|
174
|
+
const IID *iid_v2,
|
|
175
|
+
int isEdge,
|
|
176
|
+
const unsigned char *encData,
|
|
177
|
+
DWORD encLen,
|
|
178
|
+
unsigned char **outData,
|
|
179
|
+
DWORD *outLen
|
|
180
|
+
) {
|
|
181
|
+
BSTR bstrEnc = SysAllocStringByteLen((const char *)encData, encLen);
|
|
182
|
+
if (!bstrEnc) return E_OUTOFMEMORY;
|
|
183
|
+
|
|
184
|
+
BSTR bstrPlain = NULL;
|
|
185
|
+
DWORD comErr = 0;
|
|
186
|
+
HRESULT hr = E_FAIL;
|
|
187
|
+
|
|
188
|
+
if (isEdge) {
|
|
189
|
+
/* Edge: try v2 first, then v1 */
|
|
190
|
+
IEdgeElevator *elevator = NULL;
|
|
191
|
+
|
|
192
|
+
/* Try v2 */
|
|
193
|
+
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, iid_v2, (void **)&elevator);
|
|
194
|
+
if (SUCCEEDED(hr)) {
|
|
195
|
+
CoSetProxyBlanket((IUnknown *)elevator, RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_DEFAULT,
|
|
196
|
+
COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
|
|
197
|
+
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_DYNAMIC_CLOAKING);
|
|
198
|
+
hr = elevator->lpVtbl->DecryptData(elevator, bstrEnc, &bstrPlain, &comErr);
|
|
199
|
+
elevator->lpVtbl->Release(elevator);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/* Fall back to v1 */
|
|
203
|
+
if (FAILED(hr)) {
|
|
204
|
+
elevator = NULL;
|
|
205
|
+
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, iid, (void **)&elevator);
|
|
206
|
+
if (SUCCEEDED(hr)) {
|
|
207
|
+
CoSetProxyBlanket((IUnknown *)elevator, RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_DEFAULT,
|
|
208
|
+
COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
|
|
209
|
+
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_DYNAMIC_CLOAKING);
|
|
210
|
+
hr = elevator->lpVtbl->DecryptData(elevator, bstrEnc, &bstrPlain, &comErr);
|
|
211
|
+
elevator->lpVtbl->Release(elevator);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
/* Chrome/Brave: try v2 first, then v1 */
|
|
216
|
+
IElevator *elevator = NULL;
|
|
217
|
+
|
|
218
|
+
/* Try v2 (Chrome 144+) */
|
|
219
|
+
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, iid_v2, (void **)&elevator);
|
|
220
|
+
if (FAILED(hr) || hr == (HRESULT)0x80040154L /* REGDB_E_CLASSNOTREG */) {
|
|
221
|
+
/* Fall back to v1 */
|
|
222
|
+
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, iid, (void **)&elevator);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (SUCCEEDED(hr)) {
|
|
226
|
+
CoSetProxyBlanket((IUnknown *)elevator, RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_DEFAULT,
|
|
227
|
+
COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
|
|
228
|
+
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_DYNAMIC_CLOAKING);
|
|
229
|
+
hr = elevator->lpVtbl->DecryptData(elevator, bstrEnc, &bstrPlain, &comErr);
|
|
230
|
+
elevator->lpVtbl->Release(elevator);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
SysFreeString(bstrEnc);
|
|
235
|
+
|
|
236
|
+
if (FAILED(hr) || !bstrPlain) {
|
|
237
|
+
if (bstrPlain) SysFreeString(bstrPlain);
|
|
238
|
+
return FAILED(hr) ? hr : E_FAIL;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
*outLen = SysStringByteLen(bstrPlain);
|
|
242
|
+
*outData = (unsigned char *)malloc(*outLen);
|
|
243
|
+
if (!*outData) {
|
|
244
|
+
SysFreeString(bstrPlain);
|
|
245
|
+
return E_OUTOFMEMORY;
|
|
246
|
+
}
|
|
247
|
+
memcpy(*outData, bstrPlain, *outLen);
|
|
248
|
+
SysFreeString(bstrPlain);
|
|
249
|
+
return S_OK;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/* ---------- main ---------- */
|
|
253
|
+
|
|
254
|
+
int main(int argc, char *argv[]) {
|
|
255
|
+
if (argc < 2) {
|
|
256
|
+
fprintf(stderr, "Usage: chrome_abe_decrypt.exe <browser>\n");
|
|
257
|
+
fprintf(stderr, " browser: chrome, chrome-beta, brave, edge\n");
|
|
258
|
+
fprintf(stderr, "Reads base64 encrypted key from stdin, writes base64 decrypted key to stdout.\n");
|
|
259
|
+
return 1;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const char *browserName = argv[1];
|
|
263
|
+
const CLSID *clsid;
|
|
264
|
+
const IID *iid, *iid_v2;
|
|
265
|
+
int isEdge;
|
|
266
|
+
|
|
267
|
+
if (get_browser(browserName, &clsid, &iid, &iid_v2, &isEdge) != 0) {
|
|
268
|
+
fprintf(stderr, "ERROR: Unknown browser '%s'. Use: chrome, chrome-beta, brave, edge\n", browserName);
|
|
269
|
+
return 1;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/* Read base64 input from stdin */
|
|
273
|
+
char input[65536];
|
|
274
|
+
size_t totalRead = 0;
|
|
275
|
+
while (totalRead < sizeof(input) - 1) {
|
|
276
|
+
size_t n = fread(input + totalRead, 1, sizeof(input) - 1 - totalRead, stdin);
|
|
277
|
+
if (n == 0) break;
|
|
278
|
+
totalRead += n;
|
|
279
|
+
}
|
|
280
|
+
input[totalRead] = '\0';
|
|
281
|
+
|
|
282
|
+
/* Trim whitespace */
|
|
283
|
+
while (totalRead > 0 && (input[totalRead-1] == '\n' || input[totalRead-1] == '\r' || input[totalRead-1] == ' ')) {
|
|
284
|
+
input[--totalRead] = '\0';
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (totalRead == 0) {
|
|
288
|
+
fprintf(stderr, "ERROR: No input received on stdin\n");
|
|
289
|
+
return 1;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/* Decode base64 input */
|
|
293
|
+
unsigned char *encData = NULL;
|
|
294
|
+
DWORD encLen = 0;
|
|
295
|
+
if (b64_decode(input, &encData, &encLen) != 0) {
|
|
296
|
+
fprintf(stderr, "ERROR: Failed to decode base64 input\n");
|
|
297
|
+
return 1;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/* Initialize COM */
|
|
301
|
+
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
302
|
+
if (FAILED(hr)) {
|
|
303
|
+
fprintf(stderr, "ERROR: CoInitializeEx failed: 0x%08lX\n", hr);
|
|
304
|
+
free(encData);
|
|
305
|
+
return 1;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/* Decrypt */
|
|
309
|
+
unsigned char *decData = NULL;
|
|
310
|
+
DWORD decLen = 0;
|
|
311
|
+
hr = decrypt_via_com(clsid, iid, iid_v2, isEdge, encData, encLen, &decData, &decLen);
|
|
312
|
+
free(encData);
|
|
313
|
+
|
|
314
|
+
if (FAILED(hr)) {
|
|
315
|
+
fprintf(stderr, "ERROR: DecryptData failed: 0x%08lX\n", hr);
|
|
316
|
+
CoUninitialize();
|
|
317
|
+
return 1;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/* Encode result as base64 and write to stdout */
|
|
321
|
+
char *b64out = NULL;
|
|
322
|
+
if (b64_encode(decData, decLen, &b64out) != 0) {
|
|
323
|
+
fprintf(stderr, "ERROR: Failed to encode result as base64\n");
|
|
324
|
+
free(decData);
|
|
325
|
+
CoUninitialize();
|
|
326
|
+
return 1;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
printf("%s", b64out);
|
|
330
|
+
fflush(stdout);
|
|
331
|
+
|
|
332
|
+
free(b64out);
|
|
333
|
+
free(decData);
|
|
334
|
+
CoUninitialize();
|
|
335
|
+
return 0;
|
|
336
|
+
}
|
|
Binary file
|