@mherod/get-cookie 2.0.0-rc.6 → 2.0.0-rc.8
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/dist/index.js +184 -114
- package/package.json +4 -3
- package/src/CookieRow.ts +1 -0
- package/src/ExportedCookie.ts +1 -0
- package/src/argv.ts +4 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +73 -16
- package/src/browsers/CompositeCookieQueryStrategy.ts +23 -9
- package/src/browsers/CookieStoreQueryStrategy.ts +2 -1
- package/src/cli.ts +1 -4
- package/src/doSqliteQuery1.ts +3 -7
- package/src/doSqliteQuery1Params.ts +7 -0
- package/src/fetchWithCookies.ts +10 -2
- package/src/findAllFiles.ts +5 -9
- package/src/getChromeCookie.ts +3 -3
- package/src/getGroupedRenderedCookies.ts +17 -20
- package/src/isValidJwt.ts +2 -2
- package/src/queryCookies.ts +14 -10
- package/src/resultsRendered.ts +6 -3
- package/src/utils.ts +0 -25
package/dist/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var $7oI3p$lodash = require("lodash");
|
|
3
|
+
var $7oI3p$minimist = require("minimist");
|
|
3
4
|
var $7oI3p$lrucache = require("lru-cache");
|
|
4
5
|
var $7oI3p$colorette = require("colorette");
|
|
5
6
|
var $7oI3p$fs = require("fs");
|
|
6
7
|
var $7oI3p$crypto = require("crypto");
|
|
7
8
|
var $7oI3p$path = require("path");
|
|
8
|
-
var $7oI3p$child_process = require("child_process");
|
|
9
9
|
var $7oI3p$sqlite3 = require("sqlite3");
|
|
10
|
+
var $7oI3p$child_process = require("child_process");
|
|
10
11
|
var $7oI3p$toughcookie = require("tough-cookie");
|
|
11
12
|
var $7oI3p$toughcookiefilestore = require("tough-cookie-file-store");
|
|
12
13
|
var $7oI3p$jsonwebtoken = require("jsonwebtoken");
|
|
13
14
|
var $7oI3p$crossfetch = require("cross-fetch");
|
|
14
15
|
var $7oI3p$destr = require("destr");
|
|
16
|
+
var $7oI3p$useragents = require("user-agents");
|
|
15
17
|
|
|
16
18
|
function $parcel$export(e, n, v, s) {
|
|
17
19
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
@@ -42,11 +44,9 @@ $parcel$export(module.exports, "getFirefoxCookie", () => $f9b70200901ad17d$expor
|
|
|
42
44
|
$parcel$export(module.exports, "getGroupedRenderedCookies", () => $300d8b33187a203c$export$4d2e9997e2c23417);
|
|
43
45
|
$parcel$export(module.exports, "fetchWithCookies", () => $cfc07ae4aa2c7e44$export$b24a545a0b39f491);
|
|
44
46
|
|
|
45
|
-
const $fac425c10fbbada5$export$a7b6bc01c63cdfc3 = {};
|
|
46
|
-
(0, $7oI3p$lodash.merge)($fac425c10fbbada5$export$a7b6bc01c63cdfc3, process.env);
|
|
47
|
-
const $fac425c10fbbada5$export$a7c5707626fc90f = $fac425c10fbbada5$export$a7b6bc01c63cdfc3["HOME"];
|
|
48
|
-
if (!$fac425c10fbbada5$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
|
|
49
47
|
|
|
48
|
+
const $ef3d5dc2fd8022f5$export$6f4ae1207c703045 = process.argv ?? [];
|
|
49
|
+
const $ef3d5dc2fd8022f5$export$c348dfaf65040d9b = (0, ($parcel$interopDefault($7oI3p$minimist)))($ef3d5dc2fd8022f5$export$6f4ae1207c703045.slice(2));
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
@@ -68,35 +68,26 @@ async function $25b78d6746d4ad48$export$8d71c74f97c0202e(command) {
|
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
function $25b78d6746d4ad48$export$d53bf2de587a369(result) {
|
|
72
|
-
if (result == null) return null;
|
|
73
|
-
if (process.env.VERBOSE) console.log("result", result);
|
|
74
|
-
if (typeof result === "string" && result.length > 0) return result;
|
|
75
|
-
if (result.slice && result.toString) // noinspection JSCheckFunctionSignatures
|
|
76
|
-
return result.toString("utf8");
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
function $25b78d6746d4ad48$export$99ce3e33a555daf1(input) {
|
|
80
|
-
return typeof input !== "string" || input.length === 0;
|
|
81
|
-
}
|
|
82
|
-
function $25b78d6746d4ad48$export$5348b46700dd771c(input) {
|
|
83
|
-
return typeof input == "string" && input.length > 0;
|
|
84
|
-
}
|
|
85
71
|
|
|
86
72
|
|
|
87
73
|
|
|
74
|
+
const $fac425c10fbbada5$export$a7b6bc01c63cdfc3 = {};
|
|
75
|
+
(0, $7oI3p$lodash.merge)($fac425c10fbbada5$export$a7b6bc01c63cdfc3, process.env);
|
|
76
|
+
const $fac425c10fbbada5$export$a7c5707626fc90f = $fac425c10fbbada5$export$a7b6bc01c63cdfc3["HOME"];
|
|
77
|
+
if (!$fac425c10fbbada5$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
|
|
78
|
+
|
|
79
|
+
|
|
88
80
|
|
|
89
81
|
|
|
90
82
|
|
|
91
83
|
async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: name , maxDepth: maxDepth = 2 }) {
|
|
92
84
|
const rootSegments = path.split("/").length;
|
|
93
|
-
if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Searching for ${name} in ${path}`);
|
|
94
85
|
const files = [];
|
|
95
86
|
let readdirSync;
|
|
96
87
|
try {
|
|
97
88
|
readdirSync = $7oI3p$fs.readdirSync(path);
|
|
98
89
|
} catch (e) {
|
|
99
|
-
if ((0, $
|
|
90
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`Error reading ${path}`, e);
|
|
100
91
|
return [];
|
|
101
92
|
}
|
|
102
93
|
for (const file of readdirSync){
|
|
@@ -105,7 +96,7 @@ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: na
|
|
|
105
96
|
try {
|
|
106
97
|
stat = $7oI3p$fs.statSync(filePath);
|
|
107
98
|
} catch (e1) {
|
|
108
|
-
if ((0, $
|
|
99
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.error(`Error getting stat for ${filePath}`, e1);
|
|
109
100
|
continue;
|
|
110
101
|
}
|
|
111
102
|
if (stat.isDirectory()) {
|
|
@@ -117,11 +108,11 @@ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: na
|
|
|
117
108
|
});
|
|
118
109
|
files.push(...subFiles);
|
|
119
110
|
} catch (e2) {
|
|
120
|
-
if ((0, $
|
|
111
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.error(e2);
|
|
121
112
|
}
|
|
122
113
|
} else if (file === name) files.push(filePath);
|
|
123
114
|
}
|
|
124
|
-
if ((0, $
|
|
115
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) {
|
|
125
116
|
if (files.length > 0) {
|
|
126
117
|
console.log(`Found ${files.length} ${name} files`);
|
|
127
118
|
console.log(files);
|
|
@@ -134,45 +125,6 @@ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: na
|
|
|
134
125
|
|
|
135
126
|
|
|
136
127
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
140
|
-
if (!file || file && !$7oI3p$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
141
|
-
const db = new $7oI3p$sqlite3.Database(file);
|
|
142
|
-
return new Promise((resolve, reject)=>{
|
|
143
|
-
db.all(sql, (err, rows)=>{
|
|
144
|
-
if (err) {
|
|
145
|
-
reject(err);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
const rows1 = rows;
|
|
149
|
-
if (rows1 == null || rows1.length === 0) {
|
|
150
|
-
resolve([]);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (Array.isArray(rows1)) {
|
|
154
|
-
const cookieRows = rows1.map((row)=>{
|
|
155
|
-
const newVar = {
|
|
156
|
-
meta: {
|
|
157
|
-
file: file
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
const cookieRow = rowTransform(row);
|
|
161
|
-
return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
|
|
162
|
-
});
|
|
163
|
-
resolve(cookieRows);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (process.env.VERBOSE) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
167
|
-
resolve([
|
|
168
|
-
rows1
|
|
169
|
-
]);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
128
|
function $af69dfb8766652d8$export$bc926c43858bd3cb(obj) {
|
|
177
129
|
return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
|
|
178
130
|
}
|
|
@@ -191,6 +143,9 @@ function $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb(s) {
|
|
|
191
143
|
}
|
|
192
144
|
|
|
193
145
|
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
194
149
|
class $269fe42bfd555305$export$2e2bcd8739ae039 {
|
|
195
150
|
browserName = "Chrome";
|
|
196
151
|
async queryCookies(name, domain) {
|
|
@@ -211,7 +166,7 @@ async function $269fe42bfd555305$var$getPromise1(name, domain, file) {
|
|
|
211
166
|
file: file
|
|
212
167
|
});
|
|
213
168
|
} catch (e) {
|
|
214
|
-
if ((0, $
|
|
169
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error getting encrypted cookie", e);
|
|
215
170
|
return [];
|
|
216
171
|
}
|
|
217
172
|
}
|
|
@@ -225,7 +180,7 @@ async function $269fe42bfd555305$var$getPromise(name, domain) {
|
|
|
225
180
|
const results1 = await Promise.all(promises);
|
|
226
181
|
return results1.flat().filter((0, $af69dfb8766652d8$export$bc926c43858bd3cb));
|
|
227
182
|
} catch (error) {
|
|
228
|
-
if ((0, $
|
|
183
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("error", error);
|
|
229
184
|
return [];
|
|
230
185
|
}
|
|
231
186
|
}
|
|
@@ -234,7 +189,7 @@ async function $269fe42bfd555305$var$decryptValue(password, encryptedValue) {
|
|
|
234
189
|
try {
|
|
235
190
|
d = await $269fe42bfd555305$var$decrypt(password, encryptedValue);
|
|
236
191
|
} catch (e) {
|
|
237
|
-
if ((0, $
|
|
192
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error decrypting cookie", e);
|
|
238
193
|
d = null;
|
|
239
194
|
}
|
|
240
195
|
return d ?? encryptedValue.toString("utf-8");
|
|
@@ -247,27 +202,33 @@ async function $269fe42bfd555305$var$getChromeCookies({ name: name , domain: dom
|
|
|
247
202
|
const decryptedValue = await $269fe42bfd555305$var$decryptValue(password, encryptedValue);
|
|
248
203
|
const meta = {};
|
|
249
204
|
(0, $7oI3p$lodash.merge)(meta, cookieRow.meta ?? {});
|
|
250
|
-
|
|
205
|
+
const exportedCookie = {
|
|
251
206
|
domain: cookieRow.domain,
|
|
252
207
|
name: cookieRow.name,
|
|
253
208
|
value: decryptedValue,
|
|
254
209
|
meta: meta
|
|
255
210
|
};
|
|
211
|
+
const expiry = cookieRow.expiry;
|
|
212
|
+
if (expiry) (0, $7oI3p$lodash.merge)(exportedCookie, {
|
|
213
|
+
expiry: new Date(expiry)
|
|
214
|
+
});
|
|
215
|
+
return exportedCookie;
|
|
256
216
|
});
|
|
257
217
|
const results = (await Promise.all(decrypted)).filter((0, $d66f40b581ba8bfa$export$963c8d651337e4a4));
|
|
258
|
-
if ((0, $
|
|
218
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("results", results);
|
|
259
219
|
return results;
|
|
260
220
|
}
|
|
261
221
|
const $269fe42bfd555305$var$chromeLocal = $7oI3p$path.join((0, $fac425c10fbbada5$export$a7c5707626fc90f), "Library", "Application Support", "Google", "Chrome");
|
|
262
222
|
async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $7oI3p$path.join($269fe42bfd555305$var$chromeLocal, "Default", "Cookies") }) {
|
|
263
223
|
if (!(0, $7oI3p$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
|
|
264
|
-
if ((0, $
|
|
224
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) {
|
|
265
225
|
const s = file.split("/").slice(-3).join("/");
|
|
266
226
|
console.log(`Trying Chrome (at ${s}) cookie ${name} for domain ${domain}`);
|
|
267
227
|
}
|
|
268
228
|
let sql;
|
|
269
229
|
//language=SQL
|
|
270
|
-
sql = "SELECT
|
|
230
|
+
sql = "SELECT * FROM cookies";
|
|
231
|
+
// sql = "SELECT encrypted_value, name, host_key FROM cookies";
|
|
271
232
|
const wildcardRegexp = /^([*%])$/i;
|
|
272
233
|
const specifiedName = name.match(wildcardRegexp) == null;
|
|
273
234
|
const specifiedDomain = domain.match(wildcardRegexp) == null;
|
|
@@ -286,16 +247,18 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
286
247
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
287
248
|
}
|
|
288
249
|
}
|
|
289
|
-
|
|
290
|
-
const sqliteQuery1 = await (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)({
|
|
250
|
+
const sqliteQuery1 = await $269fe42bfd555305$export$bd52b72df8d0d261({
|
|
291
251
|
file: file,
|
|
292
252
|
sql: sql,
|
|
293
253
|
rowTransform: (row)=>{
|
|
294
|
-
|
|
254
|
+
const cookieRow = {
|
|
255
|
+
expiry: (row["expires_utc"] / 1000000 - 11644473600) * 1000,
|
|
295
256
|
domain: row["host_key"],
|
|
296
257
|
name: row["name"],
|
|
297
258
|
value: row["encrypted_value"]
|
|
298
259
|
};
|
|
260
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("CookieRow", cookieRow);
|
|
261
|
+
return cookieRow;
|
|
299
262
|
}
|
|
300
263
|
});
|
|
301
264
|
return sqliteQuery1.filter((row)=>{
|
|
@@ -313,21 +276,21 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
313
276
|
if (!(encryptedData1 instanceof Buffer)) {
|
|
314
277
|
if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {
|
|
315
278
|
[encryptedData1] = encryptedData1;
|
|
316
|
-
if ((0, $
|
|
279
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
|
|
317
280
|
} else throw new Error("encryptedData must be a Buffer: " + encryptedData1);
|
|
318
281
|
encryptedData1 = Buffer.from(encryptedData1);
|
|
319
282
|
}
|
|
320
|
-
if ((0, $
|
|
283
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`Trying to decrypt with password ${password}`);
|
|
321
284
|
return new Promise((resolve, reject)=>{
|
|
322
285
|
$7oI3p$crypto.pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
|
|
323
286
|
try {
|
|
324
287
|
if (error) {
|
|
325
|
-
if ((0, $
|
|
288
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error doing pbkdf2", error);
|
|
326
289
|
reject(error);
|
|
327
290
|
return;
|
|
328
291
|
}
|
|
329
292
|
if (buffer.length !== 16) {
|
|
330
|
-
if ((0, $
|
|
293
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
|
|
331
294
|
reject(new Error("Buffer length is not 16"));
|
|
332
295
|
return;
|
|
333
296
|
}
|
|
@@ -337,7 +300,7 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
337
300
|
decipher.setAutoPadding(false);
|
|
338
301
|
if (encryptedData1 && encryptedData1.slice) encryptedData1 = encryptedData1.slice(3);
|
|
339
302
|
if (encryptedData1.length % 16 !== 0) {
|
|
340
|
-
if ((0, $
|
|
303
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
|
|
341
304
|
reject(new Error("encryptedData length is not a multiple of 16"));
|
|
342
305
|
return;
|
|
343
306
|
}
|
|
@@ -345,7 +308,7 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
345
308
|
try {
|
|
346
309
|
decipher.final("utf-8");
|
|
347
310
|
} catch (e) {
|
|
348
|
-
if ((0, $
|
|
311
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error doing decipher.final()", e);
|
|
349
312
|
reject(e);
|
|
350
313
|
return;
|
|
351
314
|
}
|
|
@@ -360,6 +323,42 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
360
323
|
});
|
|
361
324
|
});
|
|
362
325
|
}
|
|
326
|
+
async function $269fe42bfd555305$export$bd52b72df8d0d261({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
327
|
+
if (!file || file && !(0, ($parcel$interopDefault($7oI3p$fs))).existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
328
|
+
const db = new $7oI3p$sqlite3.Database(file);
|
|
329
|
+
return new Promise((resolve, reject)=>{
|
|
330
|
+
db.all(sql, (err, rows)=>{
|
|
331
|
+
if (err) {
|
|
332
|
+
reject(err);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const rows1 = rows;
|
|
336
|
+
if (rows1 == null || rows1.length === 0) {
|
|
337
|
+
resolve([]);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (Array.isArray(rows1)) {
|
|
341
|
+
const cookieRows = rows1.map((row)=>{
|
|
342
|
+
const newVar = {
|
|
343
|
+
meta: {
|
|
344
|
+
file: file
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
const cookieRow = rowTransform(row);
|
|
348
|
+
return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
|
|
349
|
+
});
|
|
350
|
+
resolve(cookieRows);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
354
|
+
resolve([
|
|
355
|
+
rows1
|
|
356
|
+
]);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
|
|
363
362
|
|
|
364
363
|
|
|
365
364
|
|
|
@@ -367,6 +366,43 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
367
366
|
|
|
368
367
|
|
|
369
368
|
|
|
369
|
+
|
|
370
|
+
async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
371
|
+
if (!file || file && !$7oI3p$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
372
|
+
const db = new $7oI3p$sqlite3.Database(file);
|
|
373
|
+
return new Promise((resolve, reject)=>{
|
|
374
|
+
db.all(sql, (err, rows)=>{
|
|
375
|
+
if (err) {
|
|
376
|
+
reject(err);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const rows1 = rows;
|
|
380
|
+
if (rows1 == null || rows1.length === 0) {
|
|
381
|
+
resolve([]);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (Array.isArray(rows1)) {
|
|
385
|
+
const cookieRows = rows1.map((row)=>{
|
|
386
|
+
const newVar = {
|
|
387
|
+
meta: {
|
|
388
|
+
file: file
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
const cookieRow = rowTransform(row);
|
|
392
|
+
return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
|
|
393
|
+
});
|
|
394
|
+
resolve(cookieRows);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
398
|
+
resolve([
|
|
399
|
+
rows1
|
|
400
|
+
]);
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
|
|
370
406
|
function $b744d19cc39f964e$export$da22813e5a2ec500({ name: name , domain: domain }) {
|
|
371
407
|
const wildcardRegexp = /^([*%])$/i;
|
|
372
408
|
return {
|
|
@@ -504,8 +540,9 @@ class $e4efb16e005540de$export$2e2bcd8739ae039 {
|
|
|
504
540
|
domain: cookie.domain ?? cookieSpec.domain,
|
|
505
541
|
name: cookie.key ?? cookieSpec.name,
|
|
506
542
|
value: cookie.value,
|
|
543
|
+
expiry: cookie.expires ?? Infinity,
|
|
507
544
|
meta: {
|
|
508
|
-
file: "
|
|
545
|
+
file: "tough-cookie"
|
|
509
546
|
}
|
|
510
547
|
};
|
|
511
548
|
}
|
|
@@ -531,6 +568,8 @@ class $e4efb16e005540de$export$2e2bcd8739ae039 {
|
|
|
531
568
|
|
|
532
569
|
|
|
533
570
|
|
|
571
|
+
|
|
572
|
+
|
|
534
573
|
const $f72befa528c23ca7$var$cache = new (0, ($parcel$interopDefault($7oI3p$lrucache)))({
|
|
535
574
|
ttl: 2000,
|
|
536
575
|
max: 10
|
|
@@ -553,11 +592,18 @@ class $f72befa528c23ca7$export$2e2bcd8739ae039 {
|
|
|
553
592
|
const key = `${name}:${domain}`;
|
|
554
593
|
const cached = $f72befa528c23ca7$var$cache.get(key);
|
|
555
594
|
if (cached) return cached;
|
|
556
|
-
console.log("Querying cookies:", name, domain);
|
|
595
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Querying cookies:", name, domain);
|
|
557
596
|
const results = await Promise.all(this.#strategies.map(async (strategy)=>{
|
|
558
597
|
// @ts-ignore
|
|
559
|
-
|
|
560
|
-
|
|
598
|
+
return strategy.queryCookies(name, domain).then((cookies)=>{
|
|
599
|
+
return cookies.map((cookie)=>{
|
|
600
|
+
return (0, $7oI3p$lodash.merge)(cookie, {
|
|
601
|
+
meta: {
|
|
602
|
+
browser: strategy.browserName
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
}).catch((e)=>{
|
|
561
607
|
console.log((0, $7oI3p$colorette.red)(`Error querying ${strategy.browserName} cookies`), e);
|
|
562
608
|
return [];
|
|
563
609
|
});
|
|
@@ -576,7 +622,7 @@ function $9a6b2ace073cf1d7$export$2e2bcd8739ae039(token) {
|
|
|
576
622
|
const result = (0, ($parcel$interopDefault($7oI3p$jsonwebtoken))).decode(token, {
|
|
577
623
|
complete: true
|
|
578
624
|
});
|
|
579
|
-
if ((0, $
|
|
625
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose && result) console.log(result);
|
|
580
626
|
const payload = result?.payload;
|
|
581
627
|
if (payload) {
|
|
582
628
|
const exp = payload.exp;
|
|
@@ -594,16 +640,19 @@ function $9a6b2ace073cf1d7$export$2e2bcd8739ae039(token) {
|
|
|
594
640
|
|
|
595
641
|
async function $7a068a32d4710f0b$export$e6d428437cf2cacb({ name: name , domain: domain }, strategy = new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)()) {
|
|
596
642
|
const results = await strategy.queryCookies(name, domain);
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
643
|
+
const allCookies = (0, $7oI3p$lodash.uniqBy)(results, JSON.stringify);
|
|
644
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["require-jwt"]) {
|
|
645
|
+
const jwtCookies = [];
|
|
646
|
+
for (const result of allCookies){
|
|
647
|
+
const value = result.value;
|
|
648
|
+
if ((0, $9a6b2ace073cf1d7$export$2e2bcd8739ae039)(value)) jwtCookies.push(result);
|
|
649
|
+
}
|
|
650
|
+
return (0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["single"] ? [
|
|
651
|
+
jwtCookies[0]
|
|
652
|
+
] : jwtCookies;
|
|
653
|
+
} else return (0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["single"] ? [
|
|
654
|
+
allCookies[0]
|
|
655
|
+
] : allCookies;
|
|
607
656
|
}
|
|
608
657
|
|
|
609
658
|
|
|
@@ -617,10 +666,11 @@ async function $8481e2034946cc4b$export$4be65e66cfa2648a(params) {
|
|
|
617
666
|
|
|
618
667
|
|
|
619
668
|
|
|
669
|
+
|
|
620
670
|
async function $1a92ef2038b55530$export$e5637297e9eb6f2e(params) {
|
|
621
671
|
const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $269fe42bfd555305$export$2e2bcd8739ae039)());
|
|
622
|
-
if (
|
|
623
|
-
|
|
672
|
+
if (cookies.length == 0) throw new Error("Cookie not found");
|
|
673
|
+
return cookies.find((0, $d66f40b581ba8bfa$export$963c8d651337e4a4));
|
|
624
674
|
}
|
|
625
675
|
|
|
626
676
|
|
|
@@ -636,29 +686,36 @@ async function $f9b70200901ad17d$export$c44c5fdef43f0941(params) {
|
|
|
636
686
|
|
|
637
687
|
|
|
638
688
|
|
|
639
|
-
|
|
640
689
|
function $9c43c2ed82e63570$export$9abc0a414b0d8b8f(results) {
|
|
641
|
-
|
|
690
|
+
// sort by name and expiry descending
|
|
691
|
+
// takes the latest expiry for each name
|
|
692
|
+
const orderedResults = (0, $7oI3p$lodash.orderBy)(results, [
|
|
693
|
+
"name",
|
|
694
|
+
"expiry"
|
|
695
|
+
], [
|
|
696
|
+
"asc",
|
|
697
|
+
"desc"
|
|
698
|
+
]);
|
|
699
|
+
return (0, $7oI3p$lodash.uniqBy)(orderedResults, (r)=>r.name).map((r)=>r.name + "=" + r.value).join("; ");
|
|
642
700
|
}
|
|
643
701
|
|
|
644
702
|
|
|
645
|
-
|
|
646
|
-
{ name: name , domain: domain }) {
|
|
703
|
+
|
|
704
|
+
async function $300d8b33187a203c$export$4d2e9997e2c23417({ name: name , domain: domain }) {
|
|
647
705
|
const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
|
|
648
706
|
name: name,
|
|
649
707
|
domain: domain
|
|
650
708
|
}, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
|
|
651
|
-
if (
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
} else throw new Error("Cookie not found");
|
|
709
|
+
if (cookies.length == 0) throw new Error("Cookie not found");
|
|
710
|
+
const results = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
|
|
711
|
+
name: name,
|
|
712
|
+
domain: domain
|
|
713
|
+
});
|
|
714
|
+
const groupedByFile = (0, $7oI3p$lodash.groupBy)(results, (r)=>r.meta?.file);
|
|
715
|
+
return Object.keys(groupedByFile).map((file)=>{
|
|
716
|
+
const results = groupedByFile[file];
|
|
717
|
+
return (0, $9c43c2ed82e63570$export$9abc0a414b0d8b8f)(results);
|
|
718
|
+
});
|
|
662
719
|
}
|
|
663
720
|
|
|
664
721
|
|
|
@@ -667,10 +724,13 @@ async function $300d8b33187a203c$export$4d2e9997e2c23417(//
|
|
|
667
724
|
|
|
668
725
|
|
|
669
726
|
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
670
730
|
async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetch = (0, $7oI3p$crossfetch.fetch)) {
|
|
671
731
|
const defaultOptions = {
|
|
672
732
|
headers: {
|
|
673
|
-
"User-Agent":
|
|
733
|
+
"User-Agent": new (0, ($parcel$interopDefault($7oI3p$useragents)))().toString()
|
|
674
734
|
},
|
|
675
735
|
redirect: "manual"
|
|
676
736
|
};
|
|
@@ -699,9 +759,19 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
699
759
|
value
|
|
700
760
|
]);
|
|
701
761
|
});
|
|
702
|
-
for (const [key, value] of headers)if (key === "set-cookie")
|
|
762
|
+
for (const [key, value] of headers)if (key === "set-cookie") {
|
|
763
|
+
await (0, $53a3bcc99a05dfcf$export$928a906645f9d018).setCookie(value, url2);
|
|
764
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Set-Cookie: ${(0, $7oI3p$colorette.yellow)(value)} ${(0, $7oI3p$colorette.yellow)(url2)}`));
|
|
765
|
+
// const cookie = tough.parse(value);
|
|
766
|
+
// if (cookie instanceof Cookie) {
|
|
767
|
+
// await memoryCookieStore.putCookie(cookie);
|
|
768
|
+
// }
|
|
769
|
+
}
|
|
703
770
|
const newUrl = res.headers.get("location");
|
|
704
|
-
if (res.redirected || newUrl && newUrl !== url2)
|
|
771
|
+
if (res.redirected || newUrl && newUrl !== url2) {
|
|
772
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Redirected to `), (0, $7oI3p$colorette.yellow)(newUrl));
|
|
773
|
+
return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(newUrl, newOptions1);
|
|
774
|
+
}
|
|
705
775
|
const arrayBuffer1 = res.arrayBuffer();
|
|
706
776
|
async function arrayBuffer() {
|
|
707
777
|
return arrayBuffer1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mherod/get-cookie",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.8",
|
|
4
4
|
"description": "Node.js module for querying a local user's Chrome cookie",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"bin": "dist/cli.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"clean": "git clean -
|
|
14
|
+
"clean": "git clean -fdX && rm -rf node_modules dist && yarn install",
|
|
15
15
|
"build": "parcel build",
|
|
16
16
|
"prepare": "npm run build && npm run prettier",
|
|
17
17
|
"test": "jest",
|
|
@@ -67,7 +67,8 @@
|
|
|
67
67
|
"minimist": "^1.2.6",
|
|
68
68
|
"sqlite3": "^5.1.1",
|
|
69
69
|
"tough-cookie": "^4.1.2",
|
|
70
|
-
"tough-cookie-file-store": "^2.0.3"
|
|
70
|
+
"tough-cookie-file-store": "^2.0.3",
|
|
71
|
+
"user-agents": "^1.0.1165"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"@parcel/packager-ts": "^2.7.0",
|
package/src/CookieRow.ts
CHANGED
package/src/ExportedCookie.ts
CHANGED
package/src/argv.ts
CHANGED
|
@@ -12,6 +12,10 @@ import { isExportedCookie } from "../IsExportedCookie";
|
|
|
12
12
|
import CookieRow from "../CookieRow";
|
|
13
13
|
import ExportedCookie from "../ExportedCookie";
|
|
14
14
|
import { stringToRegex } from "../StringToRegex";
|
|
15
|
+
import { parsedArgs } from "../argv";
|
|
16
|
+
import fs from "fs";
|
|
17
|
+
import * as sqlite3 from "sqlite3";
|
|
18
|
+
import { DoSqliteQuery1Params } from "../doSqliteQuery1Params";
|
|
15
19
|
|
|
16
20
|
export default class ChromeCookieQueryStrategy implements CookieQueryStrategy {
|
|
17
21
|
browserName = "Chrome";
|
|
@@ -43,7 +47,7 @@ async function getPromise1(
|
|
|
43
47
|
file: file,
|
|
44
48
|
});
|
|
45
49
|
} catch (e) {
|
|
46
|
-
if (
|
|
50
|
+
if (parsedArgs.verbose) {
|
|
47
51
|
console.log("Error getting encrypted cookie", e);
|
|
48
52
|
}
|
|
49
53
|
return [];
|
|
@@ -62,7 +66,7 @@ async function getPromise(name: string, domain: string): Promise<CookieRow[]> {
|
|
|
62
66
|
const results1: CookieRow[][] = await Promise.all(promises);
|
|
63
67
|
return results1.flat().filter(isCookieRow);
|
|
64
68
|
} catch (error) {
|
|
65
|
-
if (
|
|
69
|
+
if (parsedArgs.verbose) {
|
|
66
70
|
console.log("error", error);
|
|
67
71
|
}
|
|
68
72
|
return [];
|
|
@@ -74,7 +78,7 @@ async function decryptValue(password: string, encryptedValue: Buffer) {
|
|
|
74
78
|
try {
|
|
75
79
|
d = await decrypt(password, encryptedValue);
|
|
76
80
|
} catch (e) {
|
|
77
|
-
if (
|
|
81
|
+
if (parsedArgs.verbose) {
|
|
78
82
|
console.log("Error decrypting cookie", e);
|
|
79
83
|
}
|
|
80
84
|
d = null;
|
|
@@ -102,17 +106,24 @@ Promise<ExportedCookie[]> {
|
|
|
102
106
|
const decryptedValue = await decryptValue(password, encryptedValue);
|
|
103
107
|
const meta = {};
|
|
104
108
|
merge(meta, cookieRow.meta ?? {});
|
|
105
|
-
|
|
109
|
+
const exportedCookie: ExportedCookie = {
|
|
106
110
|
domain: cookieRow.domain,
|
|
107
111
|
name: cookieRow.name,
|
|
108
112
|
value: decryptedValue,
|
|
109
113
|
meta: meta,
|
|
110
114
|
};
|
|
115
|
+
const expiry = cookieRow.expiry;
|
|
116
|
+
if (expiry) {
|
|
117
|
+
merge(exportedCookie, {
|
|
118
|
+
expiry: new Date(expiry),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return exportedCookie;
|
|
111
122
|
});
|
|
112
123
|
const results: ExportedCookie[] = (await Promise.all(decrypted)).filter(
|
|
113
124
|
isExportedCookie
|
|
114
125
|
);
|
|
115
|
-
if (
|
|
126
|
+
if (parsedArgs.verbose) {
|
|
116
127
|
console.log("results", results);
|
|
117
128
|
}
|
|
118
129
|
return results;
|
|
@@ -139,13 +150,14 @@ async function getEncryptedChromeCookie({
|
|
|
139
150
|
if (!existsSync(file)) {
|
|
140
151
|
throw new Error(`File ${file} does not exist`);
|
|
141
152
|
}
|
|
142
|
-
if (
|
|
153
|
+
if (parsedArgs.verbose) {
|
|
143
154
|
const s = file.split("/").slice(-3).join("/");
|
|
144
155
|
console.log(`Trying Chrome (at ${s}) cookie ${name} for domain ${domain}`);
|
|
145
156
|
}
|
|
146
157
|
let sql;
|
|
147
158
|
//language=SQL
|
|
148
|
-
sql = "SELECT
|
|
159
|
+
sql = "SELECT * FROM cookies";
|
|
160
|
+
// sql = "SELECT encrypted_value, name, host_key FROM cookies";
|
|
149
161
|
|
|
150
162
|
const wildcardRegexp = /^([*%])$/i;
|
|
151
163
|
const specifiedName = name.match(wildcardRegexp) == null;
|
|
@@ -167,16 +179,20 @@ async function getEncryptedChromeCookie({
|
|
|
167
179
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
168
180
|
}
|
|
169
181
|
}
|
|
170
|
-
|
|
171
|
-
const sqliteQuery1: CookieRow[] = await doSqliteQuery1({
|
|
182
|
+
const sqliteQuery1: CookieRow[] = await doChromeSqliteQuery1({
|
|
172
183
|
file: file,
|
|
173
184
|
sql: sql,
|
|
174
185
|
rowTransform: (row) => {
|
|
175
|
-
|
|
186
|
+
const cookieRow = {
|
|
187
|
+
expiry: (row["expires_utc"] / 1000000 - 11644473600) * 1000,
|
|
176
188
|
domain: row["host_key"],
|
|
177
189
|
name: row["name"],
|
|
178
190
|
value: row["encrypted_value"],
|
|
179
191
|
};
|
|
192
|
+
if (parsedArgs.verbose) {
|
|
193
|
+
console.log("CookieRow", cookieRow);
|
|
194
|
+
}
|
|
195
|
+
return cookieRow;
|
|
180
196
|
},
|
|
181
197
|
});
|
|
182
198
|
return sqliteQuery1.filter((row) => {
|
|
@@ -205,7 +221,7 @@ async function decrypt(
|
|
|
205
221
|
if (!(encryptedData1 instanceof Buffer)) {
|
|
206
222
|
if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {
|
|
207
223
|
[encryptedData1] = encryptedData1;
|
|
208
|
-
if (
|
|
224
|
+
if (parsedArgs.verbose) {
|
|
209
225
|
console.log(
|
|
210
226
|
`encryptedData is an array of buffers, selected first: ${encryptedData1}`
|
|
211
227
|
);
|
|
@@ -215,14 +231,14 @@ async function decrypt(
|
|
|
215
231
|
}
|
|
216
232
|
encryptedData1 = Buffer.from(encryptedData1);
|
|
217
233
|
}
|
|
218
|
-
if (
|
|
234
|
+
if (parsedArgs.verbose) {
|
|
219
235
|
console.log(`Trying to decrypt with password ${password}`);
|
|
220
236
|
}
|
|
221
237
|
return new Promise((resolve, reject) => {
|
|
222
238
|
crypto.pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer) => {
|
|
223
239
|
try {
|
|
224
240
|
if (error) {
|
|
225
|
-
if (
|
|
241
|
+
if (parsedArgs.verbose) {
|
|
226
242
|
console.log("Error doing pbkdf2", error);
|
|
227
243
|
}
|
|
228
244
|
reject(error);
|
|
@@ -230,7 +246,7 @@ async function decrypt(
|
|
|
230
246
|
}
|
|
231
247
|
|
|
232
248
|
if (buffer.length !== 16) {
|
|
233
|
-
if (
|
|
249
|
+
if (parsedArgs.verbose) {
|
|
234
250
|
console.log(
|
|
235
251
|
"Error doing pbkdf2, buffer length is not 16",
|
|
236
252
|
buffer.length
|
|
@@ -250,7 +266,7 @@ async function decrypt(
|
|
|
250
266
|
}
|
|
251
267
|
|
|
252
268
|
if (encryptedData1.length % 16 !== 0) {
|
|
253
|
-
if (
|
|
269
|
+
if (parsedArgs.verbose) {
|
|
254
270
|
console.log(
|
|
255
271
|
"Error doing pbkdf2, encryptedData length is not a multiple of 16",
|
|
256
272
|
encryptedData1.length
|
|
@@ -264,7 +280,7 @@ async function decrypt(
|
|
|
264
280
|
try {
|
|
265
281
|
decipher.final("utf-8");
|
|
266
282
|
} catch (e) {
|
|
267
|
-
if (
|
|
283
|
+
if (parsedArgs.verbose) {
|
|
268
284
|
console.log("Error doing decipher.final()", e);
|
|
269
285
|
}
|
|
270
286
|
reject(e);
|
|
@@ -284,3 +300,44 @@ async function decrypt(
|
|
|
284
300
|
});
|
|
285
301
|
});
|
|
286
302
|
}
|
|
303
|
+
|
|
304
|
+
export async function doChromeSqliteQuery1({
|
|
305
|
+
file,
|
|
306
|
+
sql,
|
|
307
|
+
rowTransform,
|
|
308
|
+
}: DoSqliteQuery1Params): Promise<CookieRow[]> {
|
|
309
|
+
if (!file || (file && !fs.existsSync(file))) {
|
|
310
|
+
throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
311
|
+
}
|
|
312
|
+
const db = new sqlite3.Database(file);
|
|
313
|
+
return new Promise((resolve, reject) => {
|
|
314
|
+
db.all(sql, (err: Error, rows: any[]) => {
|
|
315
|
+
if (err) {
|
|
316
|
+
reject(err);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const rows1: any[] = rows;
|
|
320
|
+
if (rows1 == null || rows1.length === 0) {
|
|
321
|
+
resolve([]);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (Array.isArray(rows1)) {
|
|
325
|
+
const cookieRows: CookieRow[] = rows1.map((row: any) => {
|
|
326
|
+
const newVar = {
|
|
327
|
+
meta: {
|
|
328
|
+
file: file,
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
const cookieRow: CookieRow = rowTransform(row);
|
|
332
|
+
return merge(newVar, cookieRow);
|
|
333
|
+
});
|
|
334
|
+
resolve(cookieRows);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (parsedArgs.verbose) {
|
|
338
|
+
console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
339
|
+
}
|
|
340
|
+
resolve([rows1]);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
@@ -6,6 +6,8 @@ import ExportedCookie from "../ExportedCookie";
|
|
|
6
6
|
import LRUCache from "lru-cache";
|
|
7
7
|
import CookieStoreQueryStrategy from "./CookieStoreQueryStrategy";
|
|
8
8
|
import { red } from "colorette";
|
|
9
|
+
import { merge } from "lodash";
|
|
10
|
+
import { parsedArgs } from "../argv";
|
|
9
11
|
|
|
10
12
|
const cache = new LRUCache<string, ExportedCookie[]>({
|
|
11
13
|
ttl: 1000 * 2,
|
|
@@ -37,18 +39,30 @@ export default class CompositeCookieQueryStrategy
|
|
|
37
39
|
if (cached) {
|
|
38
40
|
return cached;
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
if (parsedArgs.verbose) {
|
|
43
|
+
console.log("Querying cookies:", name, domain);
|
|
44
|
+
}
|
|
41
45
|
const results: ExportedCookie[][] = await Promise.all(
|
|
42
46
|
this.#strategies.map(async (strategy: CookieQueryStrategy) => {
|
|
43
47
|
// @ts-ignore
|
|
44
|
-
|
|
45
|
-
name,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
return strategy
|
|
49
|
+
.queryCookies(name, domain)
|
|
50
|
+
.then((cookies: ExportedCookie[]) => {
|
|
51
|
+
return cookies.map((cookie: ExportedCookie) => {
|
|
52
|
+
return merge(cookie, {
|
|
53
|
+
meta: {
|
|
54
|
+
browser: strategy.browserName,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
})
|
|
59
|
+
.catch((e) => {
|
|
60
|
+
console.log(
|
|
61
|
+
red(`Error querying ${strategy.browserName} cookies`),
|
|
62
|
+
e
|
|
63
|
+
);
|
|
64
|
+
return [];
|
|
65
|
+
});
|
|
52
66
|
})
|
|
53
67
|
);
|
|
54
68
|
const flat: ExportedCookie[] = results.flat();
|
|
@@ -57,8 +57,9 @@ export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
|
|
|
57
57
|
domain: cookie.domain ?? cookieSpec.domain,
|
|
58
58
|
name: cookie.key ?? cookieSpec.name,
|
|
59
59
|
value: cookie.value,
|
|
60
|
+
expiry: cookie.expires ?? Infinity,
|
|
60
61
|
meta: {
|
|
61
|
-
file: "
|
|
62
|
+
file: "tough-cookie",
|
|
62
63
|
},
|
|
63
64
|
};
|
|
64
65
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { argv } from "./argv";
|
|
3
|
+
import { argv, parsedArgs } from "./argv";
|
|
5
4
|
import { queryCookies } from "./queryCookies";
|
|
6
5
|
import { groupBy } from "lodash";
|
|
7
6
|
import { green, red, yellow } from "colorette";
|
|
@@ -10,8 +9,6 @@ import { fetchWithCookies } from "./fetchWithCookies";
|
|
|
10
9
|
import { unpackHeaders } from "./unpackHeaders";
|
|
11
10
|
import CookieSpec from "./CookieSpec";
|
|
12
11
|
|
|
13
|
-
const parsedArgs: minimist.ParsedArgs = minimist(argv.slice(2));
|
|
14
|
-
|
|
15
12
|
async function cliQueryCookies({ name, domain }: CookieSpec) {
|
|
16
13
|
try {
|
|
17
14
|
const results = await queryCookies({ name, domain });
|
package/src/doSqliteQuery1.ts
CHANGED
|
@@ -2,12 +2,8 @@ import * as fs from "fs";
|
|
|
2
2
|
import * as sqlite3 from "sqlite3";
|
|
3
3
|
import CookieRow from "./CookieRow";
|
|
4
4
|
import { merge } from "lodash";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
file: string;
|
|
8
|
-
sql: string;
|
|
9
|
-
rowTransform: (row: any) => CookieRow;
|
|
10
|
-
}
|
|
5
|
+
import { parsedArgs } from "./argv";
|
|
6
|
+
import { DoSqliteQuery1Params } from "./doSqliteQuery1Params";
|
|
11
7
|
|
|
12
8
|
export async function doSqliteQuery1({
|
|
13
9
|
file,
|
|
@@ -42,7 +38,7 @@ export async function doSqliteQuery1({
|
|
|
42
38
|
resolve(cookieRows);
|
|
43
39
|
return;
|
|
44
40
|
}
|
|
45
|
-
if (
|
|
41
|
+
if (parsedArgs.verbose) {
|
|
46
42
|
console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
47
43
|
}
|
|
48
44
|
resolve([rows1]);
|
package/src/fetchWithCookies.ts
CHANGED
|
@@ -7,6 +7,9 @@ import destr from "destr";
|
|
|
7
7
|
import CookieSpec from "./CookieSpec";
|
|
8
8
|
import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
|
|
9
9
|
import { cookieJar } from "./CookieStore";
|
|
10
|
+
import UserAgent from "user-agents";
|
|
11
|
+
import { parsedArgs } from "./argv";
|
|
12
|
+
import { blue, yellow } from "colorette";
|
|
10
13
|
|
|
11
14
|
export async function fetchWithCookies(
|
|
12
15
|
url: RequestInfo | URL,
|
|
@@ -15,8 +18,7 @@ export async function fetchWithCookies(
|
|
|
15
18
|
): Promise<Response> {
|
|
16
19
|
const defaultOptions: RequestInit = {
|
|
17
20
|
headers: {
|
|
18
|
-
"User-Agent":
|
|
19
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
|
|
21
|
+
"User-Agent": new UserAgent().toString(),
|
|
20
22
|
},
|
|
21
23
|
redirect: "manual",
|
|
22
24
|
};
|
|
@@ -47,6 +49,9 @@ export async function fetchWithCookies(
|
|
|
47
49
|
for (const [key, value] of headers) {
|
|
48
50
|
if (key === "set-cookie") {
|
|
49
51
|
await cookieJar.setCookie(value, url2);
|
|
52
|
+
if (parsedArgs.verbose) {
|
|
53
|
+
console.log(blue(`Set-Cookie: ${yellow(value)} ${yellow(url2)}`));
|
|
54
|
+
}
|
|
50
55
|
// const cookie = tough.parse(value);
|
|
51
56
|
// if (cookie instanceof Cookie) {
|
|
52
57
|
// await memoryCookieStore.putCookie(cookie);
|
|
@@ -56,6 +61,9 @@ export async function fetchWithCookies(
|
|
|
56
61
|
|
|
57
62
|
const newUrl: string = res.headers.get("location") as string;
|
|
58
63
|
if (res.redirected || (newUrl && newUrl !== url2)) {
|
|
64
|
+
if (parsedArgs.verbose) {
|
|
65
|
+
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
66
|
+
}
|
|
59
67
|
return fetchWithCookies(newUrl, newOptions1);
|
|
60
68
|
}
|
|
61
69
|
|
package/src/findAllFiles.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { env } from "./global";
|
|
2
1
|
import * as fs from "fs";
|
|
2
|
+
import { parsedArgs } from "./argv";
|
|
3
3
|
|
|
4
4
|
export async function findAllFiles({
|
|
5
5
|
path,
|
|
@@ -12,16 +12,12 @@ export async function findAllFiles({
|
|
|
12
12
|
maxDepth?: number;
|
|
13
13
|
}): Promise<string[]> {
|
|
14
14
|
const rootSegments = path.split("/").length;
|
|
15
|
-
|
|
16
|
-
if (env.VERBOSE) {
|
|
17
|
-
console.log(`Searching for ${name} in ${path}`);
|
|
18
|
-
}
|
|
19
15
|
const files: string[] = [];
|
|
20
16
|
let readdirSync;
|
|
21
17
|
try {
|
|
22
18
|
readdirSync = fs.readdirSync(path);
|
|
23
19
|
} catch (e) {
|
|
24
|
-
if (
|
|
20
|
+
if (parsedArgs.verbose) {
|
|
25
21
|
console.log(`Error reading ${path}`, e);
|
|
26
22
|
}
|
|
27
23
|
return [];
|
|
@@ -32,7 +28,7 @@ export async function findAllFiles({
|
|
|
32
28
|
try {
|
|
33
29
|
stat = fs.statSync(filePath);
|
|
34
30
|
} catch (e) {
|
|
35
|
-
if (
|
|
31
|
+
if (parsedArgs.verbose) {
|
|
36
32
|
console.error(`Error getting stat for ${filePath}`, e);
|
|
37
33
|
}
|
|
38
34
|
continue;
|
|
@@ -47,7 +43,7 @@ export async function findAllFiles({
|
|
|
47
43
|
});
|
|
48
44
|
files.push(...subFiles);
|
|
49
45
|
} catch (e) {
|
|
50
|
-
if (
|
|
46
|
+
if (parsedArgs.verbose) {
|
|
51
47
|
console.error(e);
|
|
52
48
|
}
|
|
53
49
|
}
|
|
@@ -56,7 +52,7 @@ export async function findAllFiles({
|
|
|
56
52
|
files.push(filePath);
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
|
-
if (
|
|
55
|
+
if (parsedArgs.verbose) {
|
|
60
56
|
if (files.length > 0) {
|
|
61
57
|
console.log(`Found ${files.length} ${name} files`);
|
|
62
58
|
console.log(files);
|
package/src/getChromeCookie.ts
CHANGED
|
@@ -2,6 +2,7 @@ import CookieSpec from "./CookieSpec";
|
|
|
2
2
|
import ExportedCookie from "./ExportedCookie";
|
|
3
3
|
import { queryCookies } from "./queryCookies";
|
|
4
4
|
import ChromeCookieQueryStrategy from "./browsers/ChromeCookieQueryStrategy";
|
|
5
|
+
import { isExportedCookie } from "./IsExportedCookie";
|
|
5
6
|
|
|
6
7
|
export async function getChromeCookie(
|
|
7
8
|
params: CookieSpec
|
|
@@ -11,9 +12,8 @@ export async function getChromeCookie(
|
|
|
11
12
|
new ChromeCookieQueryStrategy()
|
|
12
13
|
//
|
|
13
14
|
);
|
|
14
|
-
if (
|
|
15
|
-
return cookies.find((cookie) => cookie != null);
|
|
16
|
-
} else {
|
|
15
|
+
if (cookies.length == 0) {
|
|
17
16
|
throw new Error("Cookie not found");
|
|
18
17
|
}
|
|
18
|
+
return cookies.find(isExportedCookie);
|
|
19
19
|
}
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import { queryCookies } from "./queryCookies";
|
|
2
|
-
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
3
1
|
import { groupBy } from "lodash";
|
|
2
|
+
import { queryCookies } from "./queryCookies";
|
|
4
3
|
import { resultsRendered } from "./resultsRendered";
|
|
4
|
+
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
5
5
|
import CookieSpec from "./CookieSpec";
|
|
6
6
|
import ExportedCookie from "./ExportedCookie";
|
|
7
7
|
|
|
8
|
-
export async function getGroupedRenderedCookies(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
domain,
|
|
13
|
-
}: //
|
|
14
|
-
CookieSpec
|
|
15
|
-
): //
|
|
16
|
-
Promise<string[]> {
|
|
8
|
+
export async function getGroupedRenderedCookies({
|
|
9
|
+
name,
|
|
10
|
+
domain,
|
|
11
|
+
}: CookieSpec): Promise<string[]> {
|
|
17
12
|
const cookies: ExportedCookie[] = await queryCookies(
|
|
18
|
-
{
|
|
13
|
+
{
|
|
14
|
+
name,
|
|
15
|
+
domain,
|
|
16
|
+
},
|
|
19
17
|
new CompositeCookieQueryStrategy()
|
|
20
18
|
//
|
|
21
19
|
);
|
|
22
|
-
if (
|
|
23
|
-
const results: ExportedCookie[] = await queryCookies({ name, domain });
|
|
24
|
-
const groupedByFile = groupBy(results, (r) => r.meta?.file);
|
|
25
|
-
return Object.keys(groupedByFile).map((file: string) => {
|
|
26
|
-
const results: ExportedCookie[] = groupedByFile[file];
|
|
27
|
-
return resultsRendered(results);
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
20
|
+
if (cookies.length == 0) {
|
|
30
21
|
throw new Error("Cookie not found");
|
|
31
22
|
}
|
|
23
|
+
const results: ExportedCookie[] = await queryCookies({ name, domain });
|
|
24
|
+
const groupedByFile = groupBy(results, (r: ExportedCookie) => r.meta?.file);
|
|
25
|
+
return Object.keys(groupedByFile).map((file: string) => {
|
|
26
|
+
const results: ExportedCookie[] = groupedByFile[file];
|
|
27
|
+
return resultsRendered(results);
|
|
28
|
+
});
|
|
32
29
|
}
|
package/src/isValidJwt.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import jsonwebtoken, { JwtPayload } from "jsonwebtoken";
|
|
2
|
-
import {
|
|
2
|
+
import { parsedArgs } from "./argv";
|
|
3
3
|
|
|
4
4
|
export default function isValidJwt(token: any) {
|
|
5
5
|
try {
|
|
6
6
|
const result = jsonwebtoken.decode(token, { complete: true });
|
|
7
|
-
if (
|
|
7
|
+
if (parsedArgs.verbose && result) {
|
|
8
8
|
console.log(result);
|
|
9
9
|
}
|
|
10
10
|
const payload: JwtPayload = result?.payload as JwtPayload;
|
package/src/queryCookies.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { env } from "./global";
|
|
2
1
|
import { uniqBy } from "lodash";
|
|
2
|
+
import { parsedArgs } from "./argv";
|
|
3
3
|
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
4
4
|
import CookieQueryStrategy from "./browsers/CookieQueryStrategy";
|
|
5
5
|
import isValidJwt from "./isValidJwt";
|
|
@@ -9,16 +9,20 @@ import ExportedCookie from "./ExportedCookie";
|
|
|
9
9
|
export async function queryCookies(
|
|
10
10
|
{ name, domain }: CookieSpec,
|
|
11
11
|
strategy: CookieQueryStrategy = new CompositeCookieQueryStrategy()
|
|
12
|
-
) {
|
|
12
|
+
): Promise<ExportedCookie[]> {
|
|
13
13
|
const results: ExportedCookie[] = await strategy.queryCookies(name, domain);
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const allCookies: ExportedCookie[] = uniqBy(results, JSON.stringify);
|
|
15
|
+
|
|
16
|
+
if (parsedArgs["require-jwt"]) {
|
|
17
|
+
const jwtCookies = [];
|
|
18
|
+
for (const result of allCookies) {
|
|
19
|
+
const value: string = result.value;
|
|
20
|
+
if (isValidJwt(value)) {
|
|
21
|
+
jwtCookies.push(result);
|
|
22
|
+
}
|
|
20
23
|
}
|
|
24
|
+
return parsedArgs["single"] ? [jwtCookies[0]] : jwtCookies;
|
|
25
|
+
} else {
|
|
26
|
+
return parsedArgs["single"] ? [allCookies[0]] : allCookies;
|
|
21
27
|
}
|
|
22
|
-
const resultsUniq = env.REQUIRE_JWT ? jwtCookies : results1;
|
|
23
|
-
return env.SINGLE ? [resultsUniq[0]] : resultsUniq;
|
|
24
28
|
}
|
package/src/resultsRendered.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { uniqBy } from "lodash";
|
|
1
|
+
import { orderBy, uniqBy } from "lodash";
|
|
2
2
|
import ExportedCookie from "./ExportedCookie";
|
|
3
3
|
|
|
4
4
|
export function resultsRendered(results: ExportedCookie[]) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// sort by name and expiry descending
|
|
6
|
+
// takes the latest expiry for each name
|
|
7
|
+
const orderedResults = orderBy(results, ["name", "expiry"], ["asc", "desc"]);
|
|
8
|
+
return uniqBy(orderedResults, (r: ExportedCookie) => r.name)
|
|
9
|
+
.map((r: ExportedCookie) => r.name + "=" + r.value)
|
|
7
10
|
.join("; ");
|
|
8
11
|
}
|
package/src/utils.ts
CHANGED
|
@@ -23,28 +23,3 @@ export async function execSimple(command: string): Promise<string> {
|
|
|
23
23
|
);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
export function toStringOrNull(result: any) {
|
|
28
|
-
if (result == null) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
if (process.env.VERBOSE) {
|
|
32
|
-
console.log("result", result);
|
|
33
|
-
}
|
|
34
|
-
if (typeof result === "string" && result.length > 0) {
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
if (result.slice && result.toString) {
|
|
38
|
-
// noinspection JSCheckFunctionSignatures
|
|
39
|
-
return result.toString("utf8");
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function invalidString(input: any): boolean {
|
|
45
|
-
return typeof input !== "string" || input.length === 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function validString(input: any): input is string {
|
|
49
|
-
return typeof input == "string" && input.length > 0;
|
|
50
|
-
}
|