@shriyanss/js-recon 1.0.0 → 1.1.0-beta.1

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.
Files changed (198) hide show
  1. package/.api_gateway_config.json +1 -0
  2. package/.github/workflows/npm-publish.yml +35 -0
  3. package/.github/workflows/prettier.yaml +44 -0
  4. package/.prettierignore +2 -0
  5. package/.prettierrc +4 -0
  6. package/.resp_cache.json +1 -0
  7. package/.vscode/launch.json +27 -0
  8. package/CHANGELOG.md +40 -0
  9. package/README.md +35 -140
  10. package/build/api_gateway/checkFeasibility.js +32 -0
  11. package/build/api_gateway/checkFeasibility.js.map +1 -0
  12. package/build/api_gateway/checkFireWallBlocking.js +24 -0
  13. package/build/api_gateway/checkFireWallBlocking.js.map +1 -0
  14. package/build/api_gateway/genReq.js +202 -0
  15. package/build/api_gateway/genReq.js.map +1 -0
  16. package/build/api_gateway/index.js +277 -0
  17. package/build/api_gateway/index.js.map +1 -0
  18. package/build/endpoints/gen_report/gen_json.js +22 -0
  19. package/build/endpoints/gen_report/gen_json.js.map +1 -0
  20. package/build/endpoints/gen_report/gen_markdown.js +66 -0
  21. package/build/endpoints/gen_report/gen_markdown.js.map +1 -0
  22. package/build/endpoints/gen_report/utility/iterate_n_store.js +46 -0
  23. package/build/endpoints/gen_report/utility/iterate_n_store.js.map +1 -0
  24. package/build/endpoints/index.js +89 -0
  25. package/build/endpoints/index.js.map +1 -0
  26. package/build/endpoints/next_js/client_jsFilesHref.js +91 -0
  27. package/build/endpoints/next_js/client_jsFilesHref.js.map +1 -0
  28. package/build/endpoints/next_js/client_jsonParse.js +75 -0
  29. package/build/endpoints/next_js/client_jsonParse.js.map +1 -0
  30. package/build/endpoints/next_js/client_subsequentRequests.js +199 -0
  31. package/build/endpoints/next_js/client_subsequentRequests.js.map +1 -0
  32. package/build/endpoints/next_js/getWebpacks.js +45 -0
  33. package/build/endpoints/next_js/getWebpacks.js.map +1 -0
  34. package/build/globalConfig.js +11 -0
  35. package/build/globalConfig.js.map +1 -0
  36. package/build/index.js +166 -0
  37. package/build/index.js.map +1 -0
  38. package/build/lazyLoad/downloadFilesUtil.js +128 -0
  39. package/build/lazyLoad/downloadFilesUtil.js.map +1 -0
  40. package/build/lazyLoad/downloadLoadedJsUtil.js +51 -0
  41. package/build/lazyLoad/downloadLoadedJsUtil.js.map +1 -0
  42. package/build/lazyLoad/globals.js +25 -0
  43. package/build/lazyLoad/globals.js.map +1 -0
  44. package/build/lazyLoad/index.js +171 -0
  45. package/build/lazyLoad/index.js.map +1 -0
  46. package/build/lazyLoad/next_js/next_GetJSScript.js +94 -0
  47. package/build/lazyLoad/next_js/next_GetJSScript.js.map +1 -0
  48. package/build/lazyLoad/next_js/next_GetLazyResources.js +202 -0
  49. package/build/lazyLoad/next_js/next_GetLazyResources.js.map +1 -0
  50. package/build/lazyLoad/next_js/next_SubsequentRequests.js +120 -0
  51. package/build/lazyLoad/next_js/next_SubsequentRequests.js.map +1 -0
  52. package/build/lazyLoad/nuxt_js/nuxt_astParse.js +188 -0
  53. package/build/lazyLoad/nuxt_js/nuxt_astParse.js.map +1 -0
  54. package/build/lazyLoad/nuxt_js/nuxt_getFromPageSource.js +75 -0
  55. package/build/lazyLoad/nuxt_js/nuxt_getFromPageSource.js.map +1 -0
  56. package/build/lazyLoad/nuxt_js/nuxt_stringAnalysisJSFiles.js +94 -0
  57. package/build/lazyLoad/nuxt_js/nuxt_stringAnalysisJSFiles.js.map +1 -0
  58. package/build/lazyLoad/svelte/svelte_getFromPageSource.js +68 -0
  59. package/build/lazyLoad/svelte/svelte_getFromPageSource.js.map +1 -0
  60. package/build/lazyLoad/svelte/svelte_stringAnalysisJSFiles.js +95 -0
  61. package/build/lazyLoad/svelte/svelte_stringAnalysisJSFiles.js.map +1 -0
  62. package/build/map/index.js +58 -0
  63. package/build/map/index.js.map +1 -0
  64. package/build/map/next_js/getFetchInstances.js +105 -0
  65. package/build/map/next_js/getFetchInstances.js.map +1 -0
  66. package/build/map/next_js/getWebpackConnections.js +224 -0
  67. package/build/map/next_js/getWebpackConnections.js.map +1 -0
  68. package/build/map/next_js/interactive.js +32 -0
  69. package/build/map/next_js/interactive.js.map +1 -0
  70. package/build/map/next_js/interactive_helpers/commandHandler.js +190 -0
  71. package/build/map/next_js/interactive_helpers/commandHandler.js.map +1 -0
  72. package/build/map/next_js/interactive_helpers/commandHelpers.js +91 -0
  73. package/build/map/next_js/interactive_helpers/commandHelpers.js.map +1 -0
  74. package/build/map/next_js/interactive_helpers/helpMenu.js +11 -0
  75. package/build/map/next_js/interactive_helpers/helpMenu.js.map +1 -0
  76. package/build/map/next_js/interactive_helpers/keybindings.js +80 -0
  77. package/build/map/next_js/interactive_helpers/keybindings.js.map +1 -0
  78. package/build/map/next_js/interactive_helpers/printer.js +17 -0
  79. package/build/map/next_js/interactive_helpers/printer.js.map +1 -0
  80. package/build/map/next_js/interactive_helpers/ui.js +81 -0
  81. package/build/map/next_js/interactive_helpers/ui.js.map +1 -0
  82. package/build/map/next_js/resolveFetch.js +201 -0
  83. package/build/map/next_js/resolveFetch.js.map +1 -0
  84. package/build/run/index.js +62 -0
  85. package/build/run/index.js.map +1 -0
  86. package/build/strings/index.js +235 -0
  87. package/build/strings/index.js.map +1 -0
  88. package/build/strings/openapi.js +55 -0
  89. package/build/strings/openapi.js.map +1 -0
  90. package/build/strings/permutate.js +55 -0
  91. package/build/strings/permutate.js.map +1 -0
  92. package/build/strings/secrets.js +89 -0
  93. package/build/strings/secrets.js.map +1 -0
  94. package/build/techDetect/index.js +224 -0
  95. package/build/techDetect/index.js.map +1 -0
  96. package/build/utility/ai.js +69 -0
  97. package/build/utility/ai.js.map +1 -0
  98. package/build/utility/globals.js +84 -0
  99. package/build/utility/globals.js.map +1 -0
  100. package/build/utility/interfaces.js +2 -0
  101. package/build/utility/interfaces.js.map +1 -0
  102. package/build/utility/makeReq.js +265 -0
  103. package/build/utility/makeReq.js.map +1 -0
  104. package/build/utility/resolvePath.js +44 -0
  105. package/build/utility/resolvePath.js.map +1 -0
  106. package/{utility → build/utility}/runSandboxed.js +10 -13
  107. package/build/utility/runSandboxed.js.map +1 -0
  108. package/{utility → build/utility}/urlUtils.js +9 -11
  109. package/build/utility/urlUtils.js.map +1 -0
  110. package/docs/README.md +20 -0
  111. package/docs/api-gateway.md +68 -0
  112. package/docs/endpoints.md +49 -0
  113. package/docs/example-scenario.md +258 -0
  114. package/docs/interactive-mode.md +76 -0
  115. package/docs/lazyload.md +56 -0
  116. package/docs/map.md +53 -0
  117. package/docs/run.md +54 -0
  118. package/docs/strings.md +75 -0
  119. package/endpoints.json +77 -0
  120. package/extracted_urls-openapi.json +225 -0
  121. package/extracted_urls-swagger.json +225 -0
  122. package/extracted_urls.json +47 -0
  123. package/extracted_urls.txt +296 -0
  124. package/mapped.json +3413 -0
  125. package/output/ss0x00.com/_next/data/k7xKVnxmboK4SktY2dZWt/index.json +971 -0
  126. package/output/ss0x00.com/_next/static/chunks/12.7e6d2ac6e1808fc2.js +247 -0
  127. package/output/ss0x00.com/_next/static/chunks/128.160aa801ef0445bc.js +1074 -0
  128. package/output/ss0x00.com/_next/static/chunks/132.55df84f7707fc278.js +102 -0
  129. package/output/ss0x00.com/_next/static/chunks/142.77038c55d9ec10ba.js +96 -0
  130. package/output/ss0x00.com/_next/static/chunks/215.321479e91d330bfa.js +228 -0
  131. package/output/ss0x00.com/_next/static/chunks/229.097c396d86b4a882.js +458 -0
  132. package/output/ss0x00.com/_next/static/chunks/257.5fd052aa4ef06ef9.js +1327 -0
  133. package/output/ss0x00.com/_next/static/chunks/268.72cb3779f66db70b.js +10520 -0
  134. package/output/ss0x00.com/_next/static/chunks/320.57d528b0e9bf86f0.js +186 -0
  135. package/output/ss0x00.com/_next/static/chunks/325.302a44b604c35f17.js +88 -0
  136. package/output/ss0x00.com/_next/static/chunks/328.e4a0307a4fddf318.js +248 -0
  137. package/output/ss0x00.com/_next/static/chunks/432.3621f17504ef18f2.js +443 -0
  138. package/output/ss0x00.com/_next/static/chunks/44.e90dd963003a3d43.js +1094 -0
  139. package/output/ss0x00.com/_next/static/chunks/442.8c054f100f9e5e50.js +1082 -0
  140. package/output/ss0x00.com/_next/static/chunks/460.f8db9a5142598e2c.js +466 -0
  141. package/output/ss0x00.com/_next/static/chunks/487.05ca55420459c002.js +78 -0
  142. package/output/ss0x00.com/_next/static/chunks/567.1909a6b0a920114b.js +1374 -0
  143. package/output/ss0x00.com/_next/static/chunks/586.802fc9214d87fb29.js +752 -0
  144. package/output/ss0x00.com/_next/static/chunks/620.a2a3a6b94d30a4c8.js +1037 -0
  145. package/output/ss0x00.com/_next/static/chunks/642.6b3e487c9604cbb8.js +1628 -0
  146. package/output/ss0x00.com/_next/static/chunks/673.e5d77887e5c6a68c.js +1045 -0
  147. package/output/ss0x00.com/_next/static/chunks/684.8b8e52baca70524b.js +96 -0
  148. package/output/ss0x00.com/_next/static/chunks/686.79480519e5ccfb77.js +296 -0
  149. package/output/ss0x00.com/_next/static/chunks/756.7a3878a2e6765be7.js +504 -0
  150. package/output/ss0x00.com/_next/static/chunks/761.7bea7516c5d22b2a.js +1485 -0
  151. package/output/ss0x00.com/_next/static/chunks/794.e079ef369b41a3c5.js +1350 -0
  152. package/output/ss0x00.com/_next/static/chunks/826.31ba213e1d023c68.js +1031 -0
  153. package/output/ss0x00.com/_next/static/chunks/847.d8397a73efc81848.js +1068 -0
  154. package/output/ss0x00.com/_next/static/chunks/848.5feaeee1e2624aea.js +132 -0
  155. package/output/ss0x00.com/_next/static/chunks/850.ecc7c3c3d787ee03.js +1472 -0
  156. package/output/ss0x00.com/_next/static/chunks/853.50b9eb60b7d0e83c.js +1472 -0
  157. package/output/ss0x00.com/_next/static/chunks/856.7a7bb6c3c7bfc2ba.js +1320 -0
  158. package/output/ss0x00.com/_next/static/chunks/859.df4bd45c03a65f53.js +1306 -0
  159. package/output/ss0x00.com/_next/static/chunks/867.e8633955a147c978.js +541 -0
  160. package/output/ss0x00.com/_next/static/chunks/921.c3123f20a4c8d53c.js +96 -0
  161. package/output/ss0x00.com/_next/static/chunks/932.25cb421c466c99cb.js +999 -0
  162. package/output/ss0x00.com/_next/static/chunks/framework-64ad27b21261a9ce.js +9189 -0
  163. package/output/ss0x00.com/_next/static/chunks/main-710ab85aa9a8f10d.js +6583 -0
  164. package/output/ss0x00.com/_next/static/chunks/pages/5D-af5a23529ce3c337.js +486 -0
  165. package/output/ss0x00.com/_next/static/chunks/pages/_app-c449865c8af1faa0.js +39 -0
  166. package/output/ss0x00.com/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js +6383 -0
  167. package/output/ss0x00.com/_next/static/chunks/webpack-efff35ee26971294.js +271 -0
  168. package/output/ss0x00.com/_next/static/k7xKVnxmboK4SktY2dZWt/_buildManifest.js +8 -0
  169. package/output/ss0x00.com/_next/static/k7xKVnxmboK4SktY2dZWt/_ssgManifest.js +3 -0
  170. package/output/ss0x00.com/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js +82 -0
  171. package/package.json +50 -38
  172. package/strings.json +7407 -0
  173. package/api_gateway/checkFeasibility.js +0 -25
  174. package/api_gateway/checkFireWallBlocking.js +0 -17
  175. package/api_gateway/genReq.js +0 -214
  176. package/api_gateway/index.js +0 -325
  177. package/endpoints/index.js +0 -7
  178. package/globalConfig.js +0 -12
  179. package/index.js +0 -69
  180. package/lazyLoad/downloadFilesUtil.js +0 -122
  181. package/lazyLoad/downloadLoadedJsUtil.js +0 -54
  182. package/lazyLoad/globals.js +0 -15
  183. package/lazyLoad/index.js +0 -167
  184. package/lazyLoad/next_js/next_GetJSScript.js +0 -99
  185. package/lazyLoad/next_js/next_GetLazyResources.js +0 -201
  186. package/lazyLoad/next_js/next_SubsequentRequests.js +0 -138
  187. package/lazyLoad/nuxt_js/nuxt_astParse.js +0 -194
  188. package/lazyLoad/nuxt_js/nuxt_getFromPageSource.js +0 -77
  189. package/lazyLoad/nuxt_js/nuxt_stringAnalysisJSFiles.js +0 -99
  190. package/research/firewall_bypass.md +0 -38
  191. package/research/next_js.md +0 -116
  192. package/research/nuxt_js.md +0 -125
  193. package/research/vue_js.md +0 -9
  194. package/strings/index.js +0 -145
  195. package/techDetect/index.js +0 -156
  196. package/utility/globals.js +0 -6
  197. package/utility/makeReq.js +0 -179
  198. package/utility/resolvePath.js +0 -43
@@ -1,122 +0,0 @@
1
- import chalk from "chalk";
2
- import path from "path";
3
- import fs from "fs";
4
- import prettier from "prettier";
5
- import makeRequest from "../utility/makeReq.js";
6
- import { getURLDirectory } from "../utility/urlUtils.js";
7
- import { getScope, getMaxReqQueue } from "./globals.js"; // Import scope and max_req_queue functions
8
-
9
- /**
10
- * Downloads a list of URLs and saves them as files in the specified output directory.
11
- * It creates the necessary subdirectories based on the URL's host and path.
12
- * If the URL does not end with `.js`, it is skipped.
13
- * The function logs the progress and any errors to the console.
14
- * @param {string[]} urls - An array of URLs to be downloaded.
15
- * @param {string} output - The directory where the downloaded files will be saved.
16
- * @returns {Promise<void>}
17
- */
18
- const downloadFiles = async (urls, output) => {
19
- console.log(
20
- chalk.cyan(`[i] Attempting to download ${urls.length} JS chunks`),
21
- );
22
- fs.mkdirSync(output, { recursive: true });
23
-
24
- // to store ignored JS domain
25
- let ignoredJSFiles = [];
26
- let ignoredJSDomains = [];
27
-
28
- let download_count = 0;
29
- let queue = 0;
30
-
31
- const downloadPromises = urls.map(async (url) => {
32
- try {
33
- if (url.match(/\.js/)) {
34
- // get the directory of the url
35
- const { host, directory } = getURLDirectory(url);
36
-
37
- // check scope of file. Only if in scope, download it
38
- if (!getScope().includes("*")) {
39
- if (!getScope().includes(host)) {
40
- ignoredJSFiles.push(url);
41
- if (!ignoredJSDomains.includes(host)) {
42
- ignoredJSDomains.push(host);
43
- }
44
- return;
45
- }
46
- }
47
-
48
- // make the directory inside the output folder
49
- const childDir = path.join(output, host, directory);
50
- fs.mkdirSync(childDir, { recursive: true });
51
-
52
- // check if queue is full. If so, then wait for random time between
53
- // 50 to 300 ms. Then, check again, and loop the process
54
- while (queue >= getMaxReqQueue()) {
55
- await new Promise((resolve) =>
56
- setTimeout(resolve, Math.random() * 250 + 50),
57
- );
58
- }
59
- queue++;
60
- const res = await makeRequest(url);
61
- queue--;
62
-
63
- const file = `// JS Source: ${url}\n${await res.text()}`;
64
- let filename;
65
- try {
66
- filename = url
67
- .split("/")
68
- .pop()
69
- .match(/[a-zA-Z0-9\.\-_]+\.js/)[0];
70
- } catch (err) {
71
- // split the URL into multiple chunks. then iterate
72
- // through it, and find whatever matches with JS ext
73
- const chunks = url.split("/");
74
- for (const chunk of chunks) {
75
- if (chunk.match(/\.js$/)) {
76
- filename = chunk;
77
- break;
78
- }
79
- }
80
- }
81
-
82
- if (!filename) { // Handle cases where filename might not be found
83
- console.warn(chalk.yellow(`[!] Could not determine filename for URL: ${url}. Skipping.`));
84
- return;
85
- }
86
-
87
- const filePath = path.join(childDir, filename);
88
- try {
89
- fs.writeFileSync(
90
- filePath,
91
- await prettier.format(file, { parser: "babel" }),
92
- );
93
- } catch (err) {
94
- console.error(chalk.red(`[!] Failed to write file: ${filePath}`));
95
- }
96
- download_count++;
97
- }
98
- } catch (err) {
99
- console.error(chalk.red(`[!] Failed to download: ${url}`));
100
- }
101
- });
102
-
103
- await Promise.all(downloadPromises);
104
-
105
- if (ignoredJSFiles.length > 0) {
106
- console.log(
107
- chalk.yellow(
108
- `[i] Ignored ${ignoredJSFiles.length} JS files across ${ignoredJSDomains.length} domain(s) - ${ignoredJSDomains.join(", ")}`,
109
- ),
110
- );
111
- }
112
-
113
- if (download_count > 0) {
114
- console.log(
115
- chalk.green(
116
- `[✓] Downloaded ${download_count} JS chunks to ${output} directory`,
117
- ),
118
- );
119
- }
120
- };
121
-
122
- export default downloadFiles;
@@ -1,54 +0,0 @@
1
- import chalk from "chalk";
2
- import puppeteer from "puppeteer";
3
-
4
- /**
5
- * Downloads all the lazy loaded JS files from a given URL.
6
- *
7
- * It opens a headless browser instance, navigates to the given URL, and
8
- * intercepts all the requests. It checks if the request is a JS file
9
- * and if it is a GET request. If both conditions are satisfied, the URL
10
- * is added to the array of URLs. Finally, it closes the browser instance
11
- * and returns the array of URLs.
12
- *
13
- * @param {string} url - The URL of the webpage to fetch and parse.
14
- * @returns {Promise<string[]|undefined>} - A promise that resolves to an array of
15
- * absolute URLs pointing to JavaScript files found in the page, or undefined for invalid URL.
16
- */
17
- const downloadLoadedJs = async (url) => {
18
- if (!url.match(/https?:\/\/[a-zA-Z0-9\._\-]+/)) {
19
- console.log(chalk.red("[!] Invalid URL"));
20
- return; // Return undefined as per JSDoc
21
- }
22
-
23
- const browser = await puppeteer.launch({
24
- headless: true,
25
- });
26
-
27
- const page = await browser.newPage();
28
-
29
- await page.setRequestInterception(true);
30
-
31
- let js_urls_local = []; // Use a local variable, not the global one
32
- page.on("request", async (request) => {
33
- // get the request url
34
- const req_url = request.url(); // Renamed to avoid conflict with outer 'url'
35
-
36
- // see if the request is a JS file, and is a get request
37
- if (
38
- request.method() === "GET" &&
39
- req_url.match(/https?:\/\/[a-z\._\-]+\/.+\.js\??.*/)
40
- ) {
41
- js_urls_local.push(req_url);
42
- }
43
-
44
- await request.continue();
45
- });
46
-
47
- await page.goto(url);
48
-
49
- await browser.close();
50
-
51
- return js_urls_local;
52
- };
53
-
54
- export default downloadLoadedJs;
@@ -1,15 +0,0 @@
1
-
2
- let scope = [];
3
- let js_urls = [];
4
- let max_req_queue;
5
-
6
- export const getScope = () => scope;
7
- export const setScope = (newScope) => { scope = newScope; };
8
- export const pushToScope = (item) => { scope.push(item); };
9
-
10
- export const getJsUrls = () => js_urls;
11
- export const clearJsUrls = () => { js_urls = []; };
12
- export const pushToJsUrls = (url) => { js_urls.push(url); };
13
-
14
- export const getMaxReqQueue = () => max_req_queue;
15
- export const setMaxReqQueue = (newMax) => { max_req_queue = newMax; };
package/lazyLoad/index.js DELETED
@@ -1,167 +0,0 @@
1
- import chalk from "chalk";
2
- import fs from "fs";
3
- import frameworkDetect from "../techDetect/index.js";
4
- import CONFIG from "../globalConfig.js";
5
- import _traverse from "@babel/traverse";
6
- const traverse = _traverse.default;
7
- import { URL } from "url";
8
-
9
- // Next.js
10
- import subsequentRequests from "./next_js/next_SubsequentRequests.js";
11
- import next_getJSScript from "./next_js/next_GetJSScript.js";
12
- import next_getLazyResources from "./next_js/next_GetLazyResources.js";
13
-
14
- // Nuxt.js
15
- import nuxt_getFromPageSource from "./nuxt_js/nuxt_getFromPageSource.js";
16
- import nuxt_stringAnalysisJSFiles from "./nuxt_js/nuxt_stringAnalysisJSFiles.js";
17
- import nuxt_astParse from "./nuxt_js/nuxt_astParse.js";
18
-
19
- // generic
20
- import downloadFiles from "./downloadFilesUtil.js";
21
- import downloadLoadedJs from "./downloadLoadedJsUtil.js";
22
-
23
- // import global vars
24
- import * as globals from "./globals.js";
25
-
26
- /**
27
- * Downloads all lazy-loaded JavaScript files from the specified URL or file containing URLs.
28
- *
29
- * The function detects the JavaScript framework used by the webpage (e.g., Next.js, Nuxt.js)
30
- * and utilizes specific techniques to find and download lazy-loaded JS files.
31
- * It supports subsequent requests for additional JS files if specified.
32
- *
33
- * @param {string} url - The URL or path to a file containing a list of URLs to process.
34
- * @param {string} output - The directory where downloaded files will be saved.
35
- * @param {boolean} strictScope - Whether to restrict downloads to the input URL domain.
36
- * @param {string[]} inputScope - Specific domains to download JS files from.
37
- * @param {number} threads - The number of threads to use for downloading files.
38
- * @param {boolean} subsequentRequestsFlag - Whether to include JS files from subsequent requests.
39
- * @param {string} urlsFile - The JSON file containing additional URLs for subsequent requests.
40
- * @returns {Promise<void>}
41
- */
42
- const lazyLoad = async (
43
- url,
44
- output,
45
- strictScope,
46
- inputScope,
47
- threads,
48
- subsequentRequestsFlag,
49
- urlsFile,
50
- ) => {
51
- console.log(chalk.cyan("[i] Loading 'Lazy Load' module"));
52
-
53
- let urls;
54
-
55
- // check if the url is file or a URL
56
- if (fs.existsSync(url)) {
57
- urls = fs.readFileSync(url, "utf-8").split("\n");
58
- // remove the empty lines
59
- urls = urls.filter((url) => url.trim() !== "");
60
- } else if (url.match(/https?:\/\/[a-zA-Z0-9\-_\.:]+/)) {
61
- urls = [url];
62
- } else {
63
- console.log(chalk.red("[!] Invalid URL or file path"));
64
- return;
65
- }
66
-
67
- for (const url of urls) {
68
- console.log(chalk.cyan(`[i] Processing ${url}`));
69
-
70
- if (strictScope) {
71
- globals.pushToScope(new URL(url).host);
72
- } else {
73
- globals.setScope(inputScope);
74
- }
75
-
76
- globals.setMaxReqQueue(threads);
77
- globals.clearJsUrls(); // Initialize js_urls for each URL processing in the loop
78
-
79
- const tech = await frameworkDetect(url);
80
-
81
- if (tech) {
82
- if (tech.name === "next") {
83
- console.log(chalk.green("[✓] Next.js detected"));
84
- console.log(chalk.yellow(`Evidence: ${tech.evidence}`));
85
-
86
- // find the JS files from script of the webpage
87
- const jsFilesFromScriptTag = await next_getJSScript(url);
88
-
89
- // get lazy resources
90
- const lazyResourcesFromWebpack = await next_getLazyResources(url);
91
- let lazyResourcesFromSubsequentRequests;
92
-
93
- if (subsequentRequestsFlag) {
94
- // get JS files from subsequent requests
95
- lazyResourcesFromSubsequentRequests = await subsequentRequests(
96
- url,
97
- urlsFile,
98
- threads,
99
- output,
100
- globals.getJsUrls(), // Pass the global js_urls
101
- );
102
- }
103
-
104
- // download the resources
105
- // but combine them first
106
- let jsFilesToDownload = [
107
- ...(jsFilesFromScriptTag || []),
108
- ...(lazyResourcesFromWebpack || []),
109
- ...(lazyResourcesFromSubsequentRequests || []),
110
- ];
111
- // Ensure js_urls from globals are included if next_getJSScript or next_getLazyResources populated it.
112
- // This is because those functions now push to the global js_urls via setters.
113
- // The return values of next_getJSScript and next_getLazyResources might be the same array instance
114
- // or a new one depending on their implementation, so explicitly get the global one here.
115
- jsFilesToDownload.push(...globals.getJsUrls());
116
-
117
- // dedupe the files
118
- jsFilesToDownload = [...new Set(jsFilesToDownload)];
119
-
120
- await downloadFiles(jsFilesToDownload, output);
121
- } else if (tech.name === "vue") {
122
- console.log(chalk.green("[✓] Vue.js detected"));
123
- console.log(chalk.yellow(`Evidence: ${tech.evidence}`));
124
- } else if (tech.name === "nuxt") {
125
- console.log(chalk.green("[✓] Nuxt.js detected"));
126
- console.log(chalk.yellow(`Evidence: ${tech.evidence}`));
127
-
128
- let jsFilesToDownload = [];
129
-
130
- // find the files from the page source
131
- const jsFilesFromPageSource = await nuxt_getFromPageSource(url);
132
- const jsFilesFromStringAnalysis = await nuxt_stringAnalysisJSFiles(url);
133
-
134
- jsFilesToDownload.push(...jsFilesFromPageSource);
135
- jsFilesToDownload.push(...jsFilesFromStringAnalysis);
136
- // dedupe the files
137
- jsFilesToDownload = [...new Set(jsFilesToDownload)];
138
-
139
- let jsFilesFromAST = [];
140
- console.log(chalk.cyan("[i] Analyzing functions in the files found"));
141
- for (const jsFile of jsFilesToDownload) {
142
- jsFilesFromAST.push(...(await nuxt_astParse(jsFile)));
143
- }
144
-
145
- jsFilesToDownload.push(...jsFilesFromAST);
146
-
147
- jsFilesToDownload.push(...globals.getJsUrls());
148
-
149
- // dedupe the files
150
- jsFilesToDownload = [...new Set(jsFilesToDownload)];
151
-
152
- await downloadFiles(jsFilesToDownload, output);
153
- }
154
- } else {
155
- console.log(chalk.red("[!] Framework not detected :("));
156
- console.log(chalk.magenta(CONFIG.notFoundMessage));
157
- console.log(chalk.yellow("[i] Trying to download loaded JS files"));
158
- const js_urls = await downloadLoadedJs(url);
159
- if (js_urls && js_urls.length > 0) {
160
- console.log(chalk.green(`[✓] Found ${js_urls.length} JS chunks`));
161
- await downloadFiles(js_urls, output);
162
- }
163
- }
164
- }
165
- };
166
-
167
- export default lazyLoad;
@@ -1,99 +0,0 @@
1
- // lazyLoad/nextGetJSScript.js
2
- import chalk from "chalk";
3
- import { URL } from "url";
4
- import * as cheerio from "cheerio";
5
- import makeRequest from "../../utility/makeReq.js";
6
- import { getJsUrls, pushToJsUrls } from "../globals.js";
7
-
8
- /**
9
- * Asynchronously fetches the given URL and extracts JavaScript file URLs
10
- * from script tags present in the HTML content.
11
- *
12
- * @param {string} url - The URL of the webpage to fetch and parse.
13
- * @returns {Promise<string[]>} - A promise that resolves to an array of
14
- * absolute URLs pointing to JavaScript files found in script tags.
15
- */
16
- const next_getJSScript = async (url) => {
17
- // get the page source
18
- const res = await makeRequest(url);
19
- const pageSource = await res.text();
20
-
21
- // cheerio to parse the page source
22
- const $ = cheerio.load(pageSource);
23
-
24
- // find all script tags
25
- const scriptTags = $("script");
26
-
27
- // iterate through script tags
28
- for (const scriptTag of scriptTags) {
29
- // get the src attribute
30
- const src = $(scriptTag).attr("src");
31
-
32
- // see if the src is a JS file
33
- if (
34
- src !== undefined &&
35
- src.match(/(https:\/\/[a-zA-Z0-9_\_\.]+\/.+\.js\??.*|\/.+\.js\??.*)/)) {
36
- // if the src starts with /, like `/static/js/a.js` find the absolute URL
37
- if (src.startsWith("/")) {
38
- const absoluteUrl = new URL(url).origin + src;
39
- if (!getJsUrls().includes(absoluteUrl)) {
40
- pushToJsUrls(absoluteUrl);
41
- }
42
- } else if (src.match(/^[^/]/)) {
43
- // if the src is a relative URL, like `static/js/a.js` find the absolute URL
44
- // Get directory URL (origin + path without filename)
45
- const pathParts = new URL(url).pathname.split("/");
46
- pathParts.pop(); // remove filename from last
47
- const directory = new URL(url).origin + pathParts.join("/") + "/";
48
-
49
- if (!getJsUrls().includes(directory + src)) {
50
- pushToJsUrls(directory + src);
51
- }
52
- } else {
53
- if (!getJsUrls().includes(src)) {
54
- pushToJsUrls(src);
55
- }
56
- }
57
- } else {
58
- // if the script tag is inline, it could contain static JS URL
59
- // to get these, simply regex from the JS script
60
-
61
- const js_script = $(scriptTag).html();
62
- const matches = js_script.match(/static\/chunks\/[a-zA-Z0-9_\-]+\.js/g);
63
-
64
- if (matches) {
65
- const uniqueMatches = [...new Set(matches)];
66
- for (const match of uniqueMatches) {
67
- // if it is using that static/chunks/ pattern, I can just get the filename
68
- const filename = match.replace("static/chunks/", "");
69
-
70
- // go through the already found URLs, coz they will have it (src attribute
71
- // is there before inline things)
72
-
73
- let js_path_dir;
74
-
75
- for (const js_url of getJsUrls()) {
76
- if (
77
- !js_path_dir &&
78
- new URL(js_url).host === new URL(url).host &&
79
- new URL(js_url).pathname.includes("static/chunks/")
80
- ) {
81
- js_path_dir = js_url.replace(/\/[^\/]+\.js.*$/, "");
82
- }
83
- }
84
- if (js_path_dir) { // Ensure js_path_dir was found
85
- pushToJsUrls(js_path_dir + "/" + filename);
86
- }
87
- }
88
- }
89
- }
90
- }
91
-
92
- console.log(
93
- chalk.green(`[✓] Found ${getJsUrls().length} JS files from the script tags`),
94
- );
95
-
96
- return getJsUrls();
97
- };
98
-
99
- export default next_getJSScript;
@@ -1,201 +0,0 @@
1
- import chalk from "chalk";
2
- import puppeteer from "puppeteer";
3
- import parser from "@babel/parser";
4
- import _traverse from "@babel/traverse";
5
- const traverse = _traverse.default;
6
- import inquirer from "inquirer";
7
- import CONFIG from "../../globalConfig.js";
8
- import makeRequest from "../../utility/makeReq.js";
9
- import execFunc from "../../utility/runSandboxed.js";
10
- import { getJsUrls, pushToJsUrls } from "../globals.js"; // Import js_urls functions
11
-
12
- /**
13
- * Asynchronously fetches the given URL and extracts JavaScript file URLs
14
- * from webpack's require.ensure() function.
15
- *
16
- * @param {string} url - The URL of the webpage to fetch and parse.
17
- * @returns {Promise<string[]|undefined>} - A promise that resolves to an array of
18
- * absolute URLs pointing to JavaScript files found in require.ensure()
19
- * functions, or undefined if no webpack JS is found.
20
- */
21
- const next_getLazyResources = async (url) => {
22
- const browser = await puppeteer.launch({
23
- headless: true,
24
- });
25
-
26
- const page = await browser.newPage();
27
-
28
- await page.setRequestInterception(true);
29
-
30
- page.on("request", async (request) => {
31
- // get the request url
32
- const req_url = request.url(); // Renamed to avoid conflict with outer 'url'
33
-
34
- // see if the request is a JS file, and is a get request
35
- if (
36
- request.method() === "GET" &&
37
- req_url.match(/https?:\/\/[a-z\._\-]+\/.+\.js\??.*/)
38
- ) {
39
- if (!getJsUrls().includes(req_url)) {
40
- pushToJsUrls(req_url);
41
- }
42
- }
43
-
44
- await request.continue();
45
- });
46
-
47
- await page.goto(url);
48
-
49
- await browser.close();
50
-
51
- let webpack_js;
52
-
53
- // iterate through JS files
54
- for (const js_url of getJsUrls()) {
55
- // match for webpack js file
56
- if (js_url.match(/\/webpack.*\.js/)) {
57
- console.log(chalk.green(`[✓] Found webpack JS file at ${js_url}`));
58
- webpack_js = js_url;
59
- }
60
- }
61
-
62
- if (!webpack_js) {
63
- console.log(chalk.red("[!] No webpack JS file found"));
64
- console.log(chalk.magenta(CONFIG.notFoundMessage));
65
- return; // Return undefined as per JSDoc
66
- }
67
-
68
- // parse the webpack JS file
69
- const res = await makeRequest(webpack_js);
70
- const webpack_js_source = await res.text();
71
-
72
- // parse it with @babel/*
73
- const ast = parser.parse(webpack_js_source, {
74
- sourceType: "unambiguous",
75
- plugins: ["jsx", "typescript"],
76
- });
77
-
78
- let functions = [];
79
-
80
- traverse(ast, {
81
- FunctionDeclaration(path) {
82
- functions.push({
83
- name: path.node.id?.name || "(anonymous)",
84
- type: "FunctionDeclaration",
85
- source: webpack_js_source.slice(path.node.start, path.node.end),
86
- });
87
- },
88
- FunctionExpression(path) {
89
- functions.push({
90
- name: path.parent.id?.name || "(anonymous)",
91
- type: "FunctionExpression",
92
- source: webpack_js_source.slice(path.node.start, path.node.end),
93
- });
94
- },
95
- ArrowFunctionExpression(path) {
96
- functions.push({
97
- name: path.parent.id?.name || "(anonymous)",
98
- type: "ArrowFunctionExpression",
99
- source: webpack_js_source.slice(path.node.start, path.node.end),
100
- });
101
- },
102
- ObjectMethod(path) {
103
- functions.push({
104
- name: path.node.key.name,
105
- type: "ObjectMethod",
106
- source: webpack_js_source.slice(path.node.start, path.node.end),
107
- });
108
- },
109
- ClassMethod(path) {
110
- functions.push({
111
- name: path.node.key.name,
112
- type: "ClassMethod",
113
- source: webpack_js_source.slice(path.node.start, path.node.end),
114
- });
115
- },
116
- });
117
-
118
- let user_verified = false;
119
- // method 1
120
- // iterate through the functions, and find out which one ends with `".js"`
121
-
122
- let final_Func;
123
- for (const func of functions) {
124
- if (func.source.match(/"\.js".{0,15}$/)) {
125
- console.log(
126
- chalk.green(`[✓] Found JS chunk having the following source`),
127
- );
128
- console.log(chalk.yellow(func.source));
129
- final_Func = func.source;
130
- }
131
- }
132
-
133
- if (!final_Func) { // Added check if final_Func was not found
134
- console.log(chalk.red("[!] No suitable function found in webpack JS for lazy loading."));
135
- return [];
136
- }
137
-
138
- // ask through input if this is the right thing
139
- const askCorrectFuncConfirmation = async () => {
140
- const { confirmed } = await inquirer.prompt([
141
- {
142
- type: "confirm",
143
- name: "confirmed",
144
- message: "Is this the correct function?",
145
- default: true,
146
- },
147
- ]);
148
- return confirmed;
149
- };
150
-
151
- user_verified = await askCorrectFuncConfirmation();
152
- if (user_verified === true) {
153
- console.log(
154
- chalk.cyan("[i] Proceeding with the selected function to fetch files"),
155
- );
156
- } else {
157
- console.log(chalk.red("[!] Not executing function."));
158
- return [];
159
- }
160
-
161
- const urlBuilderFunc = `(() => (${final_Func}))()`;
162
-
163
- let js_paths = [];
164
- try {
165
- // rather than fuzzing, grep the integers from the func code
166
- const integers = final_Func.match(/\d+/g);
167
- if (integers) { // Check if integers were found
168
- // iterate through all integers, and get the output
169
- for (const i of integers) {
170
- const output = execFunc(urlBuilderFunc, parseInt(i));
171
- if (output.includes("undefined")) {
172
- continue;
173
- } else {
174
- js_paths.push(output);
175
- }
176
- }
177
- }
178
- } catch (err) {
179
- console.error("Unsafe or invalid code:", err.message);
180
- return [];
181
- }
182
-
183
- if (js_paths.length > 0) {
184
- console.log(chalk.green(`[✓] Found ${js_paths.length} JS chunks`));
185
- }
186
-
187
- // build final URL
188
- let final_urls = [];
189
- for (let i = 0; i < js_paths.length; i++) {
190
- // get the directory of webpack file
191
- const webpack_dir = webpack_js.split("/").slice(0, -1).join("/");
192
- // replace the filename from the js path
193
- const js_path_dir = js_paths[i].replace(/\/[a-zA-Z0-9\.]+\.js.*$/, "");
194
- const final_url = webpack_dir.replace(js_path_dir, js_paths[i]);
195
- final_urls.push(final_url);
196
- }
197
-
198
- return final_urls;
199
- };
200
-
201
- export default next_getLazyResources;