@mherod/get-cookie 1.3.0 → 2.0.0-beta.3
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/.idea/codeStyles/Project.xml +59 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/get-cookie.iml +1 -0
- package/.prettierrc.json +1 -0
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/main.js +335 -288
- package/dist/main.js.map +1 -1
- package/package.json +15 -6
- package/src/CookieRow.ts +21 -0
- package/src/argv.js +1 -0
- package/src/browsers/AbstractCookieQueryStrategy.ts +10 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +256 -0
- package/src/browsers/CompositeCookieQueryStrategy.ts +31 -0
- package/src/browsers/FirefoxCookieQueryStrategy.ts +92 -0
- package/src/browsers/SafariCookieQueryStrategy.ts +3 -0
- package/src/cli.js +77 -45
- package/src/doSqliteQuery1.ts +47 -0
- package/src/findAllFiles.ts +68 -0
- package/src/global.ts +7 -0
- package/src/index.js +38 -439
- package/src/isValidJwt.ts +14 -0
- package/src/queryCookies.ts +28 -0
- package/src/utils.ts +118 -0
- package/tsconfig.json +23 -0
- package/src/global.js +0 -3
- package/src/utils.js +0 -185
package/src/cli.js
CHANGED
|
@@ -2,57 +2,89 @@
|
|
|
2
2
|
|
|
3
3
|
import { version } from "../package.json";
|
|
4
4
|
import { env } from "./global";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (argv.length > 2) {
|
|
10
|
-
if (argv.includes("--version") || argv.includes("-v")) {
|
|
11
|
-
console.log(version);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
5
|
+
import { queryCookies } from "./queryCookies";
|
|
6
|
+
import { argv } from "./argv";
|
|
7
|
+
import { groupBy, uniqBy } from "lodash";
|
|
8
|
+
import { blue, green } from "colorette";
|
|
14
9
|
|
|
15
|
-
|
|
10
|
+
function combinedString(results) {
|
|
11
|
+
return blue(
|
|
12
|
+
uniqBy(results, (r) => r.name)
|
|
13
|
+
.map((r) => r.name + "=" + r.value)
|
|
14
|
+
.join("; ")
|
|
15
|
+
);
|
|
16
|
+
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
async function cliQueryCookies(name, domain) {
|
|
19
|
+
try {
|
|
20
|
+
const results = await queryCookies({ name, domain });
|
|
21
|
+
if (results.length > 0) {
|
|
22
|
+
if (argv.includes("--combined-string")) {
|
|
23
|
+
console.log(combinedString(results));
|
|
24
|
+
} else if (argv.includes("--dump")) {
|
|
25
|
+
console.log(results);
|
|
26
|
+
} else if (argv.includes("--dump-grouped")) {
|
|
27
|
+
const groupedByFile = groupBy(results, (r) => r.meta?.file);
|
|
28
|
+
console.log(green(JSON.stringify(groupedByFile, null, 2)));
|
|
29
|
+
} else if (argv.includes("--combined-string-grouped")) {
|
|
30
|
+
const groupedByFile = groupBy(results, (r) => r.meta?.file);
|
|
31
|
+
for (const file of Object.keys(groupedByFile)) {
|
|
32
|
+
let results = groupedByFile[file];
|
|
33
|
+
console.log(green(file) + ": ", combinedString(results));
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
for (const result of results) {
|
|
37
|
+
console.log(result.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
20
40
|
} else {
|
|
21
|
-
|
|
41
|
+
console.error("No results");
|
|
22
42
|
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.error(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
23
47
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
if (argv.includes("--chrome-only")) {
|
|
31
|
-
env.CHROME_ONLY = "true";
|
|
32
|
-
}
|
|
33
|
-
if (argv.includes("--firefox-only")) {
|
|
34
|
-
env.FIREFOX_ONLY = "true";
|
|
35
|
-
}
|
|
36
|
-
if (argv.includes("--ignore-expired")) {
|
|
37
|
-
env.IGNORE_EXPIRED = "true";
|
|
38
|
-
}
|
|
48
|
+
if (argv && argv.length > 2) {
|
|
49
|
+
if (argv.includes("--version") || argv.includes("-v")) {
|
|
50
|
+
console.log(version);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
39
53
|
|
|
40
|
-
|
|
41
|
-
console.log("Verbose mode", argv);
|
|
42
|
-
}
|
|
54
|
+
const name = argv[2];
|
|
43
55
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
let domain;
|
|
57
|
+
if (argv[3] != null && argv[3].indexOf(".") > -1) {
|
|
58
|
+
domain = argv[3];
|
|
59
|
+
} else {
|
|
60
|
+
domain = "%";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const tru = `${true}`;
|
|
64
|
+
|
|
65
|
+
if (argv.includes("--require-jwt")) {
|
|
66
|
+
env.REQUIRE_JWT = tru;
|
|
67
|
+
}
|
|
68
|
+
if (argv.includes("--verbose")) {
|
|
69
|
+
env.VERBOSE = tru;
|
|
70
|
+
}
|
|
71
|
+
if (argv.includes("--chrome-only")) {
|
|
72
|
+
env.CHROME_ONLY = tru;
|
|
73
|
+
}
|
|
74
|
+
if (argv.includes("--firefox-only")) {
|
|
75
|
+
env.FIREFOX_ONLY = tru;
|
|
57
76
|
}
|
|
77
|
+
if (argv.includes("--ignore-expired")) {
|
|
78
|
+
env.IGNORE_EXPIRED = tru;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (argv.includes("--single")) {
|
|
82
|
+
env.SINGLE = tru;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (env.VERBOSE) {
|
|
86
|
+
console.log("Verbose mode", argv);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
cliQueryCookies(name, domain).catch(console.error);
|
|
58
90
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as sqlite3 from "sqlite3";
|
|
3
|
+
import {CookieRow} from "./CookieRow";
|
|
4
|
+
|
|
5
|
+
export async function doSqliteQuery1(file: string, sql: string): Promise<CookieRow[]> {
|
|
6
|
+
if (!fs.existsSync(file)) {
|
|
7
|
+
throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
8
|
+
}
|
|
9
|
+
const db = new sqlite3.Database(file);
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
db.all(sql, (err: Error, rows: any[]) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
if (process.env.VERBOSE) {
|
|
14
|
+
console.log(`doSqliteQuery1: error ${err}`);
|
|
15
|
+
}
|
|
16
|
+
reject(err);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const rows1: any[] = rows;
|
|
20
|
+
if (rows1 == null || rows1.length === 0) {
|
|
21
|
+
if (process.env.VERBOSE) {
|
|
22
|
+
console.log(`doSqliteQuery1: no rows`);
|
|
23
|
+
}
|
|
24
|
+
resolve([]);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(rows1)) {
|
|
28
|
+
const cookieRows: CookieRow[] = rows1.map((row) => {
|
|
29
|
+
return {
|
|
30
|
+
domain: row["host_key"],
|
|
31
|
+
name: row["name"],
|
|
32
|
+
value: row["encrypted_value"],
|
|
33
|
+
meta: {
|
|
34
|
+
file: file
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
resolve(cookieRows);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (process.env.VERBOSE) {
|
|
42
|
+
console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
43
|
+
}
|
|
44
|
+
resolve([rows1]);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { env } from "./global";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
|
|
4
|
+
export async function findAllFiles(
|
|
5
|
+
{
|
|
6
|
+
path,
|
|
7
|
+
name,
|
|
8
|
+
maxDepth = 2
|
|
9
|
+
//
|
|
10
|
+
}: {
|
|
11
|
+
path: string;
|
|
12
|
+
name: string;
|
|
13
|
+
maxDepth?: number;
|
|
14
|
+
}
|
|
15
|
+
): Promise<string[]> {
|
|
16
|
+
const rootSegments = path.split("/").length;
|
|
17
|
+
|
|
18
|
+
if (env.VERBOSE) {
|
|
19
|
+
console.log(`Searching for ${name} in ${path}`);
|
|
20
|
+
}
|
|
21
|
+
const files: string[] = [];
|
|
22
|
+
let readdirSync;
|
|
23
|
+
try {
|
|
24
|
+
readdirSync = fs.readdirSync(path);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
if (env.VERBOSE) {
|
|
27
|
+
console.log(`Error reading ${path}`, e);
|
|
28
|
+
}
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
for (const file of readdirSync) {
|
|
32
|
+
const filePath = path + "/" + file;
|
|
33
|
+
let stat;
|
|
34
|
+
try {
|
|
35
|
+
stat = fs.statSync(filePath);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (env.VERBOSE) {
|
|
38
|
+
console.error(`Error getting stat for ${filePath}`, e);
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (stat.isDirectory()) {
|
|
43
|
+
if (filePath.split("/").length < rootSegments + maxDepth) {
|
|
44
|
+
try {
|
|
45
|
+
const subFiles = await findAllFiles({
|
|
46
|
+
path: filePath,
|
|
47
|
+
name: name,
|
|
48
|
+
maxDepth: 2
|
|
49
|
+
});
|
|
50
|
+
files.push(...subFiles);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
if (env.VERBOSE) {
|
|
53
|
+
console.error(e);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else if (file === name) {
|
|
58
|
+
files.push(filePath);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (env.VERBOSE) {
|
|
62
|
+
if (files.length > 0) {
|
|
63
|
+
console.log(`Found ${files.length} ${name} files`);
|
|
64
|
+
console.log(files);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return files;
|
|
68
|
+
}
|