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.
- package/AGENTS.md +131 -0
- package/Dockerfile +192 -0
- package/README.md +522 -0
- package/agents/ctf-analyzer.md +58 -0
- package/agents/ctf-controller.md +151 -0
- package/agents/ctf-speedrun.md +74 -0
- package/bin/ctf-agent.js +119 -0
- package/docker-compose.yml +13 -0
- package/mcp_config.json +19 -0
- package/package.json +44 -0
- package/references/ctf-triage-ladder.md +68 -0
- package/references/exploit-databases.md +575 -0
- package/references/llm-safety-and-policy-compliance.md +173 -0
- package/references/multi-agent-orchestration-and-policy-routing.md +278 -0
- package/references/security-events-and-intelligence.md +566 -0
- package/references/version-matrix.md +59 -0
- package/rules/ctf-execution-rules.md +44 -0
- package/rules/ctf-safety-framing-rules.md +140 -0
- package/rules/flag-validation-rules.md +25 -0
- package/scripts/__init__.py +1 -0
- package/scripts/ctf-tools.lock +205 -0
- package/scripts/ctf_init.py +1026 -0
- package/scripts/ctf_update.py +583 -0
- package/scripts/ctfd_client.py +81 -0
- package/scripts/cve_lookup.py +453 -0
- package/scripts/extract_flags.py +155 -0
- package/scripts/install_as_agent.py +278 -0
- package/scripts/install_ctf_tools.sh +603 -0
- package/scripts/parallel_triage.py +395 -0
- package/scripts/prompt_policy_sanitizer.py +283 -0
- package/scripts/scope_guard.py +444 -0
- package/scripts/skill_validator.py +504 -0
- package/scripts/workspace_cleaner.py +141 -0
- package/skills/ctf-ai-ml/SKILL.md +120 -0
- package/skills/ctf-ai-ml/adversarial-ml.md +623 -0
- package/skills/ctf-ai-ml/llm-attacks.md +487 -0
- package/skills/ctf-ai-ml/model-attacks.md +422 -0
- package/skills/ctf-crypto/SKILL.md +320 -0
- package/skills/ctf-crypto/advanced-math.md +798 -0
- package/skills/ctf-crypto/classic-ciphers.md +651 -0
- package/skills/ctf-crypto/ecc-attacks.md +347 -0
- package/skills/ctf-crypto/exotic-crypto-2.md +380 -0
- package/skills/ctf-crypto/exotic-crypto.md +528 -0
- package/skills/ctf-crypto/historical.md +113 -0
- package/skills/ctf-crypto/lattice-and-lwe.md +524 -0
- package/skills/ctf-crypto/modern-ciphers-2.md +563 -0
- package/skills/ctf-crypto/modern-ciphers-3.md +453 -0
- package/skills/ctf-crypto/modern-ciphers.md +649 -0
- package/skills/ctf-crypto/prng-attacks.md +257 -0
- package/skills/ctf-crypto/prng.md +664 -0
- package/skills/ctf-crypto/rsa-attacks-2.md +792 -0
- package/skills/ctf-crypto/rsa-attacks.md +487 -0
- package/skills/ctf-crypto/stream-ciphers.md +390 -0
- package/skills/ctf-crypto/zkp-and-advanced.md +456 -0
- package/skills/ctf-forensics/3d-printing.md +121 -0
- package/skills/ctf-forensics/SKILL.md +379 -0
- package/skills/ctf-forensics/disk-advanced.md +497 -0
- package/skills/ctf-forensics/disk-and-memory.md +491 -0
- package/skills/ctf-forensics/disk-recovery.md +699 -0
- package/skills/ctf-forensics/linux-forensics.md +511 -0
- package/skills/ctf-forensics/network-advanced.md +583 -0
- package/skills/ctf-forensics/network.md +645 -0
- package/skills/ctf-forensics/peripheral-capture.md +287 -0
- package/skills/ctf-forensics/signals-and-hardware.md +713 -0
- package/skills/ctf-forensics/steganography.md +694 -0
- package/skills/ctf-forensics/stego-advanced-2.md +475 -0
- package/skills/ctf-forensics/stego-advanced.md +481 -0
- package/skills/ctf-forensics/stego-image.md +691 -0
- package/skills/ctf-forensics/windows.md +625 -0
- package/skills/ctf-malware/SKILL.md +181 -0
- package/skills/ctf-malware/c2-and-protocols.md +274 -0
- package/skills/ctf-malware/pe-and-dotnet.md +108 -0
- package/skills/ctf-malware/scripts-and-obfuscation.md +449 -0
- package/skills/ctf-misc/SKILL.md +498 -0
- package/skills/ctf-misc/bashjails.md +323 -0
- package/skills/ctf-misc/ctfd-navigation.md +465 -0
- package/skills/ctf-misc/dns.md +255 -0
- package/skills/ctf-misc/encodings-advanced.md +504 -0
- package/skills/ctf-misc/encodings.md +431 -0
- package/skills/ctf-misc/games-and-vms-2.md +254 -0
- package/skills/ctf-misc/games-and-vms-3.md +690 -0
- package/skills/ctf-misc/games-and-vms-4.md +229 -0
- package/skills/ctf-misc/games-and-vms.md +529 -0
- package/skills/ctf-misc/linux-privesc.md +333 -0
- package/skills/ctf-misc/pyjails.md +671 -0
- package/skills/ctf-misc/rf-sdr.md +91 -0
- package/skills/ctf-osint/SKILL.md +198 -0
- package/skills/ctf-osint/geolocation-and-media.md +464 -0
- package/skills/ctf-osint/social-media.md +312 -0
- package/skills/ctf-osint/web-and-dns.md +341 -0
- package/skills/ctf-pwn/SKILL.md +214 -0
- package/skills/ctf-pwn/advanced-exploits-2.md +579 -0
- package/skills/ctf-pwn/advanced-exploits-3.md +598 -0
- package/skills/ctf-pwn/advanced-exploits-4.md +590 -0
- package/skills/ctf-pwn/advanced-exploits-5.md +119 -0
- package/skills/ctf-pwn/advanced-exploits.md +773 -0
- package/skills/ctf-pwn/advanced.md +326 -0
- package/skills/ctf-pwn/field-notes.md +245 -0
- package/skills/ctf-pwn/format-string.md +694 -0
- package/skills/ctf-pwn/heap-fsop.md +285 -0
- package/skills/ctf-pwn/heap-techniques-2.md +333 -0
- package/skills/ctf-pwn/heap-techniques.md +513 -0
- package/skills/ctf-pwn/kernel-bypass.md +421 -0
- package/skills/ctf-pwn/kernel-techniques.md +366 -0
- package/skills/ctf-pwn/kernel.md +636 -0
- package/skills/ctf-pwn/overflow-basics.md +611 -0
- package/skills/ctf-pwn/rop-advanced.md +725 -0
- package/skills/ctf-pwn/rop-and-shellcode.md +659 -0
- package/skills/ctf-pwn/sandbox-escape.md +313 -0
- package/skills/ctf-reverse/SKILL.md +163 -0
- package/skills/ctf-reverse/anti-analysis-ctf.md +204 -0
- package/skills/ctf-reverse/anti-analysis.md +693 -0
- package/skills/ctf-reverse/field-notes.md +376 -0
- package/skills/ctf-reverse/languages-compiled.md +666 -0
- package/skills/ctf-reverse/languages-platforms.md +592 -0
- package/skills/ctf-reverse/languages.md +553 -0
- package/skills/ctf-reverse/patterns-ctf-2.md +397 -0
- package/skills/ctf-reverse/patterns-ctf-3.md +797 -0
- package/skills/ctf-reverse/patterns-ctf.md +670 -0
- package/skills/ctf-reverse/patterns-runtime.md +274 -0
- package/skills/ctf-reverse/patterns.md +572 -0
- package/skills/ctf-reverse/platforms-hardware.md +387 -0
- package/skills/ctf-reverse/platforms.md +664 -0
- package/skills/ctf-reverse/tools-advanced-2.md +421 -0
- package/skills/ctf-reverse/tools-advanced.md +407 -0
- package/skills/ctf-reverse/tools-dynamic.md +679 -0
- package/skills/ctf-reverse/tools-emulation.md +319 -0
- package/skills/ctf-reverse/tools.md +573 -0
- package/skills/ctf-web/SKILL.md +153 -0
- package/skills/ctf-web/auth-and-access-2.md +82 -0
- package/skills/ctf-web/auth-and-access.md +783 -0
- package/skills/ctf-web/auth-infra.md +321 -0
- package/skills/ctf-web/auth-jwt.md +186 -0
- package/skills/ctf-web/client-side-advanced.md +739 -0
- package/skills/ctf-web/client-side.md +529 -0
- package/skills/ctf-web/cves.md +373 -0
- package/skills/ctf-web/field-notes.md +482 -0
- package/skills/ctf-web/node-and-prototype.md +200 -0
- package/skills/ctf-web/server-side-2.md +337 -0
- package/skills/ctf-web/server-side-advanced-2.md +559 -0
- package/skills/ctf-web/server-side-advanced-3.md +125 -0
- package/skills/ctf-web/server-side-advanced-4.md +480 -0
- package/skills/ctf-web/server-side-advanced.md +378 -0
- package/skills/ctf-web/server-side-deser.md +443 -0
- package/skills/ctf-web/server-side-exec-2.md +799 -0
- package/skills/ctf-web/server-side-exec.md +457 -0
- package/skills/ctf-web/server-side.md +629 -0
- package/skills/ctf-web/sql-injection.md +790 -0
- package/skills/ctf-web/web3.md +374 -0
- package/skills/ctf-writeup/SKILL.md +90 -0
- package/skills/solve-challenge/SKILL.md +269 -0
- package/skills.json +16 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
# CTF Reverse - Advanced Tools & Deobfuscation
|
|
2
|
+
|
|
3
|
+
Advanced tooling for commercial packers/protectors, binary diffing, deobfuscation frameworks, emulation, and symbolic execution beyond angr.
|
|
4
|
+
|
|
5
|
+
For advanced GDB scripting, Ghidra automation, patching frameworks, and GDB-driven CTF techniques, see [tools-advanced-2.md](tools-advanced-2.md).
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
- [VMProtect Analysis](#vmprotect-analysis)
|
|
9
|
+
- [Recognition](#recognition)
|
|
10
|
+
- [Approach](#approach)
|
|
11
|
+
- [Tools](#tools)
|
|
12
|
+
- [CTF Strategy](#ctf-strategy)
|
|
13
|
+
- [Themida / WinLicense Analysis](#themida--winlicense-analysis)
|
|
14
|
+
- [Themida Recognition](#themida-recognition)
|
|
15
|
+
- [Approach for CTF](#approach-for-ctf)
|
|
16
|
+
- [Binary Diffing](#binary-diffing)
|
|
17
|
+
- [BinDiff](#bindiff)
|
|
18
|
+
- [Diaphora](#diaphora)
|
|
19
|
+
- [Deobfuscation Frameworks](#deobfuscation-frameworks)
|
|
20
|
+
- [D-810 (IDA)](#d-810-ida)
|
|
21
|
+
- [GOOMBA (Ghidra)](#goomba-ghidra)
|
|
22
|
+
- [Miasm](#miasm)
|
|
23
|
+
- [Qiling Framework (Emulation)](#qiling-framework-emulation)
|
|
24
|
+
- [Triton (Dynamic Symbolic Execution)](#triton-dynamic-symbolic-execution)
|
|
25
|
+
- [Manticore (Symbolic Execution)](#manticore-symbolic-execution)
|
|
26
|
+
- [Rizin / Cutter](#rizin--cutter)
|
|
27
|
+
- [RetDec (Retargetable Decompiler)](#retdec-retargetable-decompiler)
|
|
28
|
+
- [Custom VM Bytecode Lifting to LLVM IR (Google CTF 2017)](#custom-vm-bytecode-lifting-to-llvm-ir-google-ctf-2017)
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## VMProtect Analysis
|
|
33
|
+
|
|
34
|
+
VMProtect virtualizes x86/x64 code into custom bytecode interpreted by a generated VM. One of the most challenging protectors in CTF.
|
|
35
|
+
|
|
36
|
+
### Recognition
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# VMProtect signatures
|
|
40
|
+
strings binary | grep -i "vmp\|vmprotect"
|
|
41
|
+
# PE sections: .vmp0, .vmp1 (VMProtect adds its own sections)
|
|
42
|
+
readelf -S binary | grep ".vmp"
|
|
43
|
+
# Large binary with entropy > 7.5 in certain sections
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Key indicators:**
|
|
47
|
+
- `push` / `pop` heavy prologues (VM entry pushes all registers to stack)
|
|
48
|
+
- Large switch-case dispatcher (the VM handler loop)
|
|
49
|
+
- Anti-debug checks embedded in VM handlers
|
|
50
|
+
- Mutation engine: same opcode has different handlers per build
|
|
51
|
+
|
|
52
|
+
### Approach
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
1. Identify VM entry points — look for pushad/pushaq-like sequences
|
|
56
|
+
2. Find the handler table — large indirect jump (jmp [reg + offset])
|
|
57
|
+
3. Trace handler execution — each handler ends with jump to next
|
|
58
|
+
4. Identify handlers:
|
|
59
|
+
- vAdd, vSub, vMul, vXor, vNot (arithmetic)
|
|
60
|
+
- vPush, vPop (stack operations)
|
|
61
|
+
- vLoad, vStore (memory access)
|
|
62
|
+
- vJmp, vJcc (control flow)
|
|
63
|
+
- vRet (VM exit — restores real registers)
|
|
64
|
+
5. Build disassembler for VM bytecode
|
|
65
|
+
6. Simplify / deobfuscate the lifted IL
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Tools
|
|
69
|
+
|
|
70
|
+
- **VMPAttack** (IDA plugin): Automatically identifies VM handlers
|
|
71
|
+
- **NoVmp**: Devirtualization via VTIL (open-source)
|
|
72
|
+
- **VMProtect devirtualizer scripts**: Community IDA/Binary Ninja scripts
|
|
73
|
+
- **Approach for CTF:** Often easier to trace specific operations (crypto, comparisons) than fully devirtualize
|
|
74
|
+
|
|
75
|
+
### CTF Strategy
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
# Trace VM execution dynamically to extract operations on flag
|
|
79
|
+
# Hook VM handler dispatch to log opcode + operands
|
|
80
|
+
|
|
81
|
+
import frida
|
|
82
|
+
|
|
83
|
+
script = """
|
|
84
|
+
var vm_dispatch = ptr('0x...'); // Address of handler table jump
|
|
85
|
+
Interceptor.attach(vm_dispatch, {
|
|
86
|
+
onEnter(args) {
|
|
87
|
+
// Log handler index and stack state
|
|
88
|
+
var handler_idx = this.context.rax; // or whichever register
|
|
89
|
+
console.log('Handler:', handler_idx, 'RSP:', this.context.rsp);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
"""
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Key insight:** Full devirtualization is rarely needed for CTF. Focus on tracing what operations are performed on your input. Hook comparison/crypto functions called from within the VM.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Themida / WinLicense Analysis
|
|
100
|
+
|
|
101
|
+
Similar to VMProtect but with additional anti-debug layers.
|
|
102
|
+
|
|
103
|
+
### Themida Recognition
|
|
104
|
+
- Sections: `.themida`, `.winlice`
|
|
105
|
+
- Extremely heavy anti-debug (kernel-level checks, driver installation)
|
|
106
|
+
- Code mutation + virtualization + packing combined
|
|
107
|
+
|
|
108
|
+
### Approach for CTF
|
|
109
|
+
1. **Dump unpacked code:** Let it run, dump process memory after unpacking
|
|
110
|
+
2. **Bypass anti-debug:** ScyllaHide in x64dbg with Themida-specific preset
|
|
111
|
+
3. **Fix imports:** Use Scylla plugin for IAT reconstruction
|
|
112
|
+
4. **Focus on dumped code:** Once unpacked, analyze as normal binary
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# x64dbg workflow for Themida:
|
|
116
|
+
1. Load binary
|
|
117
|
+
2. Enable ScyllaHide → Profile: Themida
|
|
118
|
+
3. Run to OEP (Original Entry Point) — may need several attempts
|
|
119
|
+
4. Dump with Scylla: OEP → IAT Autosearch → Get Imports → Dump
|
|
120
|
+
5. Fix dump: Scylla → Fix Dump
|
|
121
|
+
6. Analyze fixed dump in Ghidra/IDA
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Binary Diffing
|
|
127
|
+
|
|
128
|
+
Critical for patch analysis, 1-day exploit development, and CTF challenges that provide two versions of a binary.
|
|
129
|
+
|
|
130
|
+
### BinDiff
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Export from IDA/Ghidra first, then diff
|
|
134
|
+
# IDA: File → BinExport → Export as BinExport2
|
|
135
|
+
# Ghidra: Use BinExport plugin
|
|
136
|
+
|
|
137
|
+
# Command line diffing
|
|
138
|
+
bindiff primary.BinExport secondary.BinExport
|
|
139
|
+
# Opens in BinDiff GUI — shows matched/unmatched functions
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Key metrics:**
|
|
143
|
+
- Similarity score (0.0-1.0) per function pair
|
|
144
|
+
- Changed instructions highlighted
|
|
145
|
+
- Unmatched functions = new/removed code
|
|
146
|
+
|
|
147
|
+
### Diaphora
|
|
148
|
+
|
|
149
|
+
Free, open-source alternative to BinDiff, runs as IDA plugin.
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# In IDA:
|
|
153
|
+
# File → Script file → diaphora.py
|
|
154
|
+
# Export first binary, then open second and diff
|
|
155
|
+
|
|
156
|
+
# Ghidra version: diaphora_ghidra.py
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Useful for CTF:** When challenge provides "patched" and "original" binaries, diff reveals the vulnerability or hidden functionality.
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Deobfuscation Frameworks
|
|
164
|
+
|
|
165
|
+
### D-810 (IDA)
|
|
166
|
+
|
|
167
|
+
Pattern-based deobfuscation plugin for IDA Pro. Excellent for OLLVM-obfuscated binaries.
|
|
168
|
+
|
|
169
|
+
```text
|
|
170
|
+
Capabilities:
|
|
171
|
+
- MBA simplification: (a ^ b) + 2*(a & b) → a + b
|
|
172
|
+
- Dead code elimination
|
|
173
|
+
- Opaque predicate removal
|
|
174
|
+
- Constant folding
|
|
175
|
+
- Control flow unflattening (partial)
|
|
176
|
+
|
|
177
|
+
Installation: Copy to IDA plugins directory
|
|
178
|
+
Usage: Edit → Plugins → D-810 → Select rules → Apply
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### GOOMBA (Ghidra)
|
|
182
|
+
|
|
183
|
+
```text
|
|
184
|
+
GOOMBA (Ghidra-based Obfuscated Object Matching and Bytes Analysis):
|
|
185
|
+
- Integrates with Ghidra's P-Code
|
|
186
|
+
- Simplifies MBA expressions
|
|
187
|
+
- Pattern matching for known obfuscation
|
|
188
|
+
|
|
189
|
+
Installation: Copy .jar to Ghidra extensions
|
|
190
|
+
Usage: Code Browser → Analysis → GOOMBA
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Miasm
|
|
194
|
+
|
|
195
|
+
Powerful reverse engineering framework with symbolic execution and IR lifting.
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
from miasm.analysis.binary import Container
|
|
199
|
+
from miasm.analysis.machine import Machine
|
|
200
|
+
from miasm.expression.expression import *
|
|
201
|
+
|
|
202
|
+
# Load binary and lift to Miasm IR
|
|
203
|
+
cont = Container.from_stream(open("binary", "rb"))
|
|
204
|
+
machine = Machine(cont.arch)
|
|
205
|
+
mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
|
|
206
|
+
|
|
207
|
+
# Disassemble function
|
|
208
|
+
asmcfg = mdis.dis_multiblock(entry_addr)
|
|
209
|
+
|
|
210
|
+
# Lift to IR
|
|
211
|
+
lifter = machine.lifter_model_call(loc_db=cont.loc_db)
|
|
212
|
+
ircfg = lifter.new_ircfg_from_asmcfg(asmcfg)
|
|
213
|
+
|
|
214
|
+
# Symbolic execution
|
|
215
|
+
from miasm.ir.symbexec import SymbolicExecutionEngine
|
|
216
|
+
sb = SymbolicExecutionEngine(lifter)
|
|
217
|
+
# Execute symbolically, then simplify expressions
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
**Use case:** Deobfuscate expression trees, simplify complex arithmetic, trace data flow through obfuscated code.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Qiling Framework (Emulation)
|
|
225
|
+
|
|
226
|
+
Cross-platform emulation framework built on Unicorn, with OS-level support (syscalls, filesystem, registry).
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from qiling import Qiling
|
|
230
|
+
from qiling.const import QL_VERBOSE
|
|
231
|
+
|
|
232
|
+
# Emulate Linux ELF
|
|
233
|
+
ql = Qiling(["./binary"], "rootfs/x8664_linux",
|
|
234
|
+
verbose=QL_VERBOSE.DEBUG)
|
|
235
|
+
|
|
236
|
+
# Hook specific address
|
|
237
|
+
@ql.hook_address
|
|
238
|
+
def hook_check(ql, address, size):
|
|
239
|
+
if address == 0x401234:
|
|
240
|
+
ql.arch.regs.rax = 0 # Bypass check
|
|
241
|
+
ql.log.info("Anti-debug bypassed")
|
|
242
|
+
|
|
243
|
+
# Hook syscall
|
|
244
|
+
@ql.hook_syscall(name="ptrace")
|
|
245
|
+
def hook_ptrace(ql, request, pid, addr, data):
|
|
246
|
+
return 0 # Always succeed
|
|
247
|
+
|
|
248
|
+
# Hook API (Windows)
|
|
249
|
+
@ql.set_api("IsDebuggerPresent", target=ql.os.user_defined_api)
|
|
250
|
+
def hook_isdebug(ql, address, params):
|
|
251
|
+
return 0
|
|
252
|
+
|
|
253
|
+
ql.run()
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Advantages over Unicorn:**
|
|
257
|
+
- OS emulation (file I/O, network, registry)
|
|
258
|
+
- Multi-platform (Linux, Windows, macOS, Android, UEFI)
|
|
259
|
+
- Built-in debugger interface
|
|
260
|
+
- Rootfs for library loading
|
|
261
|
+
|
|
262
|
+
**CTF use cases:**
|
|
263
|
+
- Emulate binaries for foreign architectures (ARM, MIPS, RISC-V)
|
|
264
|
+
- Bypass all anti-debug at once (no debugger artifacts)
|
|
265
|
+
- Fuzz embedded/IoT firmware without hardware
|
|
266
|
+
- Trace execution without code modification
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Triton (Dynamic Symbolic Execution)
|
|
271
|
+
|
|
272
|
+
Pin-based dynamic binary analysis framework with symbolic execution, taint analysis, and AST simplification.
|
|
273
|
+
|
|
274
|
+
```python
|
|
275
|
+
from triton import *
|
|
276
|
+
|
|
277
|
+
ctx = TritonContext(ARCH.X86_64)
|
|
278
|
+
|
|
279
|
+
# Load binary sections
|
|
280
|
+
with open("binary", "rb") as f:
|
|
281
|
+
binary = f.read()
|
|
282
|
+
ctx.setConcreteMemoryAreaValue(0x400000, binary)
|
|
283
|
+
|
|
284
|
+
# Symbolize input
|
|
285
|
+
for i in range(32):
|
|
286
|
+
ctx.symbolizeMemory(MemoryAccess(INPUT_ADDR + i, CPUSIZE.BYTE), f"input_{i}")
|
|
287
|
+
|
|
288
|
+
# Emulate instructions
|
|
289
|
+
pc = ENTRY_POINT
|
|
290
|
+
while pc:
|
|
291
|
+
inst = Instruction(pc, ctx.getConcreteMemoryAreaValue(pc, 16))
|
|
292
|
+
ctx.processing(inst)
|
|
293
|
+
|
|
294
|
+
# At comparison point, extract path constraint
|
|
295
|
+
if pc == CMP_ADDR:
|
|
296
|
+
ast = ctx.getPathConstraintsAst()
|
|
297
|
+
model = ctx.getModel(ast)
|
|
298
|
+
for k, v in sorted(model.items()):
|
|
299
|
+
print(f"input[{k}] = {chr(v.getValue())}", end="")
|
|
300
|
+
break
|
|
301
|
+
|
|
302
|
+
pc = ctx.getConcreteRegisterValue(ctx.registers.rip)
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
**Triton vs angr:**
|
|
306
|
+
| Feature | Triton | angr |
|
|
307
|
+
|---|---|---|
|
|
308
|
+
| Execution | Concrete + symbolic (DSE) | Fully symbolic |
|
|
309
|
+
| Speed | Faster (concrete-driven) | Slower (explores all paths) |
|
|
310
|
+
| Path explosion | Less prone (follows one path) | Major issue |
|
|
311
|
+
| API | C++ / Python | Python |
|
|
312
|
+
| Best for | Single-path deobfuscation, taint tracking | Multi-path exploration |
|
|
313
|
+
|
|
314
|
+
**Key use:** Triton excels at deobfuscation — run the program concretely, but track symbolic state, then simplify the collected constraints.
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## Manticore (Symbolic Execution)
|
|
319
|
+
|
|
320
|
+
Trail of Bits' symbolic execution tool. Similar to angr but with native EVM (Ethereum) support.
|
|
321
|
+
|
|
322
|
+
```python
|
|
323
|
+
from manticore.native import Manticore
|
|
324
|
+
|
|
325
|
+
m = Manticore("./binary")
|
|
326
|
+
|
|
327
|
+
# Hook success/failure
|
|
328
|
+
@m.hook(0x401234)
|
|
329
|
+
def success(state):
|
|
330
|
+
buf = state.solve_one_n_batched(state.input_symbols, 32)
|
|
331
|
+
print("Flag:", bytes(buf))
|
|
332
|
+
m.kill()
|
|
333
|
+
|
|
334
|
+
@m.hook(0x401256)
|
|
335
|
+
def fail(state):
|
|
336
|
+
state.abandon()
|
|
337
|
+
|
|
338
|
+
m.run()
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
**Best for:** EVM/smart contract analysis, simpler Linux binaries. angr is generally more mature for complex RE tasks.
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## Rizin / Cutter
|
|
346
|
+
|
|
347
|
+
Rizin is the maintained fork of radare2. Cutter is its Qt-based GUI.
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
# Rizin CLI (r2-compatible commands)
|
|
351
|
+
rizin -d ./binary
|
|
352
|
+
> aaa # Analyze all
|
|
353
|
+
> afl # List functions
|
|
354
|
+
> pdf @ main # Print disassembly
|
|
355
|
+
> VV # Visual graph mode
|
|
356
|
+
|
|
357
|
+
# Cutter GUI
|
|
358
|
+
cutter binary # Open in GUI with decompiler
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Cutter advantages:**
|
|
362
|
+
- Built-in Ghidra decompiler (via r2ghidra plugin)
|
|
363
|
+
- Graph view, hex editor, debug panel in one GUI
|
|
364
|
+
- Integrated Python/JavaScript scripting console
|
|
365
|
+
- Free and open source
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## RetDec (Retargetable Decompiler)
|
|
370
|
+
|
|
371
|
+
LLVM-based decompiler supporting many architectures. Free and open-source.
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
# Install
|
|
375
|
+
pip install retdec-decompiler
|
|
376
|
+
# Or use web: https://retdec.com/decompilation/
|
|
377
|
+
|
|
378
|
+
# CLI
|
|
379
|
+
retdec-decompiler binary
|
|
380
|
+
# Outputs: binary.c (decompiled C), binary.dsm (disassembly)
|
|
381
|
+
|
|
382
|
+
# Specific function
|
|
383
|
+
retdec-decompiler --select-ranges 0x401000-0x401100 binary
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
**Strengths:** Multi-arch support (x86, ARM, MIPS, PowerPC, PIC32), free, produces compilable C. Good for architectures not well-supported by Ghidra.
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## Custom VM Bytecode Lifting to LLVM IR (Google CTF 2017)
|
|
391
|
+
|
|
392
|
+
For complex custom VMs, transpile the VM bytecode to LLVM IR and use LLVM's optimization passes to simplify the code, then decompile the optimized IR.
|
|
393
|
+
|
|
394
|
+
```python
|
|
395
|
+
# Pipeline: VM bytecode → custom disassembler → LLVM IR → optimize → decompile
|
|
396
|
+
# 1. Write disassembler for the custom VM opcodes
|
|
397
|
+
# 2. Emit LLVM IR for each opcode:
|
|
398
|
+
# INC reg → %reg = add i32 %reg, 1
|
|
399
|
+
# CDEC reg → conditional decrement
|
|
400
|
+
# CALL fn → call void @fn()
|
|
401
|
+
# 3. Use MCJIT or llc to optimize:
|
|
402
|
+
# opt -O3 -S vm_lifted.ll -o vm_optimized.ll
|
|
403
|
+
# 4. Load optimized IR in IDA or decompile with RetDec
|
|
404
|
+
# Result: 1300 lines → 150 lines after inlining + constant folding
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
**Key insight:** LLVM's optimization passes (inlining, constant folding, dead code elimination) dramatically simplify lifted VM bytecode. A custom VM with 26 registers and 3 opcodes that produces 1300 lines of IL reduces to ~150 lines after `-O3`, revealing the underlying algorithm (e.g., Collatz sequence computation).
|