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,573 @@
1
+ # CTF Reverse - Tools Reference
2
+
3
+ ## Table of Contents
4
+ - [GDB](#gdb)
5
+ - [Basic Commands](#basic-commands)
6
+ - [PIE Binary Debugging](#pie-binary-debugging)
7
+ - [One-liner Automation](#one-liner-automation)
8
+ - [Memory Examination](#memory-examination)
9
+ - [Radare2](#radare2)
10
+ - [Basic Session](#basic-session)
11
+ - [r2pipe Automation](#r2pipe-automation)
12
+ - [Ghidra](#ghidra)
13
+ - [Headless Analysis](#headless-analysis)
14
+ - [Emulator for Decryption](#emulator-for-decryption)
15
+ - [MCP Commands](#mcp-commands)
16
+ - [Unicorn Emulation](#unicorn-emulation)
17
+ - [Basic Setup](#basic-setup)
18
+ - [Mixed-Mode (64 to 32) Switch](#mixed-mode-64-to-32-switch)
19
+ - [Register Tracing Hook](#register-tracing-hook)
20
+ - [Track Register Changes](#track-register-changes)
21
+ - [Python Bytecode](#python-bytecode)
22
+ - [Disassembly](#disassembly)
23
+ - [Extract Constants](#extract-constants)
24
+ - [Pyarmor Static Unpack (1shot)](#pyarmor-static-unpack-1shot)
25
+ - [WASM Analysis](#wasm-analysis)
26
+ - [Decompile to C](#decompile-to-c)
27
+ - [Common Patterns](#common-patterns)
28
+ - [Android APK](#android-apk)
29
+ - [Extraction](#extraction)
30
+ - [Key Locations](#key-locations)
31
+ - [Search](#search)
32
+ - [Flutter APK (Blutter)](#flutter-apk-blutter)
33
+ - [HarmonyOS HAP/ABC (abc-decompiler)](#harmonyos-hapabc-abc-decompiler)
34
+ - [.NET Analysis](#net-analysis)
35
+ - [Tools](#tools)
36
+ - [Two-Stage XOR + AES-CBC Decode Pattern (Codegate 2013)](#two-stage-xor--aes-cbc-decode-pattern-codegate-2013)
37
+ - [NativeAOT](#nativeaot)
38
+ - [Packed Binaries](#packed-binaries)
39
+ - [UPX](#upx)
40
+ - [Custom Packers](#custom-packers)
41
+ - [PyInstaller](#pyinstaller)
42
+ - [LLVM IR](#llvm-ir)
43
+ - [Convert to Assembly](#convert-to-assembly)
44
+ - [RISC-V Binary Analysis (EHAX 2026)](#risc-v-binary-analysis-ehax-2026)
45
+ - [Binary Ninja](#binary-ninja)
46
+ - [Decompiler Comparison with dogbolt.org](#decompiler-comparison-with-dogboltorg)
47
+ - [Useful Commands](#useful-commands)
48
+ - [boolector SMT2 for Custom Hash Reversal (OTW Advent 2018)](#boolector-smt2-for-custom-hash-reversal-otw-advent-2018)
49
+
50
+ For dynamic instrumentation tools (Frida, angr, lldb, x64dbg), see [tools-dynamic.md](tools-dynamic.md).
51
+
52
+ ---
53
+
54
+ ## GDB
55
+
56
+ ### Basic Commands
57
+ ```bash
58
+ gdb ./binary
59
+ run # Run program
60
+ start # Run to main
61
+ b *0x401234 # Breakpoint at address
62
+ b *main+0x100 # Relative breakpoint
63
+ c # Continue
64
+ si # Step instruction
65
+ ni # Next instruction (skip calls)
66
+ x/s $rsi # Examine string
67
+ x/20x $rsp # Examine stack
68
+ info registers # Show registers
69
+ set $eax=0 # Modify register
70
+ ```
71
+
72
+ ### PIE Binary Debugging
73
+ ```bash
74
+ gdb ./binary
75
+ start # Forces PIE base resolution
76
+ b *main+0xca # Relative to main
77
+ b *main+0x198
78
+ run
79
+ ```
80
+
81
+ ### One-liner Automation
82
+ ```bash
83
+ gdb -ex 'start' -ex 'b *main+0x198' -ex 'run' ./binary
84
+ ```
85
+
86
+ ### Memory Examination
87
+ ```bash
88
+ x/s $rsi # String at RSI
89
+ x/38c $rsi # 38 characters
90
+ x/20x $rsp # 20 hex words from stack
91
+ x/10i $rip # 10 instructions from RIP
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Radare2
97
+
98
+ ### Basic Session
99
+ ```bash
100
+ r2 -d ./binary # Open in debug mode
101
+ aaa # Analyze all
102
+ afl # List functions
103
+ pdf @ main # Disassemble main
104
+ db 0x401234 # Set breakpoint
105
+ dc # Continue
106
+ ood # Restart debugging
107
+ dr # Show registers
108
+ dr eax=0 # Modify register
109
+ ```
110
+
111
+ ### r2pipe Automation
112
+ ```python
113
+ import r2pipe
114
+ r2 = r2pipe.open('./binary', flags=['-d'])
115
+ r2.cmd('aaa')
116
+ r2.cmd('db 0x401234')
117
+
118
+ for char in range(256):
119
+ r2.cmd('ood') # Restart
120
+ r2.cmd(f'dr eax={char}')
121
+ output = r2.cmd('dc')
122
+ if 'correct' in output:
123
+ print(f"Found: {chr(char)}")
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Ghidra
129
+
130
+ ### Headless Analysis
131
+ ```bash
132
+ analyzeHeadless /path/to/project tmp -import binary -postScript script.py
133
+ ```
134
+
135
+ ### Emulator for Decryption
136
+ ```java
137
+ EmulatorHelper emu = new EmulatorHelper(currentProgram);
138
+ emu.writeRegister("RSP", 0x2fff0000);
139
+ emu.writeRegister("RBP", 0x2fff0000);
140
+
141
+ // Write encrypted data
142
+ emu.writeMemory(dataAddress, encryptedBytes);
143
+
144
+ // Set function arguments
145
+ emu.writeRegister("RDI", arg1);
146
+
147
+ // Run until return
148
+ emu.setBreakpoint(returnAddress);
149
+ emu.run(functionEntryAddress);
150
+
151
+ // Read result
152
+ byte[] decrypted = emu.readMemory(outputAddress, length);
153
+ ```
154
+
155
+ ### MCP Commands
156
+ - Recon: `list_functions`, `list_imports`, `list_strings`
157
+ - Analysis: `decompile_function`, `get_xrefs_to`
158
+ - Annotation: `rename_function`, `rename_variable`
159
+
160
+ ---
161
+
162
+ ## Unicorn Emulation
163
+
164
+ ### Basic Setup
165
+ ```python
166
+ from unicorn import *
167
+ from unicorn.x86_const import *
168
+
169
+ mu = Uc(UC_ARCH_X86, UC_MODE_64)
170
+
171
+ # Map code segment
172
+ mu.mem_map(0x400000, 0x10000)
173
+ mu.mem_write(0x400000, code_bytes)
174
+
175
+ # Map stack
176
+ mu.mem_map(0x7fff0000, 0x10000)
177
+ mu.reg_write(UC_X86_REG_RSP, 0x7fff0000 + 0xff00)
178
+
179
+ # Run
180
+ mu.emu_start(start_addr, end_addr)
181
+ ```
182
+
183
+ ### Mixed-Mode (64 to 32) Switch
184
+ ```python
185
+ # When a 64-bit stub jumps into 32-bit code via retf/retfq:
186
+ # - retf pops 4-byte EIP + 2-byte CS (6 bytes)
187
+ # - retfq pops 8-byte RIP + 8-byte CS (16 bytes)
188
+
189
+ uc32 = Uc(UC_ARCH_X86, UC_MODE_32)
190
+ # Copy memory regions, then GPRs
191
+ reg_map = {
192
+ UC_X86_REG_EAX: UC_X86_REG_RAX,
193
+ UC_X86_REG_EBX: UC_X86_REG_RBX,
194
+ UC_X86_REG_ECX: UC_X86_REG_RCX,
195
+ UC_X86_REG_EDX: UC_X86_REG_RDX,
196
+ UC_X86_REG_ESI: UC_X86_REG_RSI,
197
+ UC_X86_REG_EDI: UC_X86_REG_RDI,
198
+ UC_X86_REG_EBP: UC_X86_REG_RBP,
199
+ }
200
+ for e, r in reg_map.items():
201
+ uc32.reg_write(e, mu.reg_read(r) & 0xffffffff) # mu = 64-bit emulator from above
202
+ uc32.reg_write(UC_X86_REG_EFLAGS, mu.reg_read(UC_X86_REG_RFLAGS) & 0xffffffff)
203
+
204
+ # SSE-heavy blobs need XMM registers copied
205
+ for xr in [UC_X86_REG_XMM0, UC_X86_REG_XMM1, UC_X86_REG_XMM2, UC_X86_REG_XMM3,
206
+ UC_X86_REG_XMM4, UC_X86_REG_XMM5, UC_X86_REG_XMM6, UC_X86_REG_XMM7]:
207
+ uc32.reg_write(xr, mu.reg_read(xr))
208
+
209
+ # Run 32-bit, then copy regs/memory back to 64-bit
210
+ ```
211
+
212
+ **Tip:** set `UC_IGNORE_REG_BREAK=1` to silence warnings on unimplemented regs.
213
+
214
+ ### Register Tracing Hook
215
+ ```python
216
+ def hook_code(uc, address, size, user_data):
217
+ if address == TARGET_ADDR:
218
+ rsi = uc.reg_read(UC_X86_REG_RSI)
219
+ print(f"0x{address:x}: rsi=0x{rsi:016x}")
220
+
221
+ mu.hook_add(UC_HOOK_CODE, hook_code)
222
+ ```
223
+
224
+ ### Track Register Changes
225
+ ```python
226
+ prev_rsi = [None]
227
+ def hook_rsi_changes(uc, address, size, user_data):
228
+ rsi = uc.reg_read(UC_X86_REG_RSI)
229
+ if rsi != prev_rsi[0]:
230
+ print(f"0x{address:x}: RSI changed to 0x{rsi:016x}")
231
+ prev_rsi[0] = rsi
232
+
233
+ mu.hook_add(UC_HOOK_CODE, hook_rsi_changes)
234
+ ```
235
+
236
+ ---
237
+
238
+ ## Python Bytecode
239
+
240
+ ### Disassembly
241
+ ```python
242
+ import marshal, dis
243
+
244
+ with open('file.pyc', 'rb') as f:
245
+ f.read(16) # Skip header (varies by Python version)
246
+ code = marshal.load(f)
247
+ dis.dis(code)
248
+ ```
249
+
250
+ ### Extract Constants
251
+ ```python
252
+ for ins in dis.get_instructions(code):
253
+ if ins.opname == 'LOAD_CONST':
254
+ print(ins.argval)
255
+ ```
256
+
257
+ ### Pyarmor Static Unpack (1shot)
258
+
259
+ Repository: `https://github.com/Lil-House/Pyarmor-Static-Unpack-1shot`
260
+
261
+ ```bash
262
+ # Basic usage (recursive processing)
263
+ python /path/to/oneshot/shot.py /path/to/scripts
264
+
265
+ # Specify pyarmor runtime library explicitly
266
+ python /path/to/oneshot/shot.py /path/to/scripts -r /path/to/pyarmor_runtime.so
267
+
268
+ # Save outputs to another directory
269
+ python /path/to/oneshot/shot.py /path/to/scripts -o /path/to/output
270
+ ```
271
+
272
+ Notes:
273
+ - `oneshot/pyarmor-1shot` must exist before running `shot.py`.
274
+ - Supported focus: Pyarmor 8.x-9.x (`PY` + six digits header style).
275
+ - Pyarmor 7 and earlier (`PYARMOR` header) are out of scope.
276
+ - Disassembly output is generally reliable; decompiled source is experimental.
277
+
278
+ ---
279
+
280
+ ## WASM Analysis
281
+
282
+ ### Decompile to C
283
+ ```bash
284
+ wasm2c checker.wasm -o checker.c
285
+ gcc -O3 checker.c wasm-rt-impl.c -o checker
286
+ ```
287
+
288
+ ### Common Patterns
289
+ - `w2c_memory` - Linear memory array
290
+ - `wasm_rt_trap(N)` - Runtime errors
291
+ - Function exports: `flagChecker`, `validate`
292
+
293
+ ---
294
+
295
+ ## Android APK
296
+
297
+ ### Extraction
298
+ ```bash
299
+ apktool d app.apk -o decoded/ # Best - decodes XML
300
+ jadx app.apk # Decompile to Java
301
+ unzip app.apk -d extracted/ # Simple extraction
302
+ ```
303
+
304
+ ### Key Locations
305
+ - `res/values/strings.xml` - String resources
306
+ - `AndroidManifest.xml` - App metadata
307
+ - `classes.dex` - Dalvik bytecode
308
+ - `assets/`, `res/raw/` - Resources
309
+
310
+ ### Search
311
+ ```bash
312
+ grep -r "flag\|CTF" decoded/
313
+ strings decoded/classes*.dex | grep -i flag
314
+ ```
315
+
316
+ ### Flutter APK (Blutter)
317
+
318
+ ```bash
319
+ # Run Blutter on arm64 build
320
+ python3 blutter.py path/to/app/lib/arm64-v8a out_dir
321
+ ```
322
+
323
+ ### HarmonyOS HAP/ABC (abc-decompiler)
324
+
325
+ Repository: `https://github.com/ohos-decompiler/abc-decompiler`
326
+
327
+ ```bash
328
+ # Extract .hap first to obtain .abc files
329
+ unzip app.hap -d hap_extracted/
330
+ ```
331
+
332
+ Critical startup mode:
333
+ ```bash
334
+ # Use CLI entrypoint (avoid java -jar GUI mode)
335
+ java -cp "./jadx-dev-all.jar" jadx.cli.JadxCLI [options] <input>
336
+ ```
337
+
338
+ ```bash
339
+ # Basic decompile
340
+ java -cp "./jadx-dev-all.jar" jadx.cli.JadxCLI -d "out" ".abc"
341
+
342
+ # Recommended for .abc
343
+ java -cp "./jadx-dev-all.jar" jadx.cli.JadxCLI -m simple --log-level ERROR -d "out_abc_simple" ".abc"
344
+ ```
345
+
346
+ Notes:
347
+ - Start with `-m simple --log-level ERROR`.
348
+ - If `auto` fails, retry with `-m simple` first.
349
+ - Errors do not always mean total failure; check `out_xxx/sources/`.
350
+ - Use a fresh output directory per run.
351
+
352
+ ---
353
+
354
+ ## .NET Analysis
355
+
356
+ ### Tools
357
+ - **dnSpy** - Debugging + decompilation (best)
358
+ - **ILSpy** - Decompiler
359
+ - **dotPeek** - JetBrains decompiler
360
+
361
+ ### NativeAOT
362
+ - Look for `System.Private.CoreLib` strings
363
+ - Type metadata present but restructured
364
+ - Search for length-prefixed UTF-16 patterns
365
+
366
+ ### Two-Stage XOR + AES-CBC Decode Pattern (Codegate 2013)
367
+
368
+ **Pattern:** .NET binary stores an encrypted byte array that undergoes XOR decoding followed by AES-256-CBC decryption. The same key value serves as both the AES key and IV.
369
+
370
+ **Steps:**
371
+ 1. Extract hardcoded byte array and key string from binary (dnSpy/ILSpy)
372
+ 2. XOR each byte (may be multi-pass, e.g., `0x25` then `0x58`, equivalent to single `0x7D`)
373
+ 3. Base64-decode the XOR result
374
+ 4. AES-256-CBC decrypt with `RijndaelManaged` using the extracted key as both Key and IV
375
+
376
+ ```python
377
+ from Crypto.Cipher import AES
378
+ from base64 import b64decode
379
+
380
+ # Step 1: XOR decode
381
+ data = bytearray(encrypted_bytes)
382
+ for i in range(len(data)):
383
+ data[i] ^= 0x7D # Combined XOR key (0x25 ^ 0x58)
384
+
385
+ # Step 2: Base64 decode
386
+ ct = b64decode(bytes(data))
387
+
388
+ # Step 3: AES-256-CBC decrypt (same value for key and IV)
389
+ key = b"9e2ea73295c7201c5ccd044477228527" # Padded to 32 bytes
390
+ cipher = AES.new(key, AES.MODE_CBC, iv=key)
391
+ plaintext = cipher.decrypt(ct)
392
+ ```
393
+
394
+ **Key insight:** When `RijndaelManaged` appears in .NET decompilation, check if Key and IV are set to the same value — this is a common CTF pattern. The XOR stage often serves as a simple obfuscation layer before the real crypto.
395
+
396
+ ---
397
+
398
+ ## Packed Binaries
399
+
400
+ ### UPX
401
+ ```bash
402
+ upx -d packed -o unpacked
403
+ strings binary | grep UPX # Check for UPX signature
404
+ ```
405
+
406
+ ### Custom Packers
407
+ 1. Set breakpoint after unpacking stub
408
+ 2. Dump memory
409
+ 3. Fix PE/ELF headers
410
+
411
+ ### PyInstaller
412
+ ```bash
413
+ python pyinstxtractor.py binary.exe
414
+ # Look in: binary.exe_extracted/
415
+ ```
416
+
417
+ ---
418
+
419
+ ## LLVM IR
420
+
421
+ ### Convert to Assembly
422
+ ```bash
423
+ llc task.ll --x86-asm-syntax=intel
424
+ gcc -c task.s -o file.o
425
+ ```
426
+
427
+ ---
428
+
429
+ ## RISC-V Binary Analysis (EHAX 2026)
430
+
431
+ **Pattern (iguessbro):** Statically linked, stripped RISC-V ELF binary. Can't run natively on x86.
432
+
433
+ **Disassembly with Capstone:**
434
+ ```python
435
+ from capstone import *
436
+
437
+ with open('binary', 'rb') as f:
438
+ code = f.read()
439
+
440
+ # RISC-V 64-bit with compressed instruction support
441
+ md = Cs(CS_ARCH_RISCV, CS_MODE_RISCVC | CS_MODE_RISCV64)
442
+ md.detail = True
443
+
444
+ # Disassemble from entry point (check ELF header for e_entry)
445
+ TEXT_OFFSET = 0x10000 # typical for static RISC-V
446
+ for insn in md.disasm(code[TEXT_OFFSET:], TEXT_OFFSET):
447
+ print(f"0x{insn.address:x}:\t{insn.mnemonic}\t{insn.op_str}")
448
+ ```
449
+
450
+ **Common RISC-V patterns:**
451
+ - `li a0, N` → load immediate (argument setup)
452
+ - `mv a0, s0` → register move
453
+ - `call offset` → function call (auipc + jalr pair)
454
+ - `beq/bne a0, zero, label` → conditional branch
455
+ - `sd/ld` → 64-bit store/load
456
+ - `addiw` → 32-bit add (W-suffix = word operations)
457
+
458
+ **Key differences from x86:**
459
+ - No flags register — comparisons are inline with branch instructions
460
+ - Arguments in a0-a7 (not rdi/rsi/rdx)
461
+ - Return value in a0
462
+ - Saved registers s0-s11 (callee-saved)
463
+ - Compressed instructions (2 bytes) mixed with standard (4 bytes) — use `CS_MODE_RISCVC`
464
+
465
+ **Anti-RE tricks in RISC-V:**
466
+ - Fake flags as string constants (check for `"n0t_th3_r34l"` patterns)
467
+ - Timing anti-brute-force (rdtime instruction)
468
+ - XOR decryption with incremental key: `decrypted[i] = enc[i] ^ (key & 0xFF) ^ 0xA5; key += 7`
469
+
470
+ **Emulation:** `qemu-riscv64 -L /usr/riscv64-linux-gnu/ ./binary` (needs cross-toolchain sysroot)
471
+
472
+ ---
473
+
474
+ ## Binary Ninja
475
+
476
+ Interactive disassembler/decompiler with rapid community growth.
477
+
478
+ **Decompilation outputs:** High-Level Intermediate Language (HLIL), pseudo-C, pseudo-Rust, pseudo-Python.
479
+
480
+ ```bash
481
+ # Open binary
482
+ binaryninja binary
483
+ ```
484
+
485
+ ```python
486
+ # Headless analysis (Python API)
487
+ import binaryninja
488
+ bv = binaryninja.open_view("binary")
489
+ for func in bv.functions:
490
+ print(func.name, hex(func.start))
491
+ print(func.hlil) # High-Level IL
492
+ ```
493
+
494
+ **Community plugins:** Available via Plugin Manager (Ctrl+Shift+P → "Plugin Manager").
495
+
496
+ **Free version:** https://binary.ninja/free/ (cloud-based, limited features).
497
+
498
+ **Advantages over Ghidra:** Faster startup, cleaner IL representations, better Python API for scripting.
499
+
500
+ ---
501
+
502
+ ## Decompiler Comparison with dogbolt.org
503
+
504
+ **dogbolt.org** runs multiple decompilers simultaneously on the same binary and shows results side-by-side.
505
+
506
+ **Supported decompilers:** Hex-Rays (IDA), Ghidra, Binary Ninja, angr, RetDec, Snowman, dewolf, Reko, Relyze.
507
+
508
+ **When to use:**
509
+ - Decompiler output is confusing — compare with alternatives for clarity
510
+ - One decompiler mishandles a construct — another may get it right
511
+ - Quick triage without installing every tool locally
512
+ - Validate decompiler correctness by cross-referencing outputs
513
+
514
+ ```bash
515
+ # Upload via web interface: https://dogbolt.org/
516
+ # Or use the API:
517
+ curl -F "file=@binary" https://dogbolt.org/api/binaries/
518
+ ```
519
+
520
+ **Key insight:** Different decompilers excel at different constructs. When one produces unreadable output, another often generates clearer pseudocode. Cross-referencing catches decompiler bugs.
521
+
522
+ ---
523
+
524
+ ## Useful Commands
525
+
526
+ ```bash
527
+ # File info
528
+ file binary
529
+ checksec --file=binary
530
+ rabin2 -I binary
531
+
532
+ # String extraction
533
+ strings binary | grep -iE "flag|secret"
534
+ rabin2 -z binary
535
+
536
+ # Sections
537
+ readelf -S binary
538
+ objdump -h binary
539
+
540
+ # Symbols
541
+ nm binary
542
+ readelf -s binary
543
+
544
+ # Disassembly
545
+ objdump -d binary
546
+ objdump -M intel -d binary
547
+ ```
548
+
549
+ ---
550
+
551
+ ## boolector SMT2 for Custom Hash Reversal (OTW Advent 2018)
552
+
553
+ **Pattern:** Custom hash functions built from bit operations fall to SMT solvers. boolector's QF_BV (bitvector) logic is noticeably faster than Z3 for such instances. Translate the hash into SMT2 directly, assert the output, and solve for the input.
554
+
555
+ ```smt
556
+ (set-logic QF_BV)
557
+ (declare-fun input () (_ BitVec 64))
558
+ (assert (bvuge input #x0000000020202020)) ; printable lower bound
559
+ (assert (bvule input #x000000007e7e7e7e)) ; printable upper bound
560
+
561
+ ; Emit the hash function as bvxor/bvrol/bvadd chains
562
+ (define-fun hash ((x (_ BitVec 64))) (_ BitVec 64) ...)
563
+ (assert (= (hash input) #xdeadbeefcafef00d))
564
+ (check-sat) (get-model)
565
+ ```
566
+
567
+ ```bash
568
+ boolector -m --output-format=smt2 hash.smt2
569
+ ```
570
+
571
+ **Key insight:** Z3 is the default, but for bit-level hash puzzles boolector is often 10-100× faster. Emit SMT2 from IDA/r2 by lifting each basic block into `bvxor`/`bvrol`/`bvadd` and let the solver pick the preimage.
572
+
573
+ **References:** OverTheWire Advent 2018 — Jackinthebox, writeup 12789