XXE Injection Attacks
XXE (XML External Entity) injection lets you read arbitrary files from the server, perform SSRF, and in some cases achieve code execution. It’s consistently underrated because it hides in XML parsers that developers forget about.
What is XXE?
XML supports external entities — references to resources outside the document. When the XML parser resolves them without restriction, an attacker can point them at sensitive files or internal services.
Vulnerable XML parser behavior:
|
If the response includes the contents of /etc/passwd, the parser is vulnerable.
Basic File Read
|
Windows targets
|
Useful files to read
|
SSRF via XXE
|
Combine with the SSRF playbook — enumerate internal services, cloud metadata, internal APIs.
Blind XXE — Out-of-Band Exfiltration
When the response doesn’t reflect the entity value, use OOB exfiltration.
Step 1 — Host a malicious DTD on your server
|
Step 2 — Send the XXE payload
|
The parser fetches your DTD, which defines an entity that sends the file content to your server.
Error-Based XXE
When OOB network isn’t possible but error messages are reflected:
|
The parser tries to open /nonexistent/<contents of /etc/passwd> and the path (including the file contents) appears in the error message.
Blind XXE via DNS Only
When only DNS callbacks work (HTTP blocked):
|
The hostname appears as a DNS lookup subdomain.
XXE via Different Content Types
Many APIs accept both JSON and XML. Try switching Content-Type:
|
XInclude (when you don’t control the DOCTYPE)
Some applications include user input inside server-constructed XML. If you can’t add a DOCTYPE, try XInclude:
|
XXE via File Upload
SVG file upload
SVGs are XML. Upload a malicious SVG:
|
If the server renders or processes the SVG, file contents may appear in the result.
XLSX/DOCX/PPTX (Office Open XML)
These formats are ZIP archives containing XML. Unzip, inject XXE into the internal XML, re-zip:
|
SAML injection
SAML assertions are base64-encoded XML. Decode, inject XXE, re-encode:
|
PHP Wrappers in XXE
On PHP applications, use PHP stream wrappers:
|
Decode the base64 response to get the file content.
Detection Checklist
Look for XML parsing in:
- SOAP web services
- REST APIs accepting
Content-Type: application/xml - File uploads (SVG, DOCX, XLSX, PDF)
- RSS/Atom feed processing
- SAML authentication
- OpenDocument format processing
- Any endpoint that parses user-supplied XML
Remediation
- Disable external entity processing in the XML parser (the safest fix).
- In Java:
factory.setFeature("http://xml.org/sax/features/external-general-entities", false) - In PHP:
libxml_disable_entity_loader(true)(deprecated in PHP 8 — external entities are disabled by default) - In Python
lxml:etree.XMLParser(resolve_entities=False) - Use a JSON API instead of XML where possible.
- Validate and sanitize all XML input server-side.
Discussion
Leave a comment · All fields required · No spam
No comments yet. Be the first.