chrome-tools 1.0.1 → 1.0.2
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/package.json +1 -1
- package/src/core/crypto.js +14 -2
- package/src/modules/cookies.js +17 -2
package/package.json
CHANGED
package/src/core/crypto.js
CHANGED
|
@@ -12,8 +12,20 @@ const AES_IV = Buffer.alloc(16, " "); // 16 spaces (0x20)
|
|
|
12
12
|
* @returns {string} The decrypted plaintext, or an error placeholder.
|
|
13
13
|
*/
|
|
14
14
|
export function decryptValue(encryptedBlob, derivedKey) {
|
|
15
|
+
const decrypted = decryptValueBuffer(encryptedBlob, derivedKey);
|
|
16
|
+
return Buffer.isBuffer(decrypted) ? decrypted.toString("utf-8") : decrypted;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Decrypts a Chrome encrypted blob and returns the raw plaintext bytes.
|
|
21
|
+
*
|
|
22
|
+
* @param {Buffer|Uint8Array} encryptedBlob - The encrypted blob from the database.
|
|
23
|
+
* @param {Buffer} derivedKey - The derived 16-byte key.
|
|
24
|
+
* @returns {Buffer|string} The decrypted plaintext bytes, or an error placeholder.
|
|
25
|
+
*/
|
|
26
|
+
export function decryptValueBuffer(encryptedBlob, derivedKey) {
|
|
15
27
|
if (!encryptedBlob || encryptedBlob.length === 0) {
|
|
16
|
-
return
|
|
28
|
+
return Buffer.alloc(0);
|
|
17
29
|
}
|
|
18
30
|
|
|
19
31
|
const blob = Buffer.isBuffer(encryptedBlob)
|
|
@@ -31,7 +43,7 @@ export function decryptValue(encryptedBlob, derivedKey) {
|
|
|
31
43
|
const decipher = createDecipheriv("aes-128-cbc", derivedKey, AES_IV);
|
|
32
44
|
let decrypted = decipher.update(ciphertext);
|
|
33
45
|
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
34
|
-
return decrypted
|
|
46
|
+
return decrypted;
|
|
35
47
|
} catch {
|
|
36
48
|
return "<decryption failed>";
|
|
37
49
|
}
|
package/src/modules/cookies.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { resolveTargetProfiles } from "../core/chrome.js";
|
|
3
4
|
import { deriveEncryptionKey } from "../core/keychain.js";
|
|
4
|
-
import {
|
|
5
|
+
import { decryptValueBuffer, chromeTimeToDate } from "../core/crypto.js";
|
|
5
6
|
import { queryDatabase, tableExists } from "../core/db.js";
|
|
6
7
|
|
|
8
|
+
function decodeCookieValue(encryptedValue, derivedKey, hostKey) {
|
|
9
|
+
const decrypted = decryptValueBuffer(encryptedValue, derivedKey);
|
|
10
|
+
if (!Buffer.isBuffer(decrypted)) {
|
|
11
|
+
return decrypted;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const hostHash = createHash("sha256").update(hostKey).digest();
|
|
15
|
+
const valueBytes = decrypted.length >= hostHash.length && decrypted.subarray(0, hostHash.length).equals(hostHash)
|
|
16
|
+
? decrypted.subarray(hostHash.length)
|
|
17
|
+
: decrypted;
|
|
18
|
+
|
|
19
|
+
return valueBytes.toString("utf-8");
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
/**
|
|
8
23
|
* Extracts cookies from Chrome's Cookies database.
|
|
9
24
|
* Encrypted values are decrypted using the same mechanism as passwords.
|
|
@@ -51,7 +66,7 @@ export function getCookies({ chromeDir, profile, domain, decrypt = true, limit =
|
|
|
51
66
|
for (const row of rows) {
|
|
52
67
|
let cookieValue = row.value || "";
|
|
53
68
|
if (!cookieValue && row.encrypted_value && derivedKey) {
|
|
54
|
-
cookieValue =
|
|
69
|
+
cookieValue = decodeCookieValue(row.encrypted_value, derivedKey, row.host_key);
|
|
55
70
|
}
|
|
56
71
|
|
|
57
72
|
results.push({
|