@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
@@ -0,0 +1,258 @@
1
+ # Example Scenario of using JS-Recon
2
+
3
+ This document highlights using the modules of JS-Recon individually. All of this can be automated, which can be found at the end of the file in the [Run Module](#run-module).
4
+
5
+ This example assumes that the app is a Next.JS targets. The tool is currently optimized for Next.JS.
6
+
7
+ The `lazyload` module will work on Next.JS, Nuxt.JS, and Svelte apps. All other modules are only expected to work on Next.JS apps.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Target](#target)
12
+ - [Initial Recon](#initial-recon)
13
+ - [Downloading JS files](#downloading-js-files)
14
+ - [Finding strings](#finding-strings)
15
+ - [Subseqent Requests](#subseqent-requests)
16
+ - [Getting more with strings analysis](#getting-more-with-strings-analysis)
17
+ - [Getting client-side endpoints](#getting-client-side-endpoints)
18
+ - [Mapping all the functions](#mapping-all-the-functions)
19
+ - [Launching interactive console](#launching-interactive-console)
20
+ - [Run Module](#run-module)
21
+
22
+ ## Target
23
+
24
+ The client provides the pentester a wildcard target `*.example.com`
25
+
26
+ ## Initial Recon
27
+
28
+ The pentester starts by gathering subdomains for the target, and then uses HTTP probe to filter out all the available HTTP servers.
29
+
30
+ They decide to analyze JavaScript of all the websites to gain access to additional attack surface.
31
+
32
+ ## Downloading JS files
33
+
34
+ To download JS files, the pentester can use the [`lazyload` module](./lazyload.md) of the tool. To run this, they can use the following command:
35
+
36
+ ```bash
37
+ js-recon lazyload -u https://app.example.com
38
+ ```
39
+
40
+ The tool will then analyze the responses from the server, and then download all the JS files it could find. The JS files will be written in the `./output/app.example.com` directory. If the app contains external scripts, then those will be written in the `./output/<domain>` directory.
41
+
42
+ The pentester could get the URL from the top of each file, as the tool writes all the JS files with their source commented on the top
43
+
44
+ _At the time of writing this, the tool is capable of downloading JS files for **Next.JS, Nuxt.JS, and Svelte**. For all other apps, it will download the JS files that are loaded on the webpage_
45
+
46
+ ## Finding strings
47
+
48
+ Once the pentester has downloaded all the JS files, the first thing that they would like to do is to analyze all the strings that are found in the app. To do so, they can run the [`strings` module](./strings.md).
49
+
50
+ ```bash
51
+ js-recon strings -d output/app.example.com -e
52
+ ```
53
+
54
+ Breakdown of the command:
55
+
56
+ - `strings`: Run the module to analyze strings
57
+ - `-d`: Shorthand flag for `--directory`. Defines the directory containing the JS files. If any changes to default values hasn't been done in previous command, it should be `./output/<domain>`
58
+ - `-e`: Shorthand flag for `--extract-urls`. Iterates through all the strings found, and prints any potential URLs or paths by matching against the regex
59
+ - The output for this flag is `extracted_urls.json`
60
+ - In case that the pentester wants to output it as an OpenAPI collection to load in an API client, they can use the `--openapi` flag. It will be written in `extracted_urls-openapi.json`
61
+
62
+ The `extracted_urls.json` has the following structure:
63
+
64
+ ```json
65
+ {
66
+ "urls": [
67
+ "https://api.example.com",
68
+ "https://rum.example.com",
69
+ "https://www.example.com",
70
+ "https://app.example.com",
71
+ "https://internal.app.com"
72
+ ],
73
+ "paths": [
74
+ "/v1/admin",
75
+ "/v1/dashboard",
76
+ "/v1/members",
77
+ "/v1/report",
78
+ "/v1/settings",
79
+ "/v1/edit"
80
+ ]
81
+ }
82
+ ```
83
+
84
+ ## Subseqent Requests
85
+
86
+ JS-Recon has found that the app is using Next.JS. This framework has a feature that upon sending requests to a valid client-side endpoints along with the `RSC: 1` header, the application returns a response with content type `text/x-component`, which contains more client-side paths and JS files. To get this, the tool requires the `extracted_urls.json` from the strings module, which has been generated in the previous step.
87
+
88
+ To use this method, the pentester can pass the `--subsequent-requests` flag to the lazyload command:
89
+
90
+ ```bash
91
+ js-recon lazyload -u https://app.example.com --subsequent-requests
92
+ ```
93
+
94
+ By passing this flag, the tool will read the `extracted_urls.json` file, and make HTTP requests accordingly, and then save the files found in the `output/app.example.com` directory.
95
+
96
+ ## Getting more with strings analysis
97
+
98
+ Now that the tester has got more JS files, they can run string analysis again. This time, they should pass a few more arguments to the tool:
99
+
100
+ ```bash
101
+ js-recon strings -d output/app.example.com -e -p --openapi -s
102
+ ```
103
+
104
+ Breakdown of additional flags:
105
+
106
+ - `-p`: Shorthand flag for `--permutate`. This will permutate the `urls` and `paths` in the `extracted_urls.json` file. The output will be a plaintext (`.txt`) file called `extracted_urls.txt`
107
+ - `--openapi`: This flag will genetate an output file called `extracted_urls-openapi.json`. This file is based on the `paths` in the `extracted_urls.json`, and can be directly loaded into an API client like [Postman](https://www.postman.com) or [Bruno](https://usebruno.com)
108
+ - `-s`: Shorthand flag for `--scan-secrets`. This will iterate over all the strings found, and match it against regex for popular secrets
109
+
110
+ ## Getting client-side endpoints
111
+
112
+ Now that the pentester has got all the JS files and a rough ideation of what the app can do (through string analysis), they can now get the exact client-side endpoints. Apart from unique implementations, there are some common ways a web-app stores client-side endpoints. The tool utilizes the common methods to find the client-side endpoints in the web app.
113
+
114
+ To do so, they can use the `endpoints` module of the tool
115
+
116
+ ```bash
117
+ js-recon endpoints -d output/app.example.com -u https://app.example.com -t next --subsequent-requests-dir output/app.example.com/___subsequent_requests
118
+ ```
119
+
120
+ Breakdown of the command:
121
+
122
+ - `endpoints`: This module extracts client-side endpoints from the app
123
+ - `-d`: Shorthand flag for `--directory`. Defines the directory in which the JS files are stored for the given target
124
+ - `-u`: Shorthand flag for `--urls`. The URL of the target (the paths found are prepended to it)
125
+ - `-t`: Shorthand flag for `--tech`. Defines the framework (aka tech) that the target is using. It is required to find the suitable methods
126
+ - Run with `-l`/`--list` to see list of supported tech: `js-recon endpoints -l`
127
+ - `--subsequent-requests-dir`: Flag specific to Next.js (`-t next`) targets. Defines the directory containing response texts for requests with `RSC: 1` header. By default, it is `output/<domain>/___subsequent_requests` (triple underscore `_` before `subsequent_requests`)
128
+
129
+ This command will write a file called `endpoints.json`. Following is an example of this file:
130
+
131
+ ```json
132
+ {
133
+ "https://app.example.com": {
134
+ "/": {},
135
+ "/dash": {
136
+ "/dash/clients",
137
+ "/dash/automations",
138
+ "/dash/usage"
139
+ },
140
+ "/settings": {
141
+ "/settings/clients": {
142
+ "/settings/clients/edit",
143
+ "/settings/clients/add"
144
+ },
145
+ "/settings/automations",
146
+ "/settings/usage"
147
+ }
148
+ },
149
+ "https://internal.example.com": {
150
+ "/prod": {
151
+ "/prod/env"
152
+ }
153
+ }
154
+ }
155
+ ```
156
+
157
+ ## Mapping all the functions
158
+
159
+ At this point, the pentester has got an idea of what the app looks like. They have also used the app to see the functionality in action. Now, they suspect that the app contains a secret endpoint. They have seen `https://internal.app.com` in the strings output, but are unsure how it works. They decide to manually analyze the JS files. This is where the `map` modules could help them.
160
+
161
+ They would like to first get all the instances of `fetch()` to know which functions can make the API calls. Apart from this, they would also like to get the AI-generated descriptions for the functions, as it would significantly speed up the process of analyzing the flow of all the functions. To do so, they can run the `map` module of the tool.
162
+
163
+ ```bash
164
+ js-recon map -d output/app.example.com -t next --ai description
165
+ ```
166
+
167
+ Breakdown of the command:
168
+
169
+ - `map`: Runs the `map` module
170
+ - `-d`: Shorthand flag for `--directory`. Defines the directory of the JS files
171
+ - `-t`: Shorthand flag for `--tech`. Defines the technology (aka framework) used by the app
172
+ - Run with `-l`-/`--list` flag to see a supported frameworks
173
+ - `js-recon map -l`
174
+ - `--ai`: Enable AI parsing. `description` is used as its value, which means that the tool will write descriptions for the functions
175
+
176
+ The pentester can also adjust some AI settings:
177
+
178
+ - `--ai-provider`: AI provider to use
179
+ - `openai` and `ollama` are supported as of writing this
180
+ - `--model`: AI model to use
181
+ - `--openai-api-key`: API key to use for OpenAI
182
+ - The value for environment variable `$OPENAI_API_KEY` will be used if not provided
183
+ - `--ai-threads <threads>`: Number of threads to simultaneously run to generate descriptions
184
+ - Refer to [Organization Limits](https://platform.openai.com/settings/organization/limits) in [OpenAI API Platform](https://platform.openai.com) for limits for your OpenAI Account
185
+ - For Ollama, adjust the value as per capacity of machine running Ollama
186
+ - `--ai-endpoint`: Endpoint to use with AI models
187
+ - Defaults to `https://api.openai.com/v1` for OpenAI
188
+ - Some providers like xAI supported supported using OpenAI SDK to use their models. Refer to their docs to know latest updates
189
+ - Defaults to `http://127.0.0.1:11434` for Ollama
190
+
191
+ ## Launching interactive console
192
+
193
+ Now that the pentester has got the mappings of all the functions, they can now use interactive console. To launch it, they can add `-i`/`--interative` flag to the previous command
194
+
195
+ ```bash
196
+ js-recon map -d output/app.example.com -t next --ai description -i
197
+ ```
198
+
199
+ _This feature might look complex, so it is recommended to get an overview through the [Interactive Mode Docs](./interactive-mode.md) before reading further_
200
+
201
+ The pentester would first like to get the instances of `fetch()`, so that they can know the sites where an API call could be made. So, they will run the following command in interactive mode:
202
+
203
+ ```
204
+ list fetch
205
+ ```
206
+
207
+ This will list all the functions that have a fetch function. If the pentester had enabled the AI descriptions, then they could also see a brief of what the function does. Now, they can go to any function that seems suspicious
208
+
209
+ ```
210
+ go to 1234
211
+ ```
212
+
213
+ By running this command, the tool would clear the output of the interactive mode, and print the code of the function. The tool provides vim like interface and shortcuts. The user can scroll on the function to go either up or down. Also, they can press `Esc`, and then use the arrow keys to navigate. To focus again on the input box, they can press the `i` key. To quit the app, they can press `Esc` and then `q` or `Ctrl-c`
214
+
215
+ Since the pentester prefers to see the function code in the IDE of their choice, they can write this to a separate file. To do so, they can run the following command in the interactive mode:
216
+
217
+ ```
218
+ set funcwritefile <filename>
219
+ ```
220
+
221
+ Now, every time when the `go to <id>` command will be ran, the tool will write the code to the specified file.
222
+ Once they open it in the IDE of their choice, they can go to the instances of fetch by finding it through `C-f` in the IDE. Once they find an instance, they could manually reverse engineer the full request.
223
+
224
+ To assist in doing the same, they used the following commands:
225
+
226
+ - `list all`: Lists all the functions, their descriptions, and the file they are found in
227
+ - `trace <functionName>`: This lists all the other function that the given function imports, as well as the functions to which this is being exported
228
+ - For example, a function required to modify the UI, so it will import those function, and hence they will be listed as imports
229
+ - This function is called at multiple places, which are listed as exports
230
+ - `go back`: This will take the pentester to the previous function they viewed
231
+ - `go ahead`: This will take the pentester to the next function they viewed (should work if they used `go back`)
232
+
233
+ ## Run Module
234
+
235
+ If this process seems tidious (which it is), the pentester can use the `run` module of the tool. It will:
236
+
237
+ - [Download all the JS files](#downloading-js-files)
238
+ - [Find all the strings](#finding-strings)
239
+ - [Check for subsequent requests if required](#subseqent-requests)
240
+ - [Run string analysis again](#getting-more-with-strings-analysis)
241
+ - [Get all client-side endpoints](#getting-client-side-endpoints)
242
+ - [Map all the functions](#mapping-all-the-functions)
243
+
244
+ Here's what it will **NOT** do:
245
+
246
+ - Understand the output files to build a good attack vector
247
+ - The pentester can fuzz the `paths` from the `strings` module on multiple hosts
248
+ - They can see the UI on the client-side paths found by `endpoints` module
249
+ - They can come up with new methods to get the most from the output of different modules
250
+ - Completely resolve all the requests (it would go as deep as possible, but couldn't fully resolve some requests as of writing this)
251
+
252
+ The docs for the `run` module can be found [here](./run.md)
253
+
254
+ The pentester could now automate the mentioned steps by running the following command:
255
+
256
+ ```bash
257
+ js-recon run -u https://app.example.com --secrets --ai description
258
+ ```
@@ -0,0 +1,76 @@
1
+ # Interactive Mode for Next.js Maps
2
+
3
+ The interactive mode for Next.js maps provides a terminal-based interface to explore and analyze the functions within your Next.js application. This guide will walk you through the features and commands available in this mode.
4
+
5
+ ## Getting Started
6
+
7
+ To launch the interactive mode, run the following command:
8
+
9
+ ```bash
10
+ js-recon map <other options> -i
11
+ ```
12
+
13
+ ## User Interface
14
+
15
+ The interactive mode interface is composed of three main components:
16
+
17
+ - **Title Box**: Displays the title "JS Recon Interactive Mode".
18
+ - **Output Box**: Shows the output of commands and function information. You can scroll through this box using the arrow keys when it's in focus.
19
+ - **Input Box**: This is where you type your commands.
20
+
21
+ ## Keybindings
22
+
23
+ The following keybindings are available for navigation and control:
24
+
25
+ | Key | Description |
26
+ | --------------- | ----------------------------------------------------------------------------------------------------- |
27
+ | `Ctrl+C` or `q` | Exit the interactive mode (when not in the input box). To exit from the input box, press `Esc` first. |
28
+ | `i` | Focus the input box. |
29
+ | `o` | Focus the output box. |
30
+ | `Esc` | When in the input box, focuses the output box. |
31
+ | `Up Arrow` | In the input box, navigate to the previous command. |
32
+ | `Down Arrow` | In the input box, navigate to the next command. |
33
+ | `Up Arrow` | In the output box, scroll up. |
34
+ | `Down Arrow` | In the output box, scroll down. |
35
+
36
+ ## Commands
37
+
38
+ Here is a list of available commands and their usage:
39
+
40
+ ### `help`
41
+
42
+ Displays the help menu with a list of all available commands.
43
+
44
+ ### `exit`
45
+
46
+ Exits the interactive mode.
47
+
48
+ ### `clear`
49
+
50
+ Clears the content of the output box.
51
+
52
+ ### `list`
53
+
54
+ Lists different types of information. Usage: `list <option>`
55
+
56
+ - `list fetch`: Lists all functions that contain `fetch` instances.
57
+ - `list all`: Lists all functions found in the application.
58
+ - `list nav`: Lists your function navigation history.
59
+
60
+ ### `go`
61
+
62
+ Navigates between functions. Usage: `go <option>`
63
+
64
+ - `go to <functionID>`: Displays the code for a specific function.
65
+ - `go back`: Navigates to the previously viewed function.
66
+ - `go ahead`: Navigates to the next function in your history.
67
+
68
+ ### `set`
69
+
70
+ Sets configuration options. Usage: `set <option> <value>`
71
+
72
+ - `set funcwritefile <filename>`: Sets the file where function code will be written when you use the `go to` command.
73
+
74
+ ### `trace`
75
+
76
+ Traces the imports for a given function. Usage: `trace <functionName>`
@@ -0,0 +1,56 @@
1
+ # Lazyload Command
2
+
3
+ The `lazyload` command is used to download JavaScript files from a given URL or a list of URLs. It simulates various techniques to discover and fetch JS files that are loaded dynamically.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ js-recon lazyload -u <url/file> [options]
9
+ ```
10
+
11
+ ## Options
12
+
13
+ | Option | Alias | Description | Default | Required |
14
+ | ----------------------------- | ----- | ----------------------------------------------------------------------------------- | -------------------------- | -------- |
15
+ | `--url <url/file>` | `-u` | Target URL or a file containing a list of URLs (one per line). | | Yes |
16
+ | `--output <directory>` | `-o` | Output directory to save the downloaded JS files. | `output` | No |
17
+ | `--strict-scope` | | Download JS files from only the input URL domain. | `false` | No |
18
+ | `--scope <scope>` | `-s` | Download JS files from specific domains (comma-separated). Use `*` for all domains. | `*` | No |
19
+ | `--threads <threads>` | `-t` | Number of threads to use for downloading. | `1` | No |
20
+ | `--subsequent-requests` | | Download JS files from subsequent requests (Next.JS only). | `false` | No |
21
+ | `--urls-file <file>` | | Input JSON file containing URLs (for `--subsequent-requests`) | `extracted_urls.json` | No |
22
+ | `--api-gateway` | | Generate requests using API Gateway for IP rotation. | `false` | No |
23
+ | `--api-gateway-config <file>` | | API Gateway config file. | `.api_gateway_config.json` | No |
24
+ | `--cache-file <file>` | | File to contain response cache. | `.resp_cache.json` | No |
25
+ | `--disable-cache` | | Disable response caching. | `false` | No |
26
+ | `--yes` | `-y` | Auto-approve executing JS code from the target. | `false` | No |
27
+
28
+ ## Examples
29
+
30
+ ### Basic Usage
31
+
32
+ Download all JavaScript files from a single URL:
33
+
34
+ ```bash
35
+ js-recon lazyload -u https://example.com
36
+ ```
37
+
38
+ ### Setting Scope
39
+
40
+ Download JavaScript files only from `example.com` and `cdn.example.com`:
41
+
42
+ ```bash
43
+ js-recon lazyload -u https://example.com -s "example.com,cdn.example.com"
44
+ ```
45
+
46
+ Using the `--strict-scope` will only download JS files from the URL provided. This will skip any files from external CDN.
47
+
48
+ ### Using API Gateway
49
+
50
+ Use AWS API Gateway to rotate IP addresses while downloading:
51
+
52
+ ```bash
53
+ js-recon lazyload -u https://example.com --api-gateway
54
+ ```
55
+
56
+ Read docs of [API Gateway](./api-gateway.md) for more information.
package/docs/map.md ADDED
@@ -0,0 +1,53 @@
1
+ # Map Command
2
+
3
+ The `map` command is used to map and analyze the functions within a directory of JavaScript files. It can help you understand the codebase by identifying function definitions and, optionally, using AI to generate descriptions.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ js-recon map -d <directory> -t <technology> [options]
9
+ ```
10
+
11
+ ## Options
12
+
13
+ | Option | Alias | Description | Default | Required |
14
+ | -------------------------- | ----- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | -------- |
15
+ | `--directory <directory>` | `-d` | Directory containing JS files. | | Yes |
16
+ | `--tech <tech>` | `-t` | Technology used in the JS files (run with `-l`/`--list` to see available options). | | Yes |
17
+ | `--list` | `-l` | List available technologies. | `false` | No |
18
+ | `--output <file>` | `-o` | Output file name (without extension). | `mapped` | No |
19
+ | `--format <format>` | `-f` | Output format for the results (comma-separated; available: `json`). | `json` | No |
20
+ | `--interactive` | `-i` | Interactive mode for exploring the mapped functions. | `false` | No |
21
+ | `--ai <options>` | | Use AI to analyze the code (comma-separated; available: `description`). | | No |
22
+ | `--ai-provider <provider>` | | Service provider to use for AI (available: openai, ollama) | `openai` | No |
23
+ | `--ai-endpoint <endpoint>` | | Endpoint to use for AI service (for Ollama, etc) | `https://api.openai.com/v1` for OpenAI, and `http://127.0.0.1:11434` for Ollama | No |
24
+ | `--openai-api-key <key>` | | OpenAI API key for AI analysis. | | No |
25
+ | `--model <model>` | | AI model to use for analysis. | `gpt-4o-mini` for OpenAI, and `llama3.1` for Ollama | No |
26
+
27
+ ## Examples
28
+
29
+ ### Basic Usage
30
+
31
+ The `map` command requires you to specify the directory containing the JavaScript files and the technology used.
32
+
33
+ For example, to map a Next.JS application:
34
+
35
+ ```bash
36
+ js-recon map -d /path/to/js-files -t next
37
+ ```
38
+
39
+ ### Interactive Mode
40
+
41
+ Map functions and explore them in an interactive session. For a detailed guide, see the [Interactive Mode documentation](./interactive-mode.md).
42
+
43
+ ```bash
44
+ js-recon map -d /path/to/js-files -t next -i
45
+ ```
46
+
47
+ ### AI-Powered Analysis
48
+
49
+ Use an AI model to generate descriptions for the mapped functions by providing the `--ai` flag and an OpenAI API key.
50
+
51
+ ```bash
52
+ js-recon map -d /path/to/js-files -t next --ai description --openai-api-key <your-key>
53
+ ```
package/docs/run.md ADDED
@@ -0,0 +1,54 @@
1
+ # Run Command
2
+
3
+ The `run` command is a powerful feature that automates the most of the JavaScript reconnaissance workflow by executing a series of modules in a predefined order. This command is ideal for users who want to perform a basic analysis of a target without running each module individually.
4
+
5
+ ## Workflow
6
+
7
+ The `run` command executes the following modules in sequence:
8
+
9
+ 1. **Lazy Load (Initial)**: Downloads the initial set of JavaScript files from the target URL.
10
+ 2. **Strings (Initial)**: Extracts strings, URLs, and paths from the downloaded JavaScript files.
11
+ 3. **Lazy Load (Subsequent Requests - for Next.JS)**: Downloads additional JavaScript files discovered from the extracted URLs and paths.
12
+ 4. **Strings (Final)**: Performs another round of string extraction on the newly downloaded files to find more endpoints, secrets, and other valuable information.
13
+ 5. **Endpoints**: Analyzes the collected data to identify and list all potential API endpoints.
14
+ 6. **Map**: Maps all the functions and their relationships within the JavaScript files to provide a clear overview of the application's structure.
15
+
16
+ ## Usage
17
+
18
+ ```bash
19
+ js-recon run -u <url/file> [options]
20
+ ```
21
+
22
+ ### Required Arguments
23
+
24
+ - `-u, --url <url/file>`: The target URL or a file containing a list of URLs (one per line).
25
+
26
+ ### Options
27
+
28
+ | Option | Alias | Description | Default | Required |
29
+ | ----------------------------- | ----- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------- | -------- |
30
+ | `--url <url/file>` | `-u` | Target URL or a file containing a list of URLs (one per line) | | Yes |
31
+ | `--output <directory>` | `-d` | Output directory | `output` | No |
32
+ | `--strict-scope` | | Download JS files from only the input URL domain | `false` | No |
33
+ | `--scope <scope>` | `-s` | Download JS files from specific domains (comma-separated) | `*` | No |
34
+ | `--threads <threads>` | `-t` | Number of threads to use | `1` | No |
35
+ | `--api-gateway` | | Generate requests using API Gateway | `false` | No |
36
+ | `--api-gateway-config <file>` | | API Gateway config file | `.api_gateway_config.json` | No |
37
+ | `--cache-file <file>` | | File to store response cache | `.resp_cache.json` | No |
38
+ | `--disable-cache` | | Disable response caching | `false` | No |
39
+ | `--yes` | `-y` | Auto-approve executing JS code from the target | `false` | No |
40
+ | `--secrets` | | Scan for secrets | `false` | No |
41
+ | `--ai <options>` | | Use AI to analyze the code (comma-separated; available: description) | | No |
42
+ | `--ai-threads <threads>` | | Number of threads to use for AI | `5` | No |
43
+ | `--ai-provider <provider>` | | Service provider to use for AI (available: openai, ollama) | `openai` | No |
44
+ | `--ai-endpoint <endpoint>` | | Endpoint to use for AI service (for Ollama, etc) | `https://api.openai.com/v1` for OpenAI, and `http://127.0.0.1:11434` for Ollama | No |
45
+ | `--openai-api-key <key>` | | OpenAI API Key | | No |
46
+ | `--model <model>` | | AI model to use | `gpt-4o-mini` for OpenAI, and `llama3.1` for Ollama | No |
47
+
48
+ ## Example
49
+
50
+ ```bash
51
+ js-recon run -u https://example.com -o results --secrets --ai description
52
+ ```
53
+
54
+ This command will perform a full analysis on `https://example.com`, save the output to the `results` directory, scan for secrets, and use AI to generate descriptions for the mapped functions.
@@ -0,0 +1,75 @@
1
+ # Strings Command
2
+
3
+ The `strings` command is used to extract strings, URLs, and secrets from a directory of JavaScript files. This is useful for identifying sensitive information and potential API endpoints.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ js-recon strings -d <directory> [options]
9
+ ```
10
+
11
+ ## Options
12
+
13
+ | Option | Alias | Description | Default | Required |
14
+ | ----------------------------- | ----- | ------------------------------------------------------------- | ---------------- | -------- |
15
+ | `--directory <directory>` | `-d` | Directory containing JS files. | | Yes |
16
+ | `--output <file>` | `-o` | JSON file to save the extracted strings. | `strings.json` | No |
17
+ | `--extract-urls` | `-e` | Extract URLs from the strings. | `false` | No |
18
+ | `--extracted-url-path <file>` | | Output file for extracted URLs and paths (without extension). | `extracted_urls` | No |
19
+ | `--permutate` | `-p` | Permutate the URLs and paths found. | `false` | No |
20
+ | `--openapi` | | Generate an OpenAPI specification from the paths found. | `false` | No |
21
+ | `--scan-secrets` | `-s` | Scan for secrets within the strings. | `false` | No |
22
+
23
+ ## Examples
24
+
25
+ ### Basic Usage
26
+
27
+ Extract all strings from a directory of JS files and save them to `strings.json`:
28
+
29
+ ```bash
30
+ js-recon strings -d /path/to/js-files
31
+ ```
32
+
33
+ ### Extract URLs
34
+
35
+ Extract strings and also identify and save any URLs found within them:
36
+
37
+ ```bash
38
+ js-recon strings -d /path/to/js-files -e
39
+ ```
40
+
41
+ This will write a new file called `extracted_urls.json` along with the default `strings.json`
42
+
43
+ ### Scan for Secrets
44
+
45
+ Extract strings and scan for any potential secrets or sensitive information:
46
+
47
+ ```bash
48
+ js-recon strings -d /path/to/js-files -s
49
+ ```
50
+
51
+ This will print all the potential finds on the terminal window.
52
+
53
+ *Please note that this process could be memory and compute intensive, and can take longer to run.*
54
+
55
+ ### Generate OpenAPI Specification
56
+
57
+ Extract URLs and paths, and then generate an OpenAPI specification:
58
+
59
+ ```bash
60
+ js-recon strings -d /path/to/js-files -e --openapi
61
+ ```
62
+
63
+ This will generate the default `strings.json`, the `extracted_urls.json` file with URLs and paths in simple JSON format, and the `extracted_urls-openapi.json` file. The `extracted_urls-openapi.json` can be imported into API clients like [Postman](https://www.postman.com), [Bruno](https://www.usebruno.com), etc.
64
+
65
+ ### Permutate URLs and Paths
66
+
67
+ The `--permutate` (`-p`) flag generates new potential endpoints by combining the base of found URLs with all discovered paths. This requires the `-e` flag to be active.
68
+
69
+ For example, if the tool finds the URL `https://api.example.com/v1/users` and the path `/v2/orders`, it will generate `https://api.example.com/v2/orders`.
70
+
71
+ ```bash
72
+ js-recon strings -d /path/to/js-files -e -p
73
+ ```
74
+
75
+ The permuted URLs will be saved to `extracted_urls.txt` along with `strings.json` and `extracted_urls.json`
package/endpoints.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "https://x.ai": {
3
+ "/": {},
4
+ "/news": {
5
+ "/news/grok-3": {},
6
+ "/news/series-c": {},
7
+ "/news/grok-1212": {},
8
+ "/news/grok-image-generation-release": {},
9
+ "/news/api": {},
10
+ "/news/grok-2": {},
11
+ "/news/series-b": {},
12
+ "/news/grok-1.5v": {},
13
+ "/news/grok-1.5": {},
14
+ "/news/grok-os": {},
15
+ "/news/prompt-ide": {},
16
+ "/news/grok": {}
17
+ },
18
+ "/careers": {
19
+ "/careers/open-roles": {}
20
+ },
21
+ "/grok": {
22
+ "/grok/business": {}
23
+ },
24
+ "/api": {},
25
+ "/company": {},
26
+ "/colossus": {},
27
+ "/contact": {},
28
+ "/legal": {
29
+ "/legal/privacy-policy": {}
30
+ }
31
+ },
32
+ "https://job-boards.greenhouse.io": {
33
+ "/": {},
34
+ "/xai": {
35
+ "/xai/jobs": {
36
+ "/xai/jobs/4754207007": {},
37
+ "/xai/jobs/4758530007": {},
38
+ "/xai/jobs/4730111007": {},
39
+ "/xai/jobs/4758535007": {},
40
+ "/xai/jobs/4703116007": {},
41
+ "/xai/jobs/4703137007": {}
42
+ }
43
+ }
44
+ },
45
+ "https://grok.com": {
46
+ "/": {}
47
+ },
48
+ "https://docs.x.ai": {
49
+ "/": {},
50
+ "/docs": {
51
+ "/docs/models": {},
52
+ "/docs/overview": {}
53
+ }
54
+ },
55
+ "https://console.x.ai": {
56
+ "/": {}
57
+ },
58
+ "https://grok.x.com": {
59
+ "/": {}
60
+ },
61
+ "https://apps.apple.com": {
62
+ "/": {},
63
+ "/app": {
64
+ "/app/apple-store": {
65
+ "/app/apple-store/id6670324846": {}
66
+ }
67
+ }
68
+ },
69
+ "https://play.google.com": {
70
+ "/": {},
71
+ "/store": {
72
+ "/store/apps": {
73
+ "/store/apps/details": {}
74
+ }
75
+ }
76
+ }
77
+ }