@mherod/get-cookie 1.2.0 → 1.3.0
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/prettier.xml +8 -0
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -0
- package/dist/main.js +430 -0
- package/dist/main.js.map +1 -0
- package/package.json +37 -5
- package/src/cli.js +58 -0
- package/src/global.js +3 -0
- package/src/index.js +462 -0
- package/src/utils.js +185 -0
- package/cli.js +0 -48
- package/index.js +0 -424
- package/utils.js +0 -175
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="PrettierConfiguration">
|
|
4
|
+
<option name="myRunOnSave" value="true" />
|
|
5
|
+
<option name="myRunOnReformat" value="true" />
|
|
6
|
+
<option name="myFilesPattern" value="src/{**/*,*}.{js,json}" />
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var e=require("lodash"),r=require("jsonwebtoken"),o=require("fs"),n=require("crypto"),t=require("child_process"),i=require("sqlite3");function s(e){return e&&e.__esModule?e.default:e}var l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},c={},a={},f=l.parcelRequire5c26;null==f&&((f=function(e){if(e in c)return c[e].exports;if(e in a){var r=a[e];delete a[e];var o={id:e,exports:{}};return c[e]=o,r.call(o.exports,o,o.exports),o.exports}var n=new Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}).register=function(e,r){a[e]=r},l.parcelRequire5c26=f),f.register("1rMxC",(function(e,r){var o=f("9MSW1"),n=f("lITtf"),t=f("2USPI").getCookie;const i=process.argv;if(i&&i.length>2){if(i.includes("--version")||i.includes("-v"))return void console.log(o.version);const e=i[2];let r;r=null!=i[3]&&i[3].indexOf(".")>-1?i[3]:"%",i.includes("--require-jwt")&&(n.env.REQUIRE_JWT="true"),i.includes("--verbose")&&(n.env.VERBOSE="true"),i.includes("--chrome-only")&&(n.env.CHROME_ONLY="true"),i.includes("--firefox-only")&&(n.env.FIREFOX_ONLY="true"),i.includes("--ignore-expired")&&(n.env.IGNORE_EXPIRED="true"),n.env.VERBOSE&&console.log("Verbose mode",i),t({name:e,domain:r,requireJwt:"true"===n.env.REQUIRE_JWT}).then((e=>{"string"==typeof e&&console.log(e)})).catch((e=>{console.error(e)}))}})),f.register("9MSW1",(function(e,r){e.exports=JSON.parse('{"name":"@mherod/get-cookie","version":"1.3.0","description":"Node.js module for querying a local user\'s Chrome cookie","source":"src/index.js","bin":"dist/cli.js","main":"dist/main.js","module":"dist/module.js","publishConfig":{"access":"public"},"scripts":{"clean":"git clean -fXd","build":"parcel build","test":"jest","postbuild":"npm run install:global","install:global":"npm install --force --global .","postinstall:global":"find $NVM_BIN -exec chmod +x {} \\\\; || true","prettier":"prettier --write \'src/{**/*,*}.{js,json}\'"},"targets":{"main":{"source":"src/index.js","distDir":"dist","engines":{"node":"16"}},"cli":{"source":"src/cli.js","distDir":"dist","engines":{"node":"16"}}},"@parcel/transformer-js":{"inlineFS":false,"inlineEnvironment":false},"engines":{"node":"16"},"keywords":[],"author":"Matthew Herod","license":"ISC","dependencies":{"jsonwebtoken":"^8.5.1","lodash":"^4.17.21","sqlite3":"^5.0.8"},"devDependencies":{"jest":"^28.1.0","prettier":"^2.7.1"}}')})),f.register("lITtf",(function(r,o){var n,t,i,s;n=r.exports,t="env",i=()=>c,Object.defineProperty(n,t,{get:i,set:s,enumerable:!0,configurable:!0});var l=e.merge;const c={};l(c,process.env)})),f.register("2USPI",(function(e,t){var i=f("lITtf");if("darwin"!==process.platform)throw new Error("This script only works on macOS");var l=f("7c49e"),c=l.execSimple,a=l.toStringOrNull,u=l.doSqliteQuery1,g=l.toStringValue;async function p({name:e,domain:r}){if(e&&"string"!=typeof e)throw new Error("name must be a string");if(r&&"string"!=typeof r)throw new Error("domain must be a string");const[n]=await m({path:`${i.env.HOME}/Library/Application Support/Firefox/Profiles`,name:"cookies.sqlite"});if(n&&!s(o).existsSync(n))throw new Error(`File ${n} does not exist`);let t;return i.env.VERBOSE&&console.log(`Trying Firefox cookie ${e} for domain ${r}`),t="SELECT value FROM moz_cookies","string"!=typeof e&&"string"!=typeof r||(t+=" WHERE ","string"==typeof e&&(t+=`name = '${e}'`,"string"==typeof r&&(t+=" AND ")),"string"==typeof r&&(t+=`host LIKE '${r}';`)),await u(n,t).then((e=>e.map(a).find((e=>null!==e))))}const E=`${i.env.HOME}/Library/Application Support/Google/Chrome`,d=`${E}/Default/Cookies`;async function y(e,r){if("string"!=typeof e)throw new Error("password must be a string: "+e);let o;if(o=r,null==o||"object"!=typeof o)throw new Error("encryptedData must be a object: "+o);if(!(o instanceof Buffer)){if(!(Array.isArray(o)&&o[0]instanceof Buffer))throw new Error("encryptedData must be a Buffer: "+o);[o]=o,i.env.VERBOSE&&console.log(`encryptedData is an array of buffers, selected first: ${o}`),o=Buffer.from(o)}return i.env.VERBOSE&&console.log(`Trying to decrypt with password ${e}`),new Promise(((r,t)=>{s(n).pbkdf2(e,"saltysalt",1003,16,"sha1",((e,l)=>{try{if(e)return i.env.VERBOSE&&console.log("Error doing pbkdf2",e),void t(e);if(16!==l.length)return i.env.VERBOSE&&console.log("Error doing pbkdf2, buffer length is not 16",l.length),void t(new Error("Buffer length is not 16"));const c=new Buffer.from(new Array(17).join(" "),"binary"),a=s(n).createDecipheriv("aes-128-cbc",l,c);if(a.setAutoPadding(!1),o&&o.slice&&(o=o.slice(3)),o.length%16!=0)return i.env.VERBOSE&&console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16",o.length),void t(new Error("encryptedData length is not a multiple of 16"));let f=a.update(o);try{a.final("utf-8")}catch(e){return i.env.VERBOSE&&console.log("Error doing decipher.final()",e),void t(e)}let u=f[f.length-1];u&&(f=f.slice(0,0-u)),f=f.toString("utf8"),r(f)}catch(e){t(e)}}))}))}async function h({name:e,domain:n="%",requireJwt:t=!1}){if(e&&"string"!=typeof e)throw new Error("name must be a string");if("string"!=typeof n)throw new Error("domain must be a string");const l=await m({path:E,name:"Cookies"}).then((r=>{const t=r.map((r=>async function({name:e,domain:r,file:n=d}){if(e&&"string"!=typeof e)throw new Error("name must be a string");if(r&&"string"!=typeof r)throw new Error("domain must be a string");if(n&&"string"!=typeof n)throw new Error("file must be a string");if(!s(o).existsSync(n))throw new Error(`File ${n} does not exist`);let t;return i.env.VERBOSE&&console.log(`Trying Chrome (at ${n.split("/").slice(-3).join("/")}) cookie ${e} for domain ${r}`),t="SELECT encrypted_value FROM cookies","string"!=typeof e&&"string"!=typeof r||(t+=" WHERE ","string"==typeof e&&(t+=`name = '${e}'`,"string"==typeof r&&(t+=" AND ")),"string"==typeof r&&(t+=`host_key LIKE '${r}';`)),await u(n,t)}({name:e,domain:n,file:r}).catch((e=>(i.env.VERBOSE&&console.log("Error getting encrypted cookie",e),[])))));return Promise.all(t).then((e=>e.flat())).then((e=>(i.env.VERBOSE&&console.log("getEncryptedChromeCookie results",e),e.filter((e=>e)))))})).catch((e=>(i.env.VERBOSE&&console.log("error",e),[]))),f=await async function(){return c('security find-generic-password -w -s "Chrome Safe Storage"')}();i.env.VERBOSE&&console.log("encryptedDataItems",l);const g=l.filter((e=>null!=e&&e.length>0)).map((async e=>{let r;i.env.VERBOSE&&console.log("Received encrypted",e);try{r=await y(f,e)}catch(e){return i.env.VERBOSE&&console.log("Error decrypting cookie",e),null}return r?(i.env.VERBOSE&&console.log("Decrypted",r),r):null})),p=await Promise.all(g);return i.env.VERBOSE&&console.log("results",p),p.map(a).find((e=>"string"==typeof e&&e.length>0&&(!1===t||function(e){if("string"!=typeof e)return!1;try{const o=r.decode(e,{complete:!0});return i.env.VERBOSE&&console.log(o),!0}catch(e){return!1}}(e))))}async function m({path:e,name:r,maxDepth:n=2}){if("string"!=typeof e)throw new Error("path must be a string");if("string"!=typeof r)throw new Error("name must be a string");const t=e.split("/").length;i.env.VERBOSE&&console.log(`Searching for ${r} in ${e}`);const l=[];let c;try{c=s(o).readdirSync(e)}catch(r){return i.env.VERBOSE&&console.log(`Error reading ${e}`,r),l}for(const a of c){const c=e+"/"+a;let f;try{f=s(o).statSync(c)}catch(e){i.env.VERBOSE&&console.error(`Error getting stat for ${c}`,e);continue}if(f.isDirectory()){if(c.split("/").length<t+n)try{const e=await m({path:c,name:r,rootSegments:t,maxDepth:2});l.push(...e)}catch(e){i.env.VERBOSE&&console.error(e)}}else a===r&&l.push(c)}return i.env.VERBOSE&&l.length>0&&(console.log(`Found ${l.length} ${r} files`),console.log(l)),l}e.exports={getDecryptedCookie:h,getChromeCookie:h,getFirefoxCookie:p,getCookie:async function(e){return i.env.CHROME_ONLY?(i.env.VERBOSE&&console.log("chrome only"),h(e).then((e=>{if(e&&e.length>0)return g(e)})).catch((e=>{i.env.VERBOSE&&console.error(e)}))):i.env.FIREFOX_ONLY?(i.env.VERBOSE&&console.log("firefox only"),p(e).then((e=>e.toString("utf8"))).then((e=>{if(e&&e.length>0)return g(e);console.log("No cookie found")})).catch((e=>{i.env.VERBOSE&&console.error("Error getting Firefox cookie",e)}))):await h(e).catch((e=>{i.env.VERBOSE&&console.error("Error getting Chrome cookie",e)})).then((r=>"string"==typeof r&&r.trim().length>0?r:p(e).catch((e=>{i.env.VERBOSE&&console.error("Error getting Firefox cookie",e)})))).catch((e=>{i.env.VERBOSE&&console.error("Error getting Chrome or Firefox cookie",e)})).then(g)},decrypt:y}})),f.register("7c49e",(function(e,r){var n=t.exec;e.exports={execSimple:async function(e){if("string"!=typeof e)throw new TypeError("execSimple: command must be a string");return process.env.VERBOSE&&console.log(e),new Promise(((r,o)=>{n(e,{encoding:"binary",maxBuffer:5120},((e,n,t)=>{e||t?o(e):n&&r(n.toString("utf8").trim())}))}))},execAsBuffer:async function(e){if("string"!=typeof e)throw new TypeError("execAsBuffer: command must be a string");return process.env.VERBOSE&&console.log(e),await new Promise(((r,o)=>{n(e,{encoding:"binary",maxBuffer:5120},((e,n,t)=>{if(e)return void o(e);if(t)return void o(e);let i=n;"string"==typeof i&&i.length>0&&(i=Buffer.from(i,"binary").slice(0,-1)),i&&i.length>0&&r(i)}))}))},printStringValue:function(e){process.env.VERBOSE&&console.log("Printing value",e),e&&("string"==typeof e?console.log(e):e.toString&&console.log(e.toString("utf8")))},toStringValue:function(e){if(process.env.VERBOSE&&console.log("Printing value",e),e){if("string"==typeof e)return e;if(e.toString)return e.toString("utf8")}},toStringOrNull:function(e){return null==e?null:(process.env.VERBOSE&&console.log("result",e),"string"==typeof e&&e.length>0?e:e.slice&&e.toString?e.toString("utf8"):null)},doSqliteQuery1:async function(e,r){if("string"!=typeof r)throw new TypeError("doSqliteQuery1: sql must be a string");if("string"!=typeof e)throw new TypeError("doSqliteQuery1: file must be a string");if(!o.existsSync(e))throw new Error(`doSqliteQuery1: file ${e} does not exist`);process.env.VERBOSE&&(console.log(`doSqliteQuery1: file ${e}`),console.log(`doSqliteQuery1: sql ${r}`));const n=new i.Database(e);return new Promise(((e,o)=>{n.all(r,((r,n)=>{if(r)return process.env.VERBOSE&&console.log(`doSqliteQuery1: error ${r}`),void o(r);const t=n;if(null==t||0===t.length)return process.env.VERBOSE&&console.log("doSqliteQuery1: no rows"),void e([]);if(Array.isArray(t)){process.env.VERBOSE&&console.log(`doSqliteQuery1: ${t.length} rows`);const r=t.flatMap((e=>Object.values(e))).map((e=>Buffer.from(e,"binary")));return process.env.VERBOSE&&console.log(`doSqliteQuery1: ${r.length} buffers`),void e(r)}process.env.VERBOSE&&console.log(`doSqliteQuery1: rows ${JSON.stringify(t)}`),e([t])}))}))}}})),f("1rMxC");
|
|
3
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";6rBAAA,IAAAA,EAAAC,EAAA,S,0BAIMC,UAEN,MAAMC,E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esContent":["#!/usr/bin/env node\n\nimport { version } from \"../package.json\";\nimport { env } from \"./global\";\nconst { getCookie } = require(\"./index\");\n\nconst argv = process.argv;\nif (argv) {\n if (argv.length > 2) {\n if (argv.includes(\"--version\") || argv.includes(\"-v\")) {\n console.log(version);\n return;\n }\n\n const name = argv[2];\n\n let domain;\n if (argv[3] != null && argv[3].indexOf(\".\") > -1) {\n domain = argv[3];\n } else {\n domain = \"%\";\n }\n\n if (argv.includes(\"--require-jwt\")) {\n env.REQUIRE_JWT = \"true\";\n }\n if (argv.includes(\"--verbose\")) {\n env.VERBOSE = \"true\";\n }\n if (argv.includes(\"--chrome-only\")) {\n env.CHROME_ONLY = \"true\";\n }\n if (argv.includes(\"--firefox-only\")) {\n env.FIREFOX_ONLY = \"true\";\n }\n if (argv.includes(\"--ignore-expired\")) {\n env.IGNORE_EXPIRED = \"true\";\n }\n\n if (env.VERBOSE) {\n console.log(\"Verbose mode\", argv);\n }\n\n getCookie({\n name: name,\n domain: domain,\n requireJwt: env.REQUIRE_JWT === \"true\",\n })\n .then((cookie) => {\n if (typeof cookie === \"string\") {\n console.log(cookie);\n }\n })\n .catch((err) => {\n console.error(err);\n });\n }\n}\n","{\n \"name\": \"@mherod/get-cookie\",\n \"version\": \"1.3.0\",\n \"description\": \"Node.js module for querying a local user's Chrome cookie\",\n \"source\": \"src/index.js\",\n \"bin\": \"dist/cli.js\",\n \"main\": \"dist/main.js\",\n \"module\": \"dist/module.js\",\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"scripts\": {\n \"clean\": \"git clean -fXd\",\n \"build\": \"parcel build\",\n \"test\": \"jest\",\n \"postbuild\": \"npm run install:global\",\n \"install:global\": \"npm install --force --global .\",\n \"postinstall:global\": \"find $NVM_BIN -exec chmod +x {} \\\\; || true\",\n \"prettier\": \"prettier --write 'src/{**/*,*}.{js,json}'\"\n },\n \"targets\": {\n \"main\": {\n \"source\": \"src/index.js\",\n \"distDir\": \"dist\",\n \"engines\": {\n \"node\": \"16\"\n }\n },\n \"cli\": {\n \"source\": \"src/cli.js\",\n \"distDir\": \"dist\",\n \"engines\": {\n \"node\": \"16\"\n }\n }\n },\n \"@parcel/transformer-js\": {\n \"inlineFS\": false,\n \"inlineEnvironment\": false\n },\n \"engines\": {\n \"node\": \"16\"\n },\n \"keywords\": [],\n \"author\": \"Matthew Herod\",\n \"license\": \"ISC\",\n \"dependencies\": {\n \"jsonwebtoken\": \"^8.5.1\",\n \"lodash\": \"^4.17.21\",\n \"sqlite3\": \"^5.0.8\"\n },\n \"devDependencies\": {\n \"jest\": \"^28.1.0\",\n \"prettier\": \"^2.7.1\"\n }\n}\n","const { merge } = require(\"lodash\");\nexport const env = {};\nmerge(env, process.env);\n","#!/usr/bin/env node\n\nimport fs from \"fs\";\nimport crypto from \"crypto\";\nimport { env } from \"./global\";\n\nif (process.platform !== \"darwin\") {\n throw new Error(\"This script only works on macOS\");\n}\n\nconst {\n execSimple,\n toStringOrNull,\n doSqliteQuery1,\n toStringValue,\n} = require(\"./utils\");\nconst jsonwebtoken = require(\"jsonwebtoken\");\n\nfunction isValidJwt(token) {\n if (typeof token !== \"string\") {\n return false;\n }\n try {\n const result = jsonwebtoken.decode(token, { complete: true });\n if (env.VERBOSE) {\n console.log(result);\n }\n return true;\n } catch (err) {\n return false;\n }\n}\n\n/**\n *\n * @returns {Promise<string>}\n */\nasync function getChromePassword() {\n return execSimple(\n 'security find-generic-password -w -s \"Chrome Safe Storage\"'\n );\n}\n\n/**\n *\n * @param params\n * @returns {Promise<string>}\n */\nasync function getCookie(params) {\n if (env.CHROME_ONLY) {\n if (env.VERBOSE) {\n console.log(\"chrome only\");\n }\n return getChromeCookie(params)\n .then((cookie) => {\n if (cookie && cookie.length > 0) {\n return toStringValue(cookie);\n }\n })\n .catch((err) => {\n if (env.VERBOSE) {\n console.error(err);\n }\n });\n } else if (env.FIREFOX_ONLY) {\n if (env.VERBOSE) {\n console.log(\"firefox only\");\n }\n return getFirefoxCookie(params)\n .then((b) => b.toString(\"utf8\"))\n .then((cookie) => {\n if (cookie && cookie.length > 0) {\n return toStringValue(cookie);\n } else {\n console.log(\"No cookie found\");\n }\n })\n .catch((err) => {\n if (env.VERBOSE) {\n console.error(\"Error getting Firefox cookie\", err);\n }\n });\n } else {\n return await getChromeCookie(params)\n .catch((err) => {\n if (env.VERBOSE) {\n console.error(\"Error getting Chrome cookie\", err);\n }\n })\n .then((r) => {\n if (typeof r === \"string\" && r.trim().length > 0) {\n return r;\n } else {\n return getFirefoxCookie(params).catch((err) => {\n if (env.VERBOSE) {\n console.error(\"Error getting Firefox cookie\", err);\n }\n });\n }\n })\n .catch((e) => {\n if (env.VERBOSE) {\n console.error(\"Error getting Chrome or Firefox cookie\", e);\n }\n })\n .then(toStringValue);\n }\n}\n\n/**\n *\n * @param name\n * @param domain\n * @returns {Promise<Buffer>}\n */\nasync function getFirefoxCookie({ name, domain }) {\n if (name && typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n if (domain && typeof domain !== \"string\") {\n throw new Error(\"domain must be a string\");\n }\n const [file] = await findAllFiles({\n path: `${env.HOME}/Library/Application Support/Firefox/Profiles`,\n name: \"cookies.sqlite\",\n });\n if (file && !fs.existsSync(file)) {\n throw new Error(`File ${file} does not exist`);\n }\n if (env.VERBOSE) {\n console.log(`Trying Firefox cookie ${name} for domain ${domain}`);\n }\n let sql;\n sql = \"SELECT value FROM moz_cookies\";\n if (typeof name === \"string\" || typeof domain === \"string\") {\n sql += ` WHERE `;\n if (typeof name === \"string\") {\n sql += `name = '${name}'`;\n if (typeof domain === \"string\") {\n sql += ` AND `;\n }\n }\n if (typeof domain === \"string\") {\n sql += `host LIKE '${domain}';`;\n }\n }\n return await doSqliteQuery1(file, sql).then((rows) => {\n return rows.map(toStringOrNull).find((v) => v !== null);\n });\n}\n\nconst defaultChromeRoot = `${env.HOME}/Library/Application Support/Google/Chrome`;\nconst defaultChromeCookies = `${defaultChromeRoot}/Default/Cookies`;\n\nasync function getEncryptedChromeCookie({\n name,\n domain,\n file = defaultChromeCookies,\n}) {\n if (name && typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n if (domain && typeof domain !== \"string\") {\n throw new Error(\"domain must be a string\");\n }\n if (file && typeof file !== \"string\") {\n throw new Error(\"file must be a string\");\n }\n if (!fs.existsSync(file)) {\n throw new Error(`File ${file} does not exist`);\n }\n if (env.VERBOSE) {\n console.log(\n `Trying Chrome (at ${file\n .split(\"/\")\n .slice(-3)\n .join(\"/\")}) cookie ${name} for domain ${domain}`\n );\n }\n let sql;\n sql = `SELECT encrypted_value FROM cookies`;\n if (typeof name === \"string\" || typeof domain === \"string\") {\n sql += ` WHERE `;\n if (typeof name === \"string\") {\n sql += `name = '${name}'`;\n if (typeof domain === \"string\") {\n sql += ` AND `;\n }\n }\n if (typeof domain === \"string\") {\n sql += `host_key LIKE '${domain}';`;\n }\n }\n return await doSqliteQuery1(file, sql);\n}\n\n/**\n *\n * @param {string} password\n * @param {Buffer} encryptedData\n * @returns {Promise<string>}\n */\nasync function decrypt(password, encryptedData) {\n if (typeof password !== \"string\") {\n throw new Error(\"password must be a string: \" + password);\n }\n let encryptedData1;\n encryptedData1 = encryptedData;\n if (encryptedData1 == null || typeof encryptedData1 !== \"object\") {\n throw new Error(\"encryptedData must be a object: \" + encryptedData1);\n }\n if (!(encryptedData1 instanceof Buffer)) {\n if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {\n [encryptedData1] = encryptedData1;\n if (env.VERBOSE) {\n console.log(\n `encryptedData is an array of buffers, selected first: ${encryptedData1}`\n );\n }\n } else {\n throw new Error(\"encryptedData must be a Buffer: \" + encryptedData1);\n }\n encryptedData1 = Buffer.from(encryptedData1);\n }\n if (env.VERBOSE) {\n console.log(`Trying to decrypt with password ${password}`);\n }\n return new Promise((resolve, reject) => {\n crypto.pbkdf2(password, \"saltysalt\", 1003, 16, \"sha1\", (error, buffer) => {\n try {\n if (error) {\n if (env.VERBOSE) {\n console.log(\"Error doing pbkdf2\", error);\n }\n reject(error);\n return;\n }\n\n if (buffer.length !== 16) {\n if (env.VERBOSE) {\n console.log(\n \"Error doing pbkdf2, buffer length is not 16\",\n buffer.length\n );\n }\n reject(new Error(\"Buffer length is not 16\"));\n return;\n }\n\n const iv = new Buffer.from(new Array(17).join(\" \"), \"binary\");\n const decipher = crypto.createDecipheriv(\"aes-128-cbc\", buffer, iv);\n decipher.setAutoPadding(false);\n\n if (encryptedData1 && encryptedData1.slice) {\n encryptedData1 = encryptedData1.slice(3);\n }\n\n if (encryptedData1.length % 16 !== 0) {\n if (env.VERBOSE) {\n console.log(\n \"Error doing pbkdf2, encryptedData length is not a multiple of 16\",\n encryptedData1.length\n );\n }\n reject(new Error(\"encryptedData length is not a multiple of 16\"));\n return;\n }\n\n let decoded = decipher.update(encryptedData1);\n try {\n decipher.final(\"utf-8\");\n } catch (e) {\n if (env.VERBOSE) {\n console.log(\"Error doing decipher.final()\", e);\n }\n reject(e);\n return;\n }\n\n let padding = decoded[decoded.length - 1];\n if (padding) {\n decoded = decoded.slice(0, 0 - padding);\n }\n // noinspection JSCheckFunctionSignatures\n decoded = decoded.toString(\"utf8\");\n resolve(decoded);\n } catch (e) {\n reject(e);\n }\n });\n });\n}\n\n/**\n *\n * @param {string|undefined} name\n * @param {string} domain\n * @param {boolean} requireJwt\n * @returns {Promise<string>}\n */\nasync function getChromeCookie({ name, domain = \"%\", requireJwt = false }) {\n if (name && typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n if (typeof domain !== \"string\") {\n throw new Error(\"domain must be a string\");\n }\n const encryptedDataItems = await findAllFiles({\n path: defaultChromeRoot,\n name: \"Cookies\",\n })\n .then((files) => {\n const promises = files.map((file) => {\n return getEncryptedChromeCookie({\n name: name,\n domain: domain,\n file: file,\n }).catch((e) => {\n if (env.VERBOSE) {\n console.log(\"Error getting encrypted cookie\", e);\n }\n return [];\n });\n });\n return Promise.all(promises)\n .then((results) => results.flat())\n .then((results) => {\n if (env.VERBOSE) {\n console.log(\"getEncryptedChromeCookie results\", results);\n }\n return results.filter((result) => {\n return result;\n });\n });\n })\n .catch((error) => {\n if (env.VERBOSE) {\n console.log(\"error\", error);\n }\n return [];\n });\n const password = await getChromePassword();\n if (env.VERBOSE) {\n console.log(\"encryptedDataItems\", encryptedDataItems);\n }\n const decrypted = encryptedDataItems\n .filter((encryptedData) => {\n return encryptedData != null && encryptedData.length > 0;\n })\n .map(async (encryptedData) => {\n if (env.VERBOSE) {\n console.log(\"Received encrypted\", encryptedData);\n }\n let decrypted;\n try {\n decrypted = await decrypt(password, encryptedData);\n } catch (e) {\n if (env.VERBOSE) {\n console.log(\"Error decrypting cookie\", e);\n }\n return null;\n }\n if (decrypted) {\n if (env.VERBOSE) {\n console.log(\"Decrypted\", decrypted);\n }\n return decrypted;\n }\n return null;\n });\n const results = await Promise.all(decrypted);\n if (env.VERBOSE) {\n console.log(\"results\", results);\n }\n return results.map(toStringOrNull).find((result) => {\n return (\n typeof result === \"string\" &&\n result.length > 0 &&\n (requireJwt === false || isValidJwt(result))\n );\n });\n}\n\n/**\n *\n * @param path\n * @param name\n * @param rootSegments\n * @param maxDepth\n * @returns {Promise<[string]>}\n */\nasync function findAllFiles({ path, name, maxDepth = 2 }) {\n if (typeof path !== \"string\") {\n throw new Error(\"path must be a string\");\n }\n if (typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n\n const rootSegments = path.split(\"/\").length;\n\n if (env.VERBOSE) {\n console.log(`Searching for ${name} in ${path}`);\n }\n const files = [];\n let readdirSync;\n try {\n readdirSync = fs.readdirSync(path);\n } catch (e) {\n if (env.VERBOSE) {\n console.log(`Error reading ${path}`, e);\n }\n return files;\n }\n for (const file of readdirSync) {\n const filePath = path + \"/\" + file;\n let stat;\n try {\n stat = fs.statSync(filePath);\n } catch (e) {\n if (env.VERBOSE) {\n console.error(`Error getting stat for ${filePath}`, e);\n }\n continue;\n }\n if (stat.isDirectory()) {\n if (filePath.split(\"/\").length < rootSegments + maxDepth) {\n try {\n const subFiles = await findAllFiles({\n path: filePath,\n name: name,\n rootSegments: rootSegments,\n maxDepth: 2,\n });\n files.push(...subFiles);\n } catch (e) {\n if (env.VERBOSE) {\n console.error(e);\n }\n }\n }\n } else if (file === name) {\n files.push(filePath);\n }\n }\n if (env.VERBOSE) {\n if (files.length > 0) {\n console.log(`Found ${files.length} ${name} files`);\n console.log(files);\n }\n }\n return files;\n}\n\n// noinspection JSUnusedGlobalSymbols\nmodule.exports = {\n getDecryptedCookie: getChromeCookie,\n getChromeCookie,\n getFirefoxCookie,\n getCookie,\n decrypt,\n};\n","// noinspection JSUnusedGlobalSymbols\n\nconst { exec } = require(\"child_process\");\nconst fs = require(\"fs\");\n\nasync function execSimple(command) {\n if (typeof command !== \"string\") {\n throw new TypeError(\"execSimple: command must be a string\");\n }\n if (process.env.VERBOSE) {\n console.log(command);\n }\n return new Promise((resolve, reject) => {\n exec(\n command,\n { encoding: \"binary\", maxBuffer: 5 * 1024 },\n (error, stdout, stderr) => {\n if (error) {\n reject(error);\n return;\n }\n if (stderr) {\n reject(error);\n return;\n }\n if (stdout) {\n resolve(stdout.toString(\"utf8\").trim());\n }\n }\n );\n });\n}\n\nasync function execAsBuffer(command) {\n if (typeof command !== \"string\") {\n throw new TypeError(\"execAsBuffer: command must be a string\");\n }\n if (process.env.VERBOSE) {\n console.log(command);\n }\n return await new Promise((resolve, reject) => {\n exec(\n command,\n { encoding: \"binary\", maxBuffer: 5 * 1024 },\n (error, stdout, stderr) => {\n if (error) {\n reject(error);\n return;\n }\n if (stderr) {\n reject(error);\n return;\n }\n let stdoutAsBuffer = stdout;\n if (typeof stdoutAsBuffer === \"string\" && stdoutAsBuffer.length > 0) {\n // noinspection JSCheckFunctionSignatures\n stdoutAsBuffer = Buffer.from(stdoutAsBuffer, \"binary\").slice(0, -1);\n }\n if (stdoutAsBuffer && stdoutAsBuffer.length > 0) {\n resolve(stdoutAsBuffer);\n }\n }\n );\n });\n}\n\nfunction toStringValue(r) {\n if (process.env.VERBOSE) {\n console.log(\"Printing value\", r);\n }\n if (r) {\n if (typeof r === \"string\") {\n return r;\n } else if (r.toString) {\n // noinspection JSCheckFunctionSignatures\n return r.toString(\"utf8\");\n }\n }\n}\n\nfunction printStringValue(r) {\n if (process.env.VERBOSE) {\n console.log(\"Printing value\", r);\n }\n if (r) {\n if (typeof r === \"string\") {\n console.log(r);\n } else if (r.toString) {\n // noinspection JSCheckFunctionSignatures\n console.log(r.toString(\"utf8\"));\n }\n }\n}\n\n/**\n *\n * @param result\n * @returns {string|null}\n */\nfunction toStringOrNull(result) {\n if (result == null) {\n return null;\n }\n if (process.env.VERBOSE) {\n console.log(\"result\", result);\n }\n if (typeof result === \"string\" && result.length > 0) {\n return result;\n }\n if (result.slice && result.toString) {\n // noinspection JSCheckFunctionSignatures\n return result.toString(\"utf8\");\n }\n return null;\n}\n\n/**\n *\n * @param {string} file\n * @param {string} sql\n * @returns {Promise<Buffer[]>}\n */\nasync function doSqliteQuery1(file, sql) {\n if (typeof sql !== \"string\") {\n throw new TypeError(\"doSqliteQuery1: sql must be a string\");\n }\n if (typeof file !== \"string\") {\n throw new TypeError(\"doSqliteQuery1: file must be a string\");\n }\n if (!fs.existsSync(file)) {\n throw new Error(`doSqliteQuery1: file ${file} does not exist`);\n }\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: file ${file}`);\n console.log(`doSqliteQuery1: sql ${sql}`);\n }\n const sqlite3 = require(\"sqlite3\");\n const db = new sqlite3.Database(file);\n return new Promise((resolve, reject) => {\n db.all(sql, (err, rows) => {\n if (err) {\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: error ${err}`);\n }\n reject(err);\n return;\n }\n const rows1 = rows;\n if (rows1 == null || rows1.length === 0) {\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: no rows`);\n }\n resolve([]);\n return;\n }\n if (Array.isArray(rows1)) {\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: ${rows1.length} rows`);\n }\n // noinspection JSCheckFunctionSignatures\n const buffers = rows1\n .flatMap((row) => Object.values(row))\n .map((v) => Buffer.from(v, \"binary\"));\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: ${buffers.length} buffers`);\n }\n resolve(buffers);\n return;\n }\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);\n }\n resolve([rows1]);\n });\n });\n}\n\nmodule.exports = {\n execSimple: execSimple,\n execAsBuffer: execAsBuffer,\n printStringValue: printStringValue,\n toStringValue,\n toStringOrNull: toStringOrNull,\n doSqliteQuery1,\n};\n"],"names":["$9MSW1","parcelRequire","getCookie","argv","process","length","includes","console","log","version","name","domain","indexOf","$lITtf","env","REQUIRE_JWT","VERBOSE","CHROME_ONLY","FIREFOX_ONLY","IGNORE_EXPIRED","$10ddf75b38f5e3b5$require$getCookie","requireJwt","then","cookie","catch","err","error","module","exports","JSON","parse","$hEvgT$lodash","merge","$fd08bc5d4f8fdcf9$export$a7b6bc01c63cdfc3","$fd08bc5d4f8fdcf9$require$merge","platform","Error","$7c49e","execSimple","toStringOrNull","doSqliteQuery1","toStringValue","async","$21fb586e79321a7b$var$getFirefoxCookie","file","$21fb586e79321a7b$var$findAllFiles","path","HOME","$parcel$interopDefault","$hEvgT$fs","existsSync","sql","$21fb586e79321a7b$require$doSqliteQuery1","rows","map","$21fb586e79321a7b$require$toStringOrNull","find","v","$21fb586e79321a7b$var$defaultChromeRoot","$21fb586e79321a7b$var$defaultChromeCookies","$21fb586e79321a7b$var$decrypt","password","encryptedData","encryptedData1","Buffer","Array","isArray","from","Promise","resolve","reject","$hEvgT$crypto","pbkdf2","buffer","iv","join","decipher","createDecipheriv","setAutoPadding","slice","decoded","update","final","e","padding","toString","e1","$21fb586e79321a7b$var$getChromeCookie","encryptedDataItems","files","promises","split","$21fb586e79321a7b$var$getEncryptedChromeCookie","all","results","flat","filter","result","$21fb586e79321a7b$require$execSimple","$21fb586e79321a7b$var$getChromePassword","decrypted","token","$hEvgT$jsonwebtoken","decode","complete","$21fb586e79321a7b$var$isValidJwt","maxDepth","rootSegments","readdirSync","filePath","stat","statSync","isDirectory","subFiles","push","e2","getDecryptedCookie","params","$21fb586e79321a7b$require$toStringValue","b","r","trim","$hEvgT$child_process","exec","command","TypeError","$53ccdf0f5343f791$require$exec","encoding","maxBuffer","stdout","stderr","execAsBuffer","stdoutAsBuffer","printStringValue","db","$hEvgT$sqlite3","Database","rows1","buffers","flatMap","row","Object","values","stringify"],"version":3,"file":"cli.js.map","sourceRoot":"../"}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var $bU6Ve$jsonwebtoken = require("jsonwebtoken");
|
|
3
|
+
var $bU6Ve$fs = require("fs");
|
|
4
|
+
var $bU6Ve$crypto = require("crypto");
|
|
5
|
+
var $bU6Ve$lodash = require("lodash");
|
|
6
|
+
var $bU6Ve$child_process = require("child_process");
|
|
7
|
+
var $bU6Ve$sqlite3 = require("sqlite3");
|
|
8
|
+
|
|
9
|
+
function $parcel$interopDefault(a) {
|
|
10
|
+
return a && a.__esModule ? a.default : a;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var $fa5ed5287f8fdf72$require$merge = $bU6Ve$lodash.merge;
|
|
16
|
+
const $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3 = {};
|
|
17
|
+
$fa5ed5287f8fdf72$require$merge($fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3, process.env);
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if (process.platform !== "darwin") throw new Error("This script only works on macOS");
|
|
21
|
+
var $c0cdc003fbf917f0$exports = {};
|
|
22
|
+
|
|
23
|
+
var $c0cdc003fbf917f0$require$exec = $bU6Ve$child_process.exec;
|
|
24
|
+
|
|
25
|
+
async function $c0cdc003fbf917f0$var$execSimple(command) {
|
|
26
|
+
if (typeof command !== "string") throw new TypeError("execSimple: command must be a string");
|
|
27
|
+
if (process.env.VERBOSE) console.log(command);
|
|
28
|
+
return new Promise((resolve, reject)=>{
|
|
29
|
+
$c0cdc003fbf917f0$require$exec(command, {
|
|
30
|
+
encoding: "binary",
|
|
31
|
+
maxBuffer: 5120
|
|
32
|
+
}, (error, stdout, stderr)=>{
|
|
33
|
+
if (error) {
|
|
34
|
+
reject(error);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (stderr) {
|
|
38
|
+
reject(error);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (stdout) resolve(stdout.toString("utf8").trim());
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async function $c0cdc003fbf917f0$var$execAsBuffer(command) {
|
|
46
|
+
if (typeof command !== "string") throw new TypeError("execAsBuffer: command must be a string");
|
|
47
|
+
if (process.env.VERBOSE) console.log(command);
|
|
48
|
+
return await new Promise((resolve, reject)=>{
|
|
49
|
+
$c0cdc003fbf917f0$require$exec(command, {
|
|
50
|
+
encoding: "binary",
|
|
51
|
+
maxBuffer: 5120
|
|
52
|
+
}, (error, stdout, stderr)=>{
|
|
53
|
+
if (error) {
|
|
54
|
+
reject(error);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (stderr) {
|
|
58
|
+
reject(error);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let stdoutAsBuffer = stdout;
|
|
62
|
+
if (typeof stdoutAsBuffer === "string" && stdoutAsBuffer.length > 0) // noinspection JSCheckFunctionSignatures
|
|
63
|
+
stdoutAsBuffer = Buffer.from(stdoutAsBuffer, "binary").slice(0, -1);
|
|
64
|
+
if (stdoutAsBuffer && stdoutAsBuffer.length > 0) resolve(stdoutAsBuffer);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function $c0cdc003fbf917f0$var$toStringValue(r) {
|
|
69
|
+
if (process.env.VERBOSE) console.log("Printing value", r);
|
|
70
|
+
if (r) {
|
|
71
|
+
if (typeof r === "string") return r;
|
|
72
|
+
else if (r.toString) // noinspection JSCheckFunctionSignatures
|
|
73
|
+
return r.toString("utf8");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function $c0cdc003fbf917f0$var$printStringValue(r) {
|
|
77
|
+
if (process.env.VERBOSE) console.log("Printing value", r);
|
|
78
|
+
if (r) {
|
|
79
|
+
if (typeof r === "string") console.log(r);
|
|
80
|
+
else if (r.toString) // noinspection JSCheckFunctionSignatures
|
|
81
|
+
console.log(r.toString("utf8"));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @param result
|
|
87
|
+
* @returns {string|null}
|
|
88
|
+
*/ function $c0cdc003fbf917f0$var$toStringOrNull(result) {
|
|
89
|
+
if (result == null) return null;
|
|
90
|
+
if (process.env.VERBOSE) console.log("result", result);
|
|
91
|
+
if (typeof result === "string" && result.length > 0) return result;
|
|
92
|
+
if (result.slice && result.toString) // noinspection JSCheckFunctionSignatures
|
|
93
|
+
return result.toString("utf8");
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param {string} file
|
|
100
|
+
* @param {string} sql
|
|
101
|
+
* @returns {Promise<Buffer[]>}
|
|
102
|
+
*/ async function $c0cdc003fbf917f0$var$doSqliteQuery1(file, sql) {
|
|
103
|
+
if (typeof sql !== "string") throw new TypeError("doSqliteQuery1: sql must be a string");
|
|
104
|
+
if (typeof file !== "string") throw new TypeError("doSqliteQuery1: file must be a string");
|
|
105
|
+
if (!$bU6Ve$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
106
|
+
if (process.env.VERBOSE) {
|
|
107
|
+
console.log(`doSqliteQuery1: file ${file}`);
|
|
108
|
+
console.log(`doSqliteQuery1: sql ${sql}`);
|
|
109
|
+
}
|
|
110
|
+
const sqlite3 = $bU6Ve$sqlite3;
|
|
111
|
+
const db = new sqlite3.Database(file);
|
|
112
|
+
return new Promise((resolve, reject)=>{
|
|
113
|
+
db.all(sql, (err, rows)=>{
|
|
114
|
+
if (err) {
|
|
115
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: error ${err}`);
|
|
116
|
+
reject(err);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const rows1 = rows;
|
|
120
|
+
if (rows1 == null || rows1.length === 0) {
|
|
121
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: no rows`);
|
|
122
|
+
resolve([]);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (Array.isArray(rows1)) {
|
|
126
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: ${rows1.length} rows`);
|
|
127
|
+
// noinspection JSCheckFunctionSignatures
|
|
128
|
+
const buffers = rows1.flatMap((row)=>Object.values(row)).map((v)=>Buffer.from(v, "binary"));
|
|
129
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: ${buffers.length} buffers`);
|
|
130
|
+
resolve(buffers);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (process.env.VERBOSE) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
134
|
+
resolve([
|
|
135
|
+
rows1
|
|
136
|
+
]);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
$c0cdc003fbf917f0$exports = {
|
|
141
|
+
execSimple: $c0cdc003fbf917f0$var$execSimple,
|
|
142
|
+
execAsBuffer: $c0cdc003fbf917f0$var$execAsBuffer,
|
|
143
|
+
printStringValue: $c0cdc003fbf917f0$var$printStringValue,
|
|
144
|
+
toStringValue: $c0cdc003fbf917f0$var$toStringValue,
|
|
145
|
+
toStringOrNull: $c0cdc003fbf917f0$var$toStringOrNull,
|
|
146
|
+
doSqliteQuery1: $c0cdc003fbf917f0$var$doSqliteQuery1
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
var $af7abeb0794bd6fa$require$execSimple = $c0cdc003fbf917f0$exports.execSimple;
|
|
151
|
+
var $af7abeb0794bd6fa$require$toStringOrNull = $c0cdc003fbf917f0$exports.toStringOrNull;
|
|
152
|
+
var $af7abeb0794bd6fa$require$doSqliteQuery1 = $c0cdc003fbf917f0$exports.doSqliteQuery1;
|
|
153
|
+
var $af7abeb0794bd6fa$require$toStringValue = $c0cdc003fbf917f0$exports.toStringValue;
|
|
154
|
+
|
|
155
|
+
function $af7abeb0794bd6fa$var$isValidJwt(token) {
|
|
156
|
+
if (typeof token !== "string") return false;
|
|
157
|
+
try {
|
|
158
|
+
const result = $bU6Ve$jsonwebtoken.decode(token, {
|
|
159
|
+
complete: true
|
|
160
|
+
});
|
|
161
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(result);
|
|
162
|
+
return true;
|
|
163
|
+
} catch (err) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
*
|
|
169
|
+
* @returns {Promise<string>}
|
|
170
|
+
*/ async function $af7abeb0794bd6fa$var$getChromePassword() {
|
|
171
|
+
return $af7abeb0794bd6fa$require$execSimple('security find-generic-password -w -s "Chrome Safe Storage"');
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
*
|
|
175
|
+
* @param params
|
|
176
|
+
* @returns {Promise<string>}
|
|
177
|
+
*/ async function $af7abeb0794bd6fa$var$getCookie(params) {
|
|
178
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).CHROME_ONLY) {
|
|
179
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("chrome only");
|
|
180
|
+
return $af7abeb0794bd6fa$var$getChromeCookie(params).then((cookie)=>{
|
|
181
|
+
if (cookie && cookie.length > 0) return $af7abeb0794bd6fa$require$toStringValue(cookie);
|
|
182
|
+
}).catch((err)=>{
|
|
183
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(err);
|
|
184
|
+
});
|
|
185
|
+
} else if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) {
|
|
186
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("firefox only");
|
|
187
|
+
return $af7abeb0794bd6fa$var$getFirefoxCookie(params).then((b)=>b.toString("utf8")).then((cookie)=>{
|
|
188
|
+
if (cookie && cookie.length > 0) return $af7abeb0794bd6fa$require$toStringValue(cookie);
|
|
189
|
+
else console.log("No cookie found");
|
|
190
|
+
}).catch((err)=>{
|
|
191
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error("Error getting Firefox cookie", err);
|
|
192
|
+
});
|
|
193
|
+
} else return await $af7abeb0794bd6fa$var$getChromeCookie(params).catch((err)=>{
|
|
194
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error("Error getting Chrome cookie", err);
|
|
195
|
+
}).then((r)=>{
|
|
196
|
+
if (typeof r === "string" && r.trim().length > 0) return r;
|
|
197
|
+
else return $af7abeb0794bd6fa$var$getFirefoxCookie(params).catch((err)=>{
|
|
198
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error("Error getting Firefox cookie", err);
|
|
199
|
+
});
|
|
200
|
+
}).catch((e)=>{
|
|
201
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error("Error getting Chrome or Firefox cookie", e);
|
|
202
|
+
}).then($af7abeb0794bd6fa$require$toStringValue);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* @param name
|
|
207
|
+
* @param domain
|
|
208
|
+
* @returns {Promise<Buffer>}
|
|
209
|
+
*/ async function $af7abeb0794bd6fa$var$getFirefoxCookie({ name: name , domain: domain }) {
|
|
210
|
+
if (name && typeof name !== "string") throw new Error("name must be a string");
|
|
211
|
+
if (domain && typeof domain !== "string") throw new Error("domain must be a string");
|
|
212
|
+
const [file] = await $af7abeb0794bd6fa$var$findAllFiles({
|
|
213
|
+
path: `${(0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).HOME}/Library/Application Support/Firefox/Profiles`,
|
|
214
|
+
name: "cookies.sqlite"
|
|
215
|
+
});
|
|
216
|
+
if (file && !(0, ($parcel$interopDefault($bU6Ve$fs))).existsSync(file)) throw new Error(`File ${file} does not exist`);
|
|
217
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying Firefox cookie ${name} for domain ${domain}`);
|
|
218
|
+
let sql;
|
|
219
|
+
sql = "SELECT value FROM moz_cookies";
|
|
220
|
+
if (typeof name === "string" || typeof domain === "string") {
|
|
221
|
+
sql += ` WHERE `;
|
|
222
|
+
if (typeof name === "string") {
|
|
223
|
+
sql += `name = '${name}'`;
|
|
224
|
+
if (typeof domain === "string") sql += ` AND `;
|
|
225
|
+
}
|
|
226
|
+
if (typeof domain === "string") sql += `host LIKE '${domain}';`;
|
|
227
|
+
}
|
|
228
|
+
return await $af7abeb0794bd6fa$require$doSqliteQuery1(file, sql).then((rows)=>{
|
|
229
|
+
return rows.map($af7abeb0794bd6fa$require$toStringOrNull).find((v)=>v !== null);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
const $af7abeb0794bd6fa$var$defaultChromeRoot = `${(0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).HOME}/Library/Application Support/Google/Chrome`;
|
|
233
|
+
const $af7abeb0794bd6fa$var$defaultChromeCookies = `${$af7abeb0794bd6fa$var$defaultChromeRoot}/Default/Cookies`;
|
|
234
|
+
async function $af7abeb0794bd6fa$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $af7abeb0794bd6fa$var$defaultChromeCookies , }) {
|
|
235
|
+
if (name && typeof name !== "string") throw new Error("name must be a string");
|
|
236
|
+
if (domain && typeof domain !== "string") throw new Error("domain must be a string");
|
|
237
|
+
if (file && typeof file !== "string") throw new Error("file must be a string");
|
|
238
|
+
if (!(0, ($parcel$interopDefault($bU6Ve$fs))).existsSync(file)) throw new Error(`File ${file} does not exist`);
|
|
239
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying Chrome (at ${file.split("/").slice(-3).join("/")}) cookie ${name} for domain ${domain}`);
|
|
240
|
+
let sql;
|
|
241
|
+
sql = `SELECT encrypted_value FROM cookies`;
|
|
242
|
+
if (typeof name === "string" || typeof domain === "string") {
|
|
243
|
+
sql += ` WHERE `;
|
|
244
|
+
if (typeof name === "string") {
|
|
245
|
+
sql += `name = '${name}'`;
|
|
246
|
+
if (typeof domain === "string") sql += ` AND `;
|
|
247
|
+
}
|
|
248
|
+
if (typeof domain === "string") sql += `host_key LIKE '${domain}';`;
|
|
249
|
+
}
|
|
250
|
+
return await $af7abeb0794bd6fa$require$doSqliteQuery1(file, sql);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
*
|
|
254
|
+
* @param {string} password
|
|
255
|
+
* @param {Buffer} encryptedData
|
|
256
|
+
* @returns {Promise<string>}
|
|
257
|
+
*/ async function $af7abeb0794bd6fa$var$decrypt(password, encryptedData) {
|
|
258
|
+
if (typeof password !== "string") throw new Error("password must be a string: " + password);
|
|
259
|
+
let encryptedData1;
|
|
260
|
+
encryptedData1 = encryptedData;
|
|
261
|
+
if (encryptedData1 == null || typeof encryptedData1 !== "object") throw new Error("encryptedData must be a object: " + encryptedData1);
|
|
262
|
+
if (!(encryptedData1 instanceof Buffer)) {
|
|
263
|
+
if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {
|
|
264
|
+
[encryptedData1] = encryptedData1;
|
|
265
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
|
|
266
|
+
} else throw new Error("encryptedData must be a Buffer: " + encryptedData1);
|
|
267
|
+
encryptedData1 = Buffer.from(encryptedData1);
|
|
268
|
+
}
|
|
269
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying to decrypt with password ${password}`);
|
|
270
|
+
return new Promise((resolve, reject)=>{
|
|
271
|
+
(0, ($parcel$interopDefault($bU6Ve$crypto))).pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
|
|
272
|
+
try {
|
|
273
|
+
if (error) {
|
|
274
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2", error);
|
|
275
|
+
reject(error);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (buffer.length !== 16) {
|
|
279
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
|
|
280
|
+
reject(new Error("Buffer length is not 16"));
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const iv = new Buffer.from(new Array(17).join(" "), "binary");
|
|
284
|
+
const decipher = (0, ($parcel$interopDefault($bU6Ve$crypto))).createDecipheriv("aes-128-cbc", buffer, iv);
|
|
285
|
+
decipher.setAutoPadding(false);
|
|
286
|
+
if (encryptedData1 && encryptedData1.slice) encryptedData1 = encryptedData1.slice(3);
|
|
287
|
+
if (encryptedData1.length % 16 !== 0) {
|
|
288
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
|
|
289
|
+
reject(new Error("encryptedData length is not a multiple of 16"));
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
let decoded = decipher.update(encryptedData1);
|
|
293
|
+
try {
|
|
294
|
+
decipher.final("utf-8");
|
|
295
|
+
} catch (e) {
|
|
296
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing decipher.final()", e);
|
|
297
|
+
reject(e);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
let padding = decoded[decoded.length - 1];
|
|
301
|
+
if (padding) decoded = decoded.slice(0, 0 - padding);
|
|
302
|
+
// noinspection JSCheckFunctionSignatures
|
|
303
|
+
decoded = decoded.toString("utf8");
|
|
304
|
+
resolve(decoded);
|
|
305
|
+
} catch (e1) {
|
|
306
|
+
reject(e1);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
*
|
|
313
|
+
* @param {string|undefined} name
|
|
314
|
+
* @param {string} domain
|
|
315
|
+
* @param {boolean} requireJwt
|
|
316
|
+
* @returns {Promise<string>}
|
|
317
|
+
*/ async function $af7abeb0794bd6fa$var$getChromeCookie({ name: name , domain: domain = "%" , requireJwt: requireJwt = false }) {
|
|
318
|
+
if (name && typeof name !== "string") throw new Error("name must be a string");
|
|
319
|
+
if (typeof domain !== "string") throw new Error("domain must be a string");
|
|
320
|
+
const encryptedDataItems = await $af7abeb0794bd6fa$var$findAllFiles({
|
|
321
|
+
path: $af7abeb0794bd6fa$var$defaultChromeRoot,
|
|
322
|
+
name: "Cookies"
|
|
323
|
+
}).then((files)=>{
|
|
324
|
+
const promises = files.map((file)=>{
|
|
325
|
+
return $af7abeb0794bd6fa$var$getEncryptedChromeCookie({
|
|
326
|
+
name: name,
|
|
327
|
+
domain: domain,
|
|
328
|
+
file: file
|
|
329
|
+
}).catch((e)=>{
|
|
330
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error getting encrypted cookie", e);
|
|
331
|
+
return [];
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
return Promise.all(promises).then((results)=>results.flat()).then((results)=>{
|
|
335
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("getEncryptedChromeCookie results", results);
|
|
336
|
+
return results.filter((result)=>{
|
|
337
|
+
return result;
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
}).catch((error)=>{
|
|
341
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("error", error);
|
|
342
|
+
return [];
|
|
343
|
+
});
|
|
344
|
+
const password = await $af7abeb0794bd6fa$var$getChromePassword();
|
|
345
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("encryptedDataItems", encryptedDataItems);
|
|
346
|
+
const decrypted = encryptedDataItems.filter((encryptedData)=>{
|
|
347
|
+
return encryptedData != null && encryptedData.length > 0;
|
|
348
|
+
}).map(async (encryptedData)=>{
|
|
349
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Received encrypted", encryptedData);
|
|
350
|
+
let decrypted;
|
|
351
|
+
try {
|
|
352
|
+
decrypted = await $af7abeb0794bd6fa$var$decrypt(password, encryptedData);
|
|
353
|
+
} catch (e) {
|
|
354
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error decrypting cookie", e);
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
if (decrypted) {
|
|
358
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Decrypted", decrypted);
|
|
359
|
+
return decrypted;
|
|
360
|
+
}
|
|
361
|
+
return null;
|
|
362
|
+
});
|
|
363
|
+
const results = await Promise.all(decrypted);
|
|
364
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("results", results);
|
|
365
|
+
return results.map($af7abeb0794bd6fa$require$toStringOrNull).find((result)=>{
|
|
366
|
+
return typeof result === "string" && result.length > 0 && (requireJwt === false || $af7abeb0794bd6fa$var$isValidJwt(result));
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
*
|
|
371
|
+
* @param path
|
|
372
|
+
* @param name
|
|
373
|
+
* @param rootSegments
|
|
374
|
+
* @param maxDepth
|
|
375
|
+
* @returns {Promise<[string]>}
|
|
376
|
+
*/ async function $af7abeb0794bd6fa$var$findAllFiles({ path: path , name: name , maxDepth: maxDepth = 2 }) {
|
|
377
|
+
if (typeof path !== "string") throw new Error("path must be a string");
|
|
378
|
+
if (typeof name !== "string") throw new Error("name must be a string");
|
|
379
|
+
const rootSegments = path.split("/").length;
|
|
380
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Searching for ${name} in ${path}`);
|
|
381
|
+
const files = [];
|
|
382
|
+
let readdirSync;
|
|
383
|
+
try {
|
|
384
|
+
readdirSync = (0, ($parcel$interopDefault($bU6Ve$fs))).readdirSync(path);
|
|
385
|
+
} catch (e) {
|
|
386
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Error reading ${path}`, e);
|
|
387
|
+
return files;
|
|
388
|
+
}
|
|
389
|
+
for (const file of readdirSync){
|
|
390
|
+
const filePath = path + "/" + file;
|
|
391
|
+
let stat;
|
|
392
|
+
try {
|
|
393
|
+
stat = (0, ($parcel$interopDefault($bU6Ve$fs))).statSync(filePath);
|
|
394
|
+
} catch (e1) {
|
|
395
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(`Error getting stat for ${filePath}`, e1);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (stat.isDirectory()) {
|
|
399
|
+
if (filePath.split("/").length < rootSegments + maxDepth) try {
|
|
400
|
+
const subFiles = await $af7abeb0794bd6fa$var$findAllFiles({
|
|
401
|
+
path: filePath,
|
|
402
|
+
name: name,
|
|
403
|
+
rootSegments: rootSegments,
|
|
404
|
+
maxDepth: 2
|
|
405
|
+
});
|
|
406
|
+
files.push(...subFiles);
|
|
407
|
+
} catch (e2) {
|
|
408
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(e2);
|
|
409
|
+
}
|
|
410
|
+
} else if (file === name) files.push(filePath);
|
|
411
|
+
}
|
|
412
|
+
if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) {
|
|
413
|
+
if (files.length > 0) {
|
|
414
|
+
console.log(`Found ${files.length} ${name} files`);
|
|
415
|
+
console.log(files);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return files;
|
|
419
|
+
}
|
|
420
|
+
// noinspection JSUnusedGlobalSymbols
|
|
421
|
+
module.exports = {
|
|
422
|
+
getDecryptedCookie: $af7abeb0794bd6fa$var$getChromeCookie,
|
|
423
|
+
getChromeCookie: $af7abeb0794bd6fa$var$getChromeCookie,
|
|
424
|
+
getFirefoxCookie: $af7abeb0794bd6fa$var$getFirefoxCookie,
|
|
425
|
+
getCookie: $af7abeb0794bd6fa$var$getCookie,
|
|
426
|
+
decrypt: $af7abeb0794bd6fa$var$decrypt
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;ACAA;sCAAM,mBAA6B;AAC5B,MAAM,yCAAG,GAAG,EAAE,AAAC;AACtB,gCAAM,yCAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;;;ADIxB,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAC/B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;;AELrD;qCAAM,yBAAmC;;AAGzC,eAAe,gCAAU,CAAC,OAAO,EAAE;IACjC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAC7B,MAAM,IAAI,SAA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AC,CAAC,CAAC;YACnD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SACpB;KAAA,AACF;IACD,OAAO,KAAK,CAAC;CACd;AAED,qCAAqC;AACrC,cAAc,GAAG;IACf,kBAAkB,EAAE,qCAAe;qBACnC,qCAAe;sBACf,sCAAgB;eAChB,+BAAS;aACT,6BAAO;CACR,CAAC","sources":["src/index.js","src/global.js","src/utils.js"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from \"fs\";\nimport crypto from \"crypto\";\nimport { env } from \"./global\";\n\nif (process.platform !== \"darwin\") {\n throw new Error(\"This script only works on macOS\");\n}\n\nconst {\n execSimple,\n toStringOrNull,\n doSqliteQuery1,\n toStringValue,\n} = require(\"./utils\");\nconst jsonwebtoken = require(\"jsonwebtoken\");\n\nfunction isValidJwt(token) {\n if (typeof token !== \"string\") {\n return false;\n }\n try {\n const result = jsonwebtoken.decode(token, { complete: true });\n if (env.VERBOSE) {\n console.log(result);\n }\n return true;\n } catch (err) {\n return false;\n }\n}\n\n/**\n *\n * @returns {Promise<string>}\n */\nasync function getChromePassword() {\n return execSimple(\n 'security find-generic-password -w -s \"Chrome Safe Storage\"'\n );\n}\n\n/**\n *\n * @param params\n * @returns {Promise<string>}\n */\nasync function getCookie(params) {\n if (env.CHROME_ONLY) {\n if (env.VERBOSE) {\n console.log(\"chrome only\");\n }\n return getChromeCookie(params)\n .then((cookie) => {\n if (cookie && cookie.length > 0) {\n return toStringValue(cookie);\n }\n })\n .catch((err) => {\n if (env.VERBOSE) {\n console.error(err);\n }\n });\n } else if (env.FIREFOX_ONLY) {\n if (env.VERBOSE) {\n console.log(\"firefox only\");\n }\n return getFirefoxCookie(params)\n .then((b) => b.toString(\"utf8\"))\n .then((cookie) => {\n if (cookie && cookie.length > 0) {\n return toStringValue(cookie);\n } else {\n console.log(\"No cookie found\");\n }\n })\n .catch((err) => {\n if (env.VERBOSE) {\n console.error(\"Error getting Firefox cookie\", err);\n }\n });\n } else {\n return await getChromeCookie(params)\n .catch((err) => {\n if (env.VERBOSE) {\n console.error(\"Error getting Chrome cookie\", err);\n }\n })\n .then((r) => {\n if (typeof r === \"string\" && r.trim().length > 0) {\n return r;\n } else {\n return getFirefoxCookie(params).catch((err) => {\n if (env.VERBOSE) {\n console.error(\"Error getting Firefox cookie\", err);\n }\n });\n }\n })\n .catch((e) => {\n if (env.VERBOSE) {\n console.error(\"Error getting Chrome or Firefox cookie\", e);\n }\n })\n .then(toStringValue);\n }\n}\n\n/**\n *\n * @param name\n * @param domain\n * @returns {Promise<Buffer>}\n */\nasync function getFirefoxCookie({ name, domain }) {\n if (name && typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n if (domain && typeof domain !== \"string\") {\n throw new Error(\"domain must be a string\");\n }\n const [file] = await findAllFiles({\n path: `${env.HOME}/Library/Application Support/Firefox/Profiles`,\n name: \"cookies.sqlite\",\n });\n if (file && !fs.existsSync(file)) {\n throw new Error(`File ${file} does not exist`);\n }\n if (env.VERBOSE) {\n console.log(`Trying Firefox cookie ${name} for domain ${domain}`);\n }\n let sql;\n sql = \"SELECT value FROM moz_cookies\";\n if (typeof name === \"string\" || typeof domain === \"string\") {\n sql += ` WHERE `;\n if (typeof name === \"string\") {\n sql += `name = '${name}'`;\n if (typeof domain === \"string\") {\n sql += ` AND `;\n }\n }\n if (typeof domain === \"string\") {\n sql += `host LIKE '${domain}';`;\n }\n }\n return await doSqliteQuery1(file, sql).then((rows) => {\n return rows.map(toStringOrNull).find((v) => v !== null);\n });\n}\n\nconst defaultChromeRoot = `${env.HOME}/Library/Application Support/Google/Chrome`;\nconst defaultChromeCookies = `${defaultChromeRoot}/Default/Cookies`;\n\nasync function getEncryptedChromeCookie({\n name,\n domain,\n file = defaultChromeCookies,\n}) {\n if (name && typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n if (domain && typeof domain !== \"string\") {\n throw new Error(\"domain must be a string\");\n }\n if (file && typeof file !== \"string\") {\n throw new Error(\"file must be a string\");\n }\n if (!fs.existsSync(file)) {\n throw new Error(`File ${file} does not exist`);\n }\n if (env.VERBOSE) {\n console.log(\n `Trying Chrome (at ${file\n .split(\"/\")\n .slice(-3)\n .join(\"/\")}) cookie ${name} for domain ${domain}`\n );\n }\n let sql;\n sql = `SELECT encrypted_value FROM cookies`;\n if (typeof name === \"string\" || typeof domain === \"string\") {\n sql += ` WHERE `;\n if (typeof name === \"string\") {\n sql += `name = '${name}'`;\n if (typeof domain === \"string\") {\n sql += ` AND `;\n }\n }\n if (typeof domain === \"string\") {\n sql += `host_key LIKE '${domain}';`;\n }\n }\n return await doSqliteQuery1(file, sql);\n}\n\n/**\n *\n * @param {string} password\n * @param {Buffer} encryptedData\n * @returns {Promise<string>}\n */\nasync function decrypt(password, encryptedData) {\n if (typeof password !== \"string\") {\n throw new Error(\"password must be a string: \" + password);\n }\n let encryptedData1;\n encryptedData1 = encryptedData;\n if (encryptedData1 == null || typeof encryptedData1 !== \"object\") {\n throw new Error(\"encryptedData must be a object: \" + encryptedData1);\n }\n if (!(encryptedData1 instanceof Buffer)) {\n if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {\n [encryptedData1] = encryptedData1;\n if (env.VERBOSE) {\n console.log(\n `encryptedData is an array of buffers, selected first: ${encryptedData1}`\n );\n }\n } else {\n throw new Error(\"encryptedData must be a Buffer: \" + encryptedData1);\n }\n encryptedData1 = Buffer.from(encryptedData1);\n }\n if (env.VERBOSE) {\n console.log(`Trying to decrypt with password ${password}`);\n }\n return new Promise((resolve, reject) => {\n crypto.pbkdf2(password, \"saltysalt\", 1003, 16, \"sha1\", (error, buffer) => {\n try {\n if (error) {\n if (env.VERBOSE) {\n console.log(\"Error doing pbkdf2\", error);\n }\n reject(error);\n return;\n }\n\n if (buffer.length !== 16) {\n if (env.VERBOSE) {\n console.log(\n \"Error doing pbkdf2, buffer length is not 16\",\n buffer.length\n );\n }\n reject(new Error(\"Buffer length is not 16\"));\n return;\n }\n\n const iv = new Buffer.from(new Array(17).join(\" \"), \"binary\");\n const decipher = crypto.createDecipheriv(\"aes-128-cbc\", buffer, iv);\n decipher.setAutoPadding(false);\n\n if (encryptedData1 && encryptedData1.slice) {\n encryptedData1 = encryptedData1.slice(3);\n }\n\n if (encryptedData1.length % 16 !== 0) {\n if (env.VERBOSE) {\n console.log(\n \"Error doing pbkdf2, encryptedData length is not a multiple of 16\",\n encryptedData1.length\n );\n }\n reject(new Error(\"encryptedData length is not a multiple of 16\"));\n return;\n }\n\n let decoded = decipher.update(encryptedData1);\n try {\n decipher.final(\"utf-8\");\n } catch (e) {\n if (env.VERBOSE) {\n console.log(\"Error doing decipher.final()\", e);\n }\n reject(e);\n return;\n }\n\n let padding = decoded[decoded.length - 1];\n if (padding) {\n decoded = decoded.slice(0, 0 - padding);\n }\n // noinspection JSCheckFunctionSignatures\n decoded = decoded.toString(\"utf8\");\n resolve(decoded);\n } catch (e) {\n reject(e);\n }\n });\n });\n}\n\n/**\n *\n * @param {string|undefined} name\n * @param {string} domain\n * @param {boolean} requireJwt\n * @returns {Promise<string>}\n */\nasync function getChromeCookie({ name, domain = \"%\", requireJwt = false }) {\n if (name && typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n if (typeof domain !== \"string\") {\n throw new Error(\"domain must be a string\");\n }\n const encryptedDataItems = await findAllFiles({\n path: defaultChromeRoot,\n name: \"Cookies\",\n })\n .then((files) => {\n const promises = files.map((file) => {\n return getEncryptedChromeCookie({\n name: name,\n domain: domain,\n file: file,\n }).catch((e) => {\n if (env.VERBOSE) {\n console.log(\"Error getting encrypted cookie\", e);\n }\n return [];\n });\n });\n return Promise.all(promises)\n .then((results) => results.flat())\n .then((results) => {\n if (env.VERBOSE) {\n console.log(\"getEncryptedChromeCookie results\", results);\n }\n return results.filter((result) => {\n return result;\n });\n });\n })\n .catch((error) => {\n if (env.VERBOSE) {\n console.log(\"error\", error);\n }\n return [];\n });\n const password = await getChromePassword();\n if (env.VERBOSE) {\n console.log(\"encryptedDataItems\", encryptedDataItems);\n }\n const decrypted = encryptedDataItems\n .filter((encryptedData) => {\n return encryptedData != null && encryptedData.length > 0;\n })\n .map(async (encryptedData) => {\n if (env.VERBOSE) {\n console.log(\"Received encrypted\", encryptedData);\n }\n let decrypted;\n try {\n decrypted = await decrypt(password, encryptedData);\n } catch (e) {\n if (env.VERBOSE) {\n console.log(\"Error decrypting cookie\", e);\n }\n return null;\n }\n if (decrypted) {\n if (env.VERBOSE) {\n console.log(\"Decrypted\", decrypted);\n }\n return decrypted;\n }\n return null;\n });\n const results = await Promise.all(decrypted);\n if (env.VERBOSE) {\n console.log(\"results\", results);\n }\n return results.map(toStringOrNull).find((result) => {\n return (\n typeof result === \"string\" &&\n result.length > 0 &&\n (requireJwt === false || isValidJwt(result))\n );\n });\n}\n\n/**\n *\n * @param path\n * @param name\n * @param rootSegments\n * @param maxDepth\n * @returns {Promise<[string]>}\n */\nasync function findAllFiles({ path, name, maxDepth = 2 }) {\n if (typeof path !== \"string\") {\n throw new Error(\"path must be a string\");\n }\n if (typeof name !== \"string\") {\n throw new Error(\"name must be a string\");\n }\n\n const rootSegments = path.split(\"/\").length;\n\n if (env.VERBOSE) {\n console.log(`Searching for ${name} in ${path}`);\n }\n const files = [];\n let readdirSync;\n try {\n readdirSync = fs.readdirSync(path);\n } catch (e) {\n if (env.VERBOSE) {\n console.log(`Error reading ${path}`, e);\n }\n return files;\n }\n for (const file of readdirSync) {\n const filePath = path + \"/\" + file;\n let stat;\n try {\n stat = fs.statSync(filePath);\n } catch (e) {\n if (env.VERBOSE) {\n console.error(`Error getting stat for ${filePath}`, e);\n }\n continue;\n }\n if (stat.isDirectory()) {\n if (filePath.split(\"/\").length < rootSegments + maxDepth) {\n try {\n const subFiles = await findAllFiles({\n path: filePath,\n name: name,\n rootSegments: rootSegments,\n maxDepth: 2,\n });\n files.push(...subFiles);\n } catch (e) {\n if (env.VERBOSE) {\n console.error(e);\n }\n }\n }\n } else if (file === name) {\n files.push(filePath);\n }\n }\n if (env.VERBOSE) {\n if (files.length > 0) {\n console.log(`Found ${files.length} ${name} files`);\n console.log(files);\n }\n }\n return files;\n}\n\n// noinspection JSUnusedGlobalSymbols\nmodule.exports = {\n getDecryptedCookie: getChromeCookie,\n getChromeCookie,\n getFirefoxCookie,\n getCookie,\n decrypt,\n};\n","const { merge } = require(\"lodash\");\nexport const env = {};\nmerge(env, process.env);\n","// noinspection JSUnusedGlobalSymbols\n\nconst { exec } = require(\"child_process\");\nconst fs = require(\"fs\");\n\nasync function execSimple(command) {\n if (typeof command !== \"string\") {\n throw new TypeError(\"execSimple: command must be a string\");\n }\n if (process.env.VERBOSE) {\n console.log(command);\n }\n return new Promise((resolve, reject) => {\n exec(\n command,\n { encoding: \"binary\", maxBuffer: 5 * 1024 },\n (error, stdout, stderr) => {\n if (error) {\n reject(error);\n return;\n }\n if (stderr) {\n reject(error);\n return;\n }\n if (stdout) {\n resolve(stdout.toString(\"utf8\").trim());\n }\n }\n );\n });\n}\n\nasync function execAsBuffer(command) {\n if (typeof command !== \"string\") {\n throw new TypeError(\"execAsBuffer: command must be a string\");\n }\n if (process.env.VERBOSE) {\n console.log(command);\n }\n return await new Promise((resolve, reject) => {\n exec(\n command,\n { encoding: \"binary\", maxBuffer: 5 * 1024 },\n (error, stdout, stderr) => {\n if (error) {\n reject(error);\n return;\n }\n if (stderr) {\n reject(error);\n return;\n }\n let stdoutAsBuffer = stdout;\n if (typeof stdoutAsBuffer === \"string\" && stdoutAsBuffer.length > 0) {\n // noinspection JSCheckFunctionSignatures\n stdoutAsBuffer = Buffer.from(stdoutAsBuffer, \"binary\").slice(0, -1);\n }\n if (stdoutAsBuffer && stdoutAsBuffer.length > 0) {\n resolve(stdoutAsBuffer);\n }\n }\n );\n });\n}\n\nfunction toStringValue(r) {\n if (process.env.VERBOSE) {\n console.log(\"Printing value\", r);\n }\n if (r) {\n if (typeof r === \"string\") {\n return r;\n } else if (r.toString) {\n // noinspection JSCheckFunctionSignatures\n return r.toString(\"utf8\");\n }\n }\n}\n\nfunction printStringValue(r) {\n if (process.env.VERBOSE) {\n console.log(\"Printing value\", r);\n }\n if (r) {\n if (typeof r === \"string\") {\n console.log(r);\n } else if (r.toString) {\n // noinspection JSCheckFunctionSignatures\n console.log(r.toString(\"utf8\"));\n }\n }\n}\n\n/**\n *\n * @param result\n * @returns {string|null}\n */\nfunction toStringOrNull(result) {\n if (result == null) {\n return null;\n }\n if (process.env.VERBOSE) {\n console.log(\"result\", result);\n }\n if (typeof result === \"string\" && result.length > 0) {\n return result;\n }\n if (result.slice && result.toString) {\n // noinspection JSCheckFunctionSignatures\n return result.toString(\"utf8\");\n }\n return null;\n}\n\n/**\n *\n * @param {string} file\n * @param {string} sql\n * @returns {Promise<Buffer[]>}\n */\nasync function doSqliteQuery1(file, sql) {\n if (typeof sql !== \"string\") {\n throw new TypeError(\"doSqliteQuery1: sql must be a string\");\n }\n if (typeof file !== \"string\") {\n throw new TypeError(\"doSqliteQuery1: file must be a string\");\n }\n if (!fs.existsSync(file)) {\n throw new Error(`doSqliteQuery1: file ${file} does not exist`);\n }\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: file ${file}`);\n console.log(`doSqliteQuery1: sql ${sql}`);\n }\n const sqlite3 = require(\"sqlite3\");\n const db = new sqlite3.Database(file);\n return new Promise((resolve, reject) => {\n db.all(sql, (err, rows) => {\n if (err) {\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: error ${err}`);\n }\n reject(err);\n return;\n }\n const rows1 = rows;\n if (rows1 == null || rows1.length === 0) {\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: no rows`);\n }\n resolve([]);\n return;\n }\n if (Array.isArray(rows1)) {\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: ${rows1.length} rows`);\n }\n // noinspection JSCheckFunctionSignatures\n const buffers = rows1\n .flatMap((row) => Object.values(row))\n .map((v) => Buffer.from(v, \"binary\"));\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: ${buffers.length} buffers`);\n }\n resolve(buffers);\n return;\n }\n if (process.env.VERBOSE) {\n console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);\n }\n resolve([rows1]);\n });\n });\n}\n\nmodule.exports = {\n execSimple: execSimple,\n execAsBuffer: execAsBuffer,\n printStringValue: printStringValue,\n toStringValue,\n toStringOrNull: toStringOrNull,\n doSqliteQuery1,\n};\n"],"names":[],"version":3,"file":"main.js.map","sourceRoot":"../"}
|