ineedcodes 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/skills/401-403-bypass-techniques/SKILL.md +348 -0
- package/skills/active-directory-acl-abuse/BLOODHOUND_PATHS.md +281 -0
- package/skills/active-directory-acl-abuse/SKILL.md +295 -0
- package/skills/active-directory-certificate-services/ADCS_ESC_MATRIX.md +197 -0
- package/skills/active-directory-certificate-services/SKILL.md +303 -0
- package/skills/active-directory-kerberos-attacks/KERBEROS_ATTACK_CHAINS.md +226 -0
- package/skills/active-directory-kerberos-attacks/SKILL.md +311 -0
- package/skills/ai-ml-security/SKILL.md +425 -0
- package/skills/android-pentesting-tricks/FRIDA_SCRIPTS.md +394 -0
- package/skills/android-pentesting-tricks/SKILL.md +369 -0
- package/skills/anti-debugging-techniques/ANTI_DEBUG_MATRIX.md +117 -0
- package/skills/anti-debugging-techniques/SKILL.md +407 -0
- package/skills/api-auth-and-jwt-abuse/SKILL.md +76 -0
- package/skills/api-authorization-and-bola/SKILL.md +48 -0
- package/skills/api-recon-and-docs/SKILL.md +61 -0
- package/skills/api-sec/SKILL.md +49 -0
- package/skills/arbitrary-write-to-rce/SKILL.md +361 -0
- package/skills/auth-sec/SKILL.md +41 -0
- package/skills/authbypass-authentication-flaws/SKILL.md +441 -0
- package/skills/bba-ad-attacker/SKILL.md +420 -0
- package/skills/bba-api-security/SKILL.md +95 -0
- package/skills/bba-attack-planner/SKILL.md +186 -0
- package/skills/bba-binary-exploit/SKILL.md +65 -0
- package/skills/bba-bizlogic-hunter/SKILL.md +304 -0
- package/skills/bba-bug-bounty/SKILL.md +245 -0
- package/skills/bba-cicd-redteam/SKILL.md +515 -0
- package/skills/bba-cloud-security/SKILL.md +97 -0
- package/skills/bba-container-escape/SKILL.md +161 -0
- package/skills/bba-credential-tester/SKILL.md +346 -0
- package/skills/bba-crypto-analyst/SKILL.md +54 -0
- package/skills/bba-ctf-solver/SKILL.md +166 -0
- package/skills/bba-detection-engineer/SKILL.md +93 -0
- package/skills/bba-engagement-planner/SKILL.md +68 -0
- package/skills/bba-exploit-chainer/SKILL.md +280 -0
- package/skills/bba-exploit-guide/SKILL.md +96 -0
- package/skills/bba-forensics-analyst/SKILL.md +512 -0
- package/skills/bba-graphql-hunter/SKILL.md +145 -0
- package/skills/bba-hardware-hacker/SKILL.md +57 -0
- package/skills/bba-jwt-cracker/SKILL.md +133 -0
- package/skills/bba-llm-redteam/SKILL.md +149 -0
- package/skills/bba-malware-analyst/SKILL.md +305 -0
- package/skills/bba-mobile-pentester/SKILL.md +350 -0
- package/skills/bba-osint-collector/SKILL.md +645 -0
- package/skills/bba-payload-crafter/SKILL.md +347 -0
- package/skills/bba-phishing-operator/SKILL.md +516 -0
- package/skills/bba-poc-validator/SKILL.md +249 -0
- package/skills/bba-privesc-advisor/SKILL.md +98 -0
- package/skills/bba-purple-team/SKILL.md +56 -0
- package/skills/bba-recon-advisor/SKILL.md +215 -0
- package/skills/bba-red-team-operator/SKILL.md +61 -0
- package/skills/bba-report-generator/SKILL.md +145 -0
- package/skills/bba-reverse-engineer/SKILL.md +298 -0
- package/skills/bba-social-engineer/SKILL.md +341 -0
- package/skills/bba-ssrf-hunter/SKILL.md +120 -0
- package/skills/bba-stig-analyst/SKILL.md +108 -0
- package/skills/bba-subdomain-takeover/SKILL.md +141 -0
- package/skills/bba-swarm-orchestrator/SKILL.md +351 -0
- package/skills/bba-threat-modeler/SKILL.md +574 -0
- package/skills/bba-vuln-scanner/SKILL.md +305 -0
- package/skills/bba-web-hunter/SKILL.md +285 -0
- package/skills/bba-wireless-pentester/SKILL.md +539 -0
- package/skills/binary-protection-bypass/PROTECTION_BYPASS_MATRIX.md +168 -0
- package/skills/binary-protection-bypass/SKILL.md +295 -0
- package/skills/browser-exploitation-v8/SKILL.md +334 -0
- package/skills/browser-exploitation-v8/V8_EXPLOITATION_PATTERNS.md +288 -0
- package/skills/business-logic-vuln/SKILL.md +33 -0
- package/skills/business-logic-vulnerabilities/CHECKLIST.md +375 -0
- package/skills/business-logic-vulnerabilities/METHODOLOGY.md +337 -0
- package/skills/business-logic-vulnerabilities/SCENARIOS.md +1095 -0
- package/skills/business-logic-vulnerabilities/SKILL.md +711 -0
- package/skills/classical-cipher-analysis/SKILL.md +663 -0
- package/skills/clickjacking/SKILL.md +163 -0
- package/skills/cmdi-command-injection/SKILL.md +687 -0
- package/skills/code-obfuscation-deobfuscation/SKILL.md +391 -0
- package/skills/container-escape-techniques/DOCKER_ESCAPE_CHAINS.md +296 -0
- package/skills/container-escape-techniques/SKILL.md +339 -0
- package/skills/cors-cross-origin-misconfiguration/SCENARIOS.md +152 -0
- package/skills/cors-cross-origin-misconfiguration/SKILL.md +270 -0
- package/skills/crlf-injection/SKILL.md +179 -0
- package/skills/csp-bypass-advanced/SKILL.md +259 -0
- package/skills/csrf-cross-site-request-forgery/SKILL.md +526 -0
- package/skills/csv-formula-injection/SKILL.md +144 -0
- package/skills/dangling-markup-injection/SKILL.md +321 -0
- package/skills/defi-attack-patterns/SKILL.md +355 -0
- package/skills/dependency-confusion/SKILL.md +178 -0
- package/skills/deserialization-insecure/JAVA_GADGET_CHAINS.md +511 -0
- package/skills/deserialization-insecure/SKILL.md +725 -0
- package/skills/dns-rebinding-attacks/SKILL.md +337 -0
- package/skills/email-header-injection/SKILL.md +349 -0
- package/skills/expression-language-injection/SKILL.md +243 -0
- package/skills/file-access-vuln/SKILL.md +33 -0
- package/skills/format-string-exploitation/SKILL.md +312 -0
- package/skills/ghost-bits-cast-attack/PAYLOAD_COOKBOOK.md +448 -0
- package/skills/ghost-bits-cast-attack/SKILL.md +799 -0
- package/skills/graphql-and-hidden-parameters/SKILL.md +50 -0
- package/skills/hack/SKILL.md +162 -0
- package/skills/hash-attack-techniques/SKILL.md +491 -0
- package/skills/heap-exploitation/HOUSE_OF_TECHNIQUES.md +244 -0
- package/skills/heap-exploitation/IO_FILE_EXPLOITATION.md +256 -0
- package/skills/heap-exploitation/SKILL.md +217 -0
- package/skills/http-host-header-attacks/SKILL.md +323 -0
- package/skills/http-parameter-pollution/SKILL.md +208 -0
- package/skills/http2-specific-attacks/SKILL.md +350 -0
- package/skills/idor-broken-object-authorization/SKILL.md +336 -0
- package/skills/injection-checking/EXTRA_INJECTION_TYPES.md +450 -0
- package/skills/injection-checking/SKILL.md +50 -0
- package/skills/insecure-source-code-management/SKILL.md +161 -0
- package/skills/ios-pentesting-tricks/IOS_RUNTIME_TRICKS.md +411 -0
- package/skills/ios-pentesting-tricks/SKILL.md +418 -0
- package/skills/jndi-injection/SKILL.md +265 -0
- package/skills/jwt-oauth-token-attacks/SKILL.md +301 -0
- package/skills/kernel-exploitation/KERNEL_HEAP_TECHNIQUES.md +293 -0
- package/skills/kernel-exploitation/KERNEL_MITIGATION_BYPASS.md +224 -0
- package/skills/kernel-exploitation/SKILL.md +307 -0
- package/skills/kubernetes-pentesting/SKILL.md +348 -0
- package/skills/lattice-crypto-attacks/SKILL.md +497 -0
- package/skills/linux-lateral-movement/SKILL.md +348 -0
- package/skills/linux-privilege-escalation/KERNEL_EXPLOITS_CHECKLIST.md +260 -0
- package/skills/linux-privilege-escalation/SKILL.md +346 -0
- package/skills/linux-privilege-escalation/SUID_CAPABILITIES_TRICKS.md +305 -0
- package/skills/linux-security-bypass/SKILL.md +345 -0
- package/skills/llm-prompt-injection/JAILBREAK_PATTERNS.md +306 -0
- package/skills/llm-prompt-injection/SKILL.md +357 -0
- package/skills/macos-process-injection/DYLIB_XPC_TECHNIQUES.md +373 -0
- package/skills/macos-process-injection/SKILL.md +384 -0
- package/skills/macos-security-bypass/SKILL.md +337 -0
- package/skills/macos-security-bypass/TCC_BYPASS_MATRIX.md +200 -0
- package/skills/memory-forensics-volatility/SKILL.md +323 -0
- package/skills/memory-forensics-volatility/VOLATILITY_CHEATSHEET.md +225 -0
- package/skills/mobile-ssl-pinning-bypass/SKILL.md +531 -0
- package/skills/network-protocol-attacks/NAME_RESOLUTION_POISONING.md +226 -0
- package/skills/network-protocol-attacks/SKILL.md +330 -0
- package/skills/nosql-injection/SKILL.md +341 -0
- package/skills/ntlm-relay-coercion/COERCION_METHODS.md +253 -0
- package/skills/ntlm-relay-coercion/SKILL.md +267 -0
- package/skills/oauth-oidc-misconfiguration/SKILL.md +46 -0
- package/skills/open-redirect/SKILL.md +380 -0
- package/skills/path-traversal-lfi/SKILL.md +802 -0
- package/skills/prototype-pollution/SKILL.md +190 -0
- package/skills/prototype-pollution-advanced/KNOWN_GADGETS.md +253 -0
- package/skills/prototype-pollution-advanced/SKILL.md +338 -0
- package/skills/race-condition/SKILL.md +526 -0
- package/skills/recon-and-methodology/SKILL.md +389 -0
- package/skills/recon-for-sec/SKILL.md +29 -0
- package/skills/request-smuggling/H2_SMUGGLING_VARIANTS.md +498 -0
- package/skills/request-smuggling/SKILL.md +314 -0
- package/skills/reverse-shell-techniques/SHELL_CHEATSHEET.md +196 -0
- package/skills/reverse-shell-techniques/SKILL.md +290 -0
- package/skills/rsa-attack-techniques/RSA_ATTACK_CATALOG.md +432 -0
- package/skills/rsa-attack-techniques/SKILL.md +437 -0
- package/skills/saml-sso-assertion-attacks/SKILL.md +41 -0
- package/skills/sandbox-escape-techniques/PYTHON_SANDBOX_ESCAPE.md +349 -0
- package/skills/sandbox-escape-techniques/SECCOMP_BYPASS.md +332 -0
- package/skills/sandbox-escape-techniques/SKILL.md +250 -0
- package/skills/smart-contract-vulnerabilities/SKILL.md +314 -0
- package/skills/smart-contract-vulnerabilities/SOLIDITY_VULN_PATTERNS.md +460 -0
- package/skills/sqli-sql-injection/SCENARIOS.md +575 -0
- package/skills/sqli-sql-injection/SKILL.md +489 -0
- package/skills/sqli-sql-injection/SQLMAP_ADVANCED.md +642 -0
- package/skills/ssrf-server-side-request-forgery/SCENARIOS.md +226 -0
- package/skills/ssrf-server-side-request-forgery/SKILL.md +323 -0
- package/skills/ssrf-server-side-request-forgery/URL_PARSER_TRICKS.md +650 -0
- package/skills/ssti-server-side-template-injection/ENGINE_PAYLOADS.md +456 -0
- package/skills/ssti-server-side-template-injection/SCENARIOS.md +319 -0
- package/skills/ssti-server-side-template-injection/SKILL.md +344 -0
- package/skills/stack-overflow-and-rop/ROP_ADVANCED_TECHNIQUES.md +249 -0
- package/skills/stack-overflow-and-rop/SKILL.md +304 -0
- package/skills/steganography-techniques/SKILL.md +348 -0
- package/skills/steganography-techniques/STEGO_TOOLS_GUIDE.md +335 -0
- package/skills/subdomain-takeover/SKILL.md +247 -0
- package/skills/symbolic-execution-tools/ANGR_COOKBOOK.md +437 -0
- package/skills/symbolic-execution-tools/SKILL.md +419 -0
- package/skills/symmetric-cipher-attacks/BLOCK_CIPHER_ATTACKS.md +364 -0
- package/skills/symmetric-cipher-attacks/SKILL.md +462 -0
- package/skills/traffic-analysis-pcap/SKILL.md +341 -0
- package/skills/tunneling-and-pivoting/SKILL.md +343 -0
- package/skills/type-juggling/SKILL.md +291 -0
- package/skills/unauthorized-access-common-services/PORT_SERVICE_MATRIX.md +340 -0
- package/skills/unauthorized-access-common-services/SKILL.md +388 -0
- package/skills/upload-insecure-files/SCENARIOS.md +158 -0
- package/skills/upload-insecure-files/SKILL.md +543 -0
- package/skills/vm-and-bytecode-reverse/SKILL.md +450 -0
- package/skills/vr-cheatsheet-authentication_bypass/SKILL.md +184 -0
- package/skills/vr-cheatsheet-dangerous_functions/SKILL.md +200 -0
- package/skills/vr-cheatsheet-linux_commands/SKILL.md +40 -0
- package/skills/vr-cheatsheet-rce/SKILL.md +177 -0
- package/skills/vr-cheatsheet-reverse_engineering/SKILL.md +144 -0
- package/skills/vr-cheatsheet-sqli/SKILL.md +270 -0
- package/skills/vr-cheatsheet-ssrf/SKILL.md +173 -0
- package/skills/vr-cheatsheet-xss/SKILL.md +177 -0
- package/skills/vr-methodology-mindset_and_tips/SKILL.md +51 -0
- package/skills/vr-template-vulnerability_report_template/SKILL.md +59 -0
- package/skills/vr-writeup-CVE-2026-9136/SKILL.md +171 -0
- package/skills/vr-writeup-ZVE-2026-3795/SKILL.md +350 -0
- package/skills/vr-writeup-api_key_leak/SKILL.md +103 -0
- package/skills/waf-bypass-techniques/SKILL.md +290 -0
- package/skills/waf-bypass-techniques/WAF_PRODUCT_MATRIX.md +202 -0
- package/skills/web-cache-deception/CACHE_POISONING_TECHNIQUES.md +637 -0
- package/skills/web-cache-deception/SKILL.md +222 -0
- package/skills/websocket-security/SKILL.md +454 -0
- package/skills/windows-av-evasion/AMSI_BYPASS_TECHNIQUES.md +289 -0
- package/skills/windows-av-evasion/SKILL.md +342 -0
- package/skills/windows-lateral-movement/CREDENTIAL_DUMPING.md +308 -0
- package/skills/windows-lateral-movement/SKILL.md +335 -0
- package/skills/windows-privilege-escalation/SKILL.md +328 -0
- package/skills/windows-privilege-escalation/TOKEN_POTATO_TRICKS.md +216 -0
- package/skills/windows-privilege-escalation/UAC_BYPASS_METHODS.md +225 -0
- package/skills/xslt-injection/SKILL.md +281 -0
- package/skills/xss-cross-site-scripting/ADVANCED_XSS_TRICKS.md +276 -0
- package/skills/xss-cross-site-scripting/SCENARIOS.md +278 -0
- package/skills/xss-cross-site-scripting/SKILL.md +379 -0
- package/skills/xxe-xml-external-entity/SCENARIOS.md +112 -0
- package/skills/xxe-xml-external-entity/SKILL.md +554 -0
- package/src/agent.js +1 -1
- package/src/session.js +47 -11
- package/src/skills.js +30 -6
- package/src/ui.js +1 -1
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: symbolic-execution-tools
|
|
3
|
+
description: >-
|
|
4
|
+
Symbolic execution and constraint solving playbook. Use when solving CTF
|
|
5
|
+
reversing challenges, recovering keys, bypassing checks, or automating
|
|
6
|
+
binary analysis with angr, Z3, or Unicorn Engine.gated: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# SKILL: Symbolic Execution Tools — Expert Analysis Playbook
|
|
10
|
+
|
|
11
|
+
> **AI LOAD INSTRUCTION**: Expert symbolic execution techniques using angr, Z3, and Unicorn Engine. Covers CTF challenge automation, constraint solving patterns, function hooking, SimProcedure replacement, and emulation-based unpacking. Base models often produce broken angr scripts due to incorrect state initialization or missing hooks for libc functions.
|
|
12
|
+
|
|
13
|
+
## 0. RELATED ROUTING
|
|
14
|
+
|
|
15
|
+
- [anti-debugging-techniques](../anti-debugging-techniques/SKILL.md) when anti-debug checks need to be symbolically bypassed
|
|
16
|
+
- [code-obfuscation-deobfuscation](../code-obfuscation-deobfuscation/SKILL.md) when using symbolic execution for deobfuscation
|
|
17
|
+
- [vm-and-bytecode-reverse](../vm-and-bytecode-reverse/SKILL.md) when applying angr to custom VM challenges
|
|
18
|
+
|
|
19
|
+
### Advanced Reference
|
|
20
|
+
|
|
21
|
+
Also load [ANGR_COOKBOOK.md](./ANGR_COOKBOOK.md) when you need:
|
|
22
|
+
- 15+ ready-to-use angr script patterns for common CTF challenges
|
|
23
|
+
- Hook templates for scanf, printf, malloc, strcmp
|
|
24
|
+
- Symbolic file input, stdin, argv patterns
|
|
25
|
+
- Optimization tricks for path explosion management
|
|
26
|
+
|
|
27
|
+
### When to use which tool
|
|
28
|
+
|
|
29
|
+
| Scenario | Best Tool | Why |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| Pure math / equation system | Z3 | Direct constraint solving, no binary needed |
|
|
32
|
+
| Binary with control flow | angr | Explores paths, manages constraints automatically |
|
|
33
|
+
| Emulate specific code region | Unicorn | Fast, no symbolic overhead, good for unpacking |
|
|
34
|
+
| Complex binary + custom VM | angr + Unicorn (combo) | angr for control flow, Unicorn for VM handlers |
|
|
35
|
+
| Kernel / firmware code | Qiling | Full system emulation with OS awareness |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 1. ANGR — CORE CONCEPTS
|
|
40
|
+
|
|
41
|
+
### 1.1 Pipeline
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
Project(binary)
|
|
45
|
+
→ Factory.entry_state() / blank_state(addr=)
|
|
46
|
+
→ SimulationManager(state)
|
|
47
|
+
→ explore(find=target, avoid=bad)
|
|
48
|
+
→ found[0].solver.eval(symbolic_var)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 1.2 Essential Setup
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import angr
|
|
55
|
+
import claripy
|
|
56
|
+
|
|
57
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
58
|
+
|
|
59
|
+
# Entry state: start from program entry point
|
|
60
|
+
state = proj.factory.entry_state()
|
|
61
|
+
|
|
62
|
+
# Blank state: start from arbitrary address
|
|
63
|
+
state = proj.factory.blank_state(addr=0x401000)
|
|
64
|
+
|
|
65
|
+
# Full init state: with command-line args
|
|
66
|
+
state = proj.factory.full_init_state(args=['./challenge', arg1_sym])
|
|
67
|
+
|
|
68
|
+
simgr = proj.factory.simulation_manager(state)
|
|
69
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
70
|
+
|
|
71
|
+
if simgr.found:
|
|
72
|
+
found = simgr.found[0]
|
|
73
|
+
solution = found.solver.eval(symbolic_input, cast_to=bytes)
|
|
74
|
+
print(f"Solution: {solution}")
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 1.3 Symbolic Variables (claripy)
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
# Bitvector (fixed-size integer)
|
|
81
|
+
sym_input = claripy.BVS("input", 64) # 64-bit symbolic
|
|
82
|
+
sym_byte = claripy.BVS("byte", 8) # 8-bit symbolic
|
|
83
|
+
sym_buf = claripy.BVS("buffer", 8 * 32) # 32-byte buffer
|
|
84
|
+
|
|
85
|
+
# Concrete bitvector
|
|
86
|
+
concrete = claripy.BVV(0x41, 8) # concrete value 0x41
|
|
87
|
+
|
|
88
|
+
# Constraints
|
|
89
|
+
state.solver.add(sym_input > 0)
|
|
90
|
+
state.solver.add(sym_input < 100)
|
|
91
|
+
state.solver.add(sym_byte >= 0x20) # printable ASCII
|
|
92
|
+
state.solver.add(sym_byte <= 0x7e)
|
|
93
|
+
|
|
94
|
+
# Evaluate
|
|
95
|
+
value = state.solver.eval(sym_input)
|
|
96
|
+
all_values = state.solver.eval_upto(sym_input, 10) # up to 10 solutions
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 1.4 Symbolic stdin
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
flag_len = 32
|
|
103
|
+
sym_stdin = claripy.BVS("stdin", 8 * flag_len)
|
|
104
|
+
|
|
105
|
+
state = proj.factory.entry_state(stdin=sym_stdin)
|
|
106
|
+
|
|
107
|
+
# Constrain to printable ASCII
|
|
108
|
+
for i in range(flag_len):
|
|
109
|
+
byte = sym_stdin.get_byte(i)
|
|
110
|
+
state.solver.add(byte >= 0x20)
|
|
111
|
+
state.solver.add(byte <= 0x7e)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 1.5 Hooking Functions
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
# Hook by address (skip N bytes of original code)
|
|
118
|
+
@proj.hook(0x401100, length=5)
|
|
119
|
+
def skip_check(state):
|
|
120
|
+
state.regs.eax = 1 # force success
|
|
121
|
+
|
|
122
|
+
# SimProcedure: replace library function
|
|
123
|
+
class MyStrcmp(angr.SimProcedure):
|
|
124
|
+
def run(self, s1, s2):
|
|
125
|
+
return claripy.If(
|
|
126
|
+
self.state.memory.load(s1, 32) == self.state.memory.load(s2, 32),
|
|
127
|
+
claripy.BVV(0, 32),
|
|
128
|
+
claripy.BVV(1, 32)
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
proj.hook_symbol('strcmp', MyStrcmp())
|
|
132
|
+
|
|
133
|
+
# Hook common problematic functions
|
|
134
|
+
proj.hook_symbol('printf', angr.SIM_PROCEDURES['libc']['printf']())
|
|
135
|
+
proj.hook_symbol('scanf', angr.SIM_PROCEDURES['libc']['scanf']())
|
|
136
|
+
proj.hook_symbol('puts', angr.SIM_PROCEDURES['libc']['puts']())
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 1.6 Memory Operations
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
# Read memory (symbolic-aware)
|
|
143
|
+
data = state.memory.load(addr, size) # returns BV
|
|
144
|
+
data_concrete = state.solver.eval(data, cast_to=bytes)
|
|
145
|
+
|
|
146
|
+
# Write memory
|
|
147
|
+
state.memory.store(addr, claripy.BVV(0x41, 8))
|
|
148
|
+
state.memory.store(addr, sym_buf)
|
|
149
|
+
|
|
150
|
+
# Read/write registers
|
|
151
|
+
rax = state.regs.rax
|
|
152
|
+
state.regs.rdi = claripy.BVV(0x1000, 64)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 2. Z3 CONSTRAINT SOLVING
|
|
158
|
+
|
|
159
|
+
### 2.1 Core API
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from z3 import *
|
|
163
|
+
|
|
164
|
+
# Sorts
|
|
165
|
+
x = BitVec('x', 32) # 32-bit bitvector
|
|
166
|
+
y = Int('y') # arbitrary precision integer
|
|
167
|
+
b = Bool('b') # boolean
|
|
168
|
+
|
|
169
|
+
# Solver
|
|
170
|
+
s = Solver()
|
|
171
|
+
s.add(x + y == 42)
|
|
172
|
+
s.add(x > 0)
|
|
173
|
+
s.add(y > 0)
|
|
174
|
+
|
|
175
|
+
if s.check() == sat:
|
|
176
|
+
m = s.model()
|
|
177
|
+
print(f"x = {m[x]}, y = {m[y]}")
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 2.2 Common CTF Patterns
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
# Serial key validation: each char satisfies constraints
|
|
184
|
+
key = [BitVec(f'k{i}', 8) for i in range(16)]
|
|
185
|
+
s = Solver()
|
|
186
|
+
for k in key:
|
|
187
|
+
s.add(k >= 0x30, k <= 0x7a) # alphanumeric-ish
|
|
188
|
+
|
|
189
|
+
# XOR key recovery
|
|
190
|
+
plaintext = b"known_plaintext"
|
|
191
|
+
ciphertext = b"\x12\x34..."
|
|
192
|
+
key_byte = BitVec('key', 8)
|
|
193
|
+
s = Solver()
|
|
194
|
+
for p, c in zip(plaintext, ciphertext):
|
|
195
|
+
s.add(p ^ key_byte == c)
|
|
196
|
+
|
|
197
|
+
# System of linear equations (modular)
|
|
198
|
+
a, b, c = BitVecs('a b c', 32)
|
|
199
|
+
s = Solver()
|
|
200
|
+
s.add(3*a + 5*b + 7*c == 0x12345678)
|
|
201
|
+
s.add(2*a + 4*b + 6*c == 0xDEADBEEF)
|
|
202
|
+
s.add(a ^ b ^ c == 0xCAFEBABE)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 2.3 Optimization
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
from z3 import Optimize
|
|
209
|
+
|
|
210
|
+
opt = Optimize()
|
|
211
|
+
x = BitVec('x', 32)
|
|
212
|
+
opt.add(x > 0)
|
|
213
|
+
opt.add(x < 1000)
|
|
214
|
+
opt.minimize(x) # find smallest satisfying value
|
|
215
|
+
opt.check()
|
|
216
|
+
print(opt.model())
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## 3. UNICORN ENGINE — CODE EMULATION
|
|
222
|
+
|
|
223
|
+
### 3.1 Basic Setup
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
from unicorn import *
|
|
227
|
+
from unicorn.x86_const import *
|
|
228
|
+
from capstone import Cs, CS_ARCH_X86, CS_MODE_64
|
|
229
|
+
|
|
230
|
+
mu = Uc(UC_ARCH_X86, UC_MODE_64)
|
|
231
|
+
|
|
232
|
+
CODE_ADDR = 0x400000
|
|
233
|
+
STACK_ADDR = 0x7fff0000
|
|
234
|
+
STACK_SIZE = 0x10000
|
|
235
|
+
|
|
236
|
+
mu.mem_map(CODE_ADDR, 0x10000)
|
|
237
|
+
mu.mem_map(STACK_ADDR, STACK_SIZE)
|
|
238
|
+
|
|
239
|
+
mu.mem_write(CODE_ADDR, code_bytes)
|
|
240
|
+
mu.reg_write(UC_X86_REG_RSP, STACK_ADDR + STACK_SIZE - 0x1000)
|
|
241
|
+
mu.reg_write(UC_X86_REG_RBP, STACK_ADDR + STACK_SIZE - 0x1000)
|
|
242
|
+
|
|
243
|
+
mu.emu_start(CODE_ADDR, CODE_ADDR + len(code_bytes))
|
|
244
|
+
|
|
245
|
+
result = mu.reg_read(UC_X86_REG_RAX)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 3.2 Hooking Memory & Instructions
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
# Hook memory access
|
|
252
|
+
def hook_mem(uc, access, address, size, value, user_data):
|
|
253
|
+
if access == UC_MEM_WRITE:
|
|
254
|
+
print(f"Write {value:#x} to {address:#x}")
|
|
255
|
+
elif access == UC_MEM_READ:
|
|
256
|
+
print(f"Read from {address:#x}")
|
|
257
|
+
|
|
258
|
+
mu.hook_add(UC_HOOK_MEM_READ | UC_HOOK_MEM_WRITE, hook_mem)
|
|
259
|
+
|
|
260
|
+
# Hook specific instruction (for tracing)
|
|
261
|
+
def hook_code(uc, address, size, user_data):
|
|
262
|
+
code = uc.mem_read(address, size)
|
|
263
|
+
md = Cs(CS_ARCH_X86, CS_MODE_64)
|
|
264
|
+
for insn in md.disasm(bytes(code), address):
|
|
265
|
+
print(f" {insn.address:#x}: {insn.mnemonic} {insn.op_str}")
|
|
266
|
+
|
|
267
|
+
mu.hook_add(UC_HOOK_CODE, hook_code)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### 3.3 Use Cases
|
|
271
|
+
|
|
272
|
+
| Use Case | Approach |
|
|
273
|
+
|---|---|
|
|
274
|
+
| Unpack shellcode | Map shellcode, emulate, dump decoded payload |
|
|
275
|
+
| Decrypt strings | Emulate decryption function with controlled inputs |
|
|
276
|
+
| Brute-force short keys | Loop emulation with different key inputs |
|
|
277
|
+
| Analyze obfuscated function | Emulate function, observe register/memory state |
|
|
278
|
+
| Firmware code emulation | Map firmware memory layout, emulate routines |
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## 4. ANGR EXPLORATION STRATEGIES
|
|
283
|
+
|
|
284
|
+
### 4.1 find/avoid
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
simgr.explore(
|
|
288
|
+
find=lambda s: b"Correct" in s.posix.dumps(1), # stdout contains "Correct"
|
|
289
|
+
avoid=lambda s: b"Wrong" in s.posix.dumps(1) # avoid "Wrong" output
|
|
290
|
+
)
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### 4.2 Managing Path Explosion
|
|
294
|
+
|
|
295
|
+
| Strategy | Implementation |
|
|
296
|
+
|---|---|
|
|
297
|
+
| Constrain input space | Add constraints (printable, length limits) |
|
|
298
|
+
| Avoid dead-end paths | Use `avoid=` for known failure addresses |
|
|
299
|
+
| Hook complex functions | Replace with simplified SimProcedure |
|
|
300
|
+
| Limit loop iterations | `state.options.add(angr.options.LAZY_SOLVES)` |
|
|
301
|
+
| Use veritesting | `simgr.explore(..., technique=angr.exploration_techniques.Veritesting())` |
|
|
302
|
+
| DFS instead of BFS | `simgr.use_technique(angr.exploration_techniques.DFS())` |
|
|
303
|
+
| Timeout per path | `simgr.explore(..., num_find=1)` + timeout wrapper |
|
|
304
|
+
|
|
305
|
+
### 4.3 Concrete + Symbolic Hybrid
|
|
306
|
+
|
|
307
|
+
```python
|
|
308
|
+
state = proj.factory.entry_state(
|
|
309
|
+
add_options={angr.options.UNICORN} # use Unicorn for concrete regions
|
|
310
|
+
)
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
This dramatically speeds up execution: concrete code runs natively via Unicorn, switching to symbolic only when symbolic variables are involved.
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## 5. PRACTICAL WORKFLOW
|
|
318
|
+
|
|
319
|
+
### 5.1 CTF Binary Solving Workflow
|
|
320
|
+
|
|
321
|
+
```
|
|
322
|
+
1. Static analysis: identify input method, success/fail conditions
|
|
323
|
+
└─ Find "Correct" / "Wrong" strings → get their xref addresses
|
|
324
|
+
|
|
325
|
+
2. Choose tool:
|
|
326
|
+
├─ Pure math (no binary needed) → Z3
|
|
327
|
+
├─ Small binary, clear success/fail → angr explore
|
|
328
|
+
└─ Specific function to emulate → Unicorn
|
|
329
|
+
|
|
330
|
+
3. Set up symbolic input:
|
|
331
|
+
├─ stdin → claripy.BVS + entry_state(stdin=)
|
|
332
|
+
├─ argv → full_init_state(args=[...])
|
|
333
|
+
├─ file input → SimFile
|
|
334
|
+
└─ specific memory → state.memory.store(addr, sym)
|
|
335
|
+
|
|
336
|
+
4. Hook problematic functions:
|
|
337
|
+
├─ printf/puts → SimProcedure or no-op
|
|
338
|
+
├─ scanf → custom handler
|
|
339
|
+
├─ time/random → return concrete value
|
|
340
|
+
└─ anti-debug → skip entirely
|
|
341
|
+
|
|
342
|
+
5. Explore and extract:
|
|
343
|
+
└─ simgr.explore(find=, avoid=) → solver.eval()
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## 6. DECISION TREE
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
Need to solve a reversing challenge?
|
|
352
|
+
│
|
|
353
|
+
├─ Is the challenge pure math / equations?
|
|
354
|
+
│ └─ Yes → Z3
|
|
355
|
+
│ ├─ Linear equations → BitVec + Solver
|
|
356
|
+
│ ├─ Modular arithmetic → BitVec (natural mod 2^n)
|
|
357
|
+
│ ├─ Boolean logic → Bool + Solver
|
|
358
|
+
│ └─ Optimization → Optimize + minimize/maximize
|
|
359
|
+
│
|
|
360
|
+
├─ Is it a compiled binary with clear success/fail?
|
|
361
|
+
│ └─ Yes → angr
|
|
362
|
+
│ ├─ Input via stdin → symbolic stdin
|
|
363
|
+
│ ├─ Input via argv → full_init_state with symbolic args
|
|
364
|
+
│ ├─ Input via file → SimFile
|
|
365
|
+
│ ├─ Path explosion → add constraints, avoid paths, hook loops
|
|
366
|
+
│ └─ Complex library calls → hook with SimProcedure
|
|
367
|
+
│
|
|
368
|
+
├─ Need to emulate a specific function/region?
|
|
369
|
+
│ └─ Yes → Unicorn Engine
|
|
370
|
+
│ ├─ Decryption routine → map code + data, emulate, read result
|
|
371
|
+
│ ├─ Shellcode analysis → map shellcode, hook syscalls
|
|
372
|
+
│ └─ Key schedule → emulate with different inputs
|
|
373
|
+
│
|
|
374
|
+
├─ Need to analyze firmware / exotic arch?
|
|
375
|
+
│ └─ Yes → Qiling (full system emulation with OS support)
|
|
376
|
+
│
|
|
377
|
+
├─ Binary has VM protection?
|
|
378
|
+
│ └─ angr for handler analysis + Z3 for bytecode constraints
|
|
379
|
+
│
|
|
380
|
+
└─ None of the above working?
|
|
381
|
+
├─ Combine: Unicorn for concrete regions + Z3 for constraints
|
|
382
|
+
├─ Manual reverse engineering with debugger
|
|
383
|
+
└─ Side-channel approach (timing, power analysis for hardware)
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## 7. COMMON PITFALLS & FIXES
|
|
389
|
+
|
|
390
|
+
| Problem | Cause | Fix |
|
|
391
|
+
|---|---|---|
|
|
392
|
+
| angr hangs forever | Path explosion in loops | Add `avoid=` for loop-back edges, or hook the loop |
|
|
393
|
+
| Z3 returns `unknown` | Non-linear constraints too complex | Simplify, split into sub-problems, use `set_param("timeout", 5000)` |
|
|
394
|
+
| Unicorn crashes on syscall | Syscall not handled | Hook syscall interrupt, handle or skip |
|
|
395
|
+
| angr wrong result | Incorrect state initialization | Verify initial memory layout matches actual binary |
|
|
396
|
+
| Symbolic memory too large | Unbounded symbolic reads | Concretize array indices where possible |
|
|
397
|
+
| SimProcedure wrong types | Argument type mismatch | Check calling convention (cdecl vs fastcall) |
|
|
398
|
+
| angr can't load binary | Missing libraries | Use `auto_load_libs=False` + hook needed symbols |
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
## 8. TOOL VERSIONS & INSTALLATION
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
# angr (Python 3.8+)
|
|
406
|
+
pip install angr
|
|
407
|
+
|
|
408
|
+
# Z3
|
|
409
|
+
pip install z3-solver
|
|
410
|
+
|
|
411
|
+
# Unicorn Engine
|
|
412
|
+
pip install unicorn
|
|
413
|
+
|
|
414
|
+
# Capstone (disassembly, pairs with Unicorn)
|
|
415
|
+
pip install capstone
|
|
416
|
+
|
|
417
|
+
# Keystone (assembly)
|
|
418
|
+
pip install keystone-engine
|
|
419
|
+
```
|