👽XXE(XML External Entity)
Last updated
Last updated
Key | Definition | Example |
---|---|---|
Since data is being sent in XML
And the email gets displayed back. So trying different variables(&/;) We can display the company variable:
It is displaying the company name instead of &company;
Note: Some web applications may default to a JSON format in HTTP request, but may still accept other formats, including XML. So, even if a web app sends requests in a JSON format, we can try changing the Content-Type header to application/xml, and then convert the JSON data to XML with an online tool. If the web application does accept the request with XML data, then we may also test it against XXE vulnerabilities, which may reveal an unanticipated XXE vulnerability.
So defining an external XML entity
Tip: In certain Java web applications, we may also be able to specify a directory instead of a file, and we will get a directory listing instead, which can be useful for locating sensitive files.
As we can see, this did not work, as we did not get any content. This happened because the file we are referencing is not in a proper XML format, so it fails to be referenced as an external XML entity.
If a file contains some of XML's special characters (e.g. </>/&), it would break the external entity reference and not be used for the reference
So we can base64 encode:
Note: We replaced all spaces in the above XML code with $IFS, to avoid breaking the XML syntax. Furthermore, many other characters like |, >, and { may break the code, so we should avoid using them.
Another common attack often carried out through XXE vulnerabilities is SSRF exploitation. This causes DOS
With php files we can avoid breaking it by using base64 but for other types of files we need to use CDATA like <![CDATA[ FILE_CONTENT ]]>
For example:
Then we can refer the &joined; entity. However this will not work since XML prevents joining of internal and external entity.
Better Way:
Utilize XML Parameter Entities (special entity starts with % and used only in DTD) If we reference them from an external source then all of them would be considered external and joined like:
Host on attack machine:
Now we can reference the xxe.dtd and use &joined; Example:
This way no need to base64 encode it.
Note: In some modern web servers, we may not be able to read some files (like index.php), as the web server would be preventing a DOS attack caused by file/entity self-reference (i.e., XML entity reference loop), as mentioned in the previous section.
If application does not write any output we need to do XXE blind. If any runtime errors are show (eg: PHP errors)
To check if errors are present reference a non existing entity. This can reveal directories. We can host a DTD file with:
The above payload defines the file parameter entity and then joins it with an entity that does not exist, so the web application would throw an error saying that this entity does not exist, along with our joined %file; as part of the error.
Once we host our DTD script and send the above payload as our XML data (no need to include any other XML data), we will get the content of the /etc/hosts file as follows:
Out of band is like last section where we connected to our machine to get the hosted file.
Instead of sending the request only we can make the webapp send the request to our web server with the content of the file we requested. Like so:
We can automate this process by making a php webserver: Index.php
Then run the server php -S 0.0.0.0:8000
The payload:
The request would look like this:
The file content will be there in the attack machine terminal
Tip: In addition to storing our base64 encoded data as a parameter to our URL, we may utilize DNS OOB Exfiltration by placing the encoded data as a sub-domain for our URL (e.g. ENCODEDTEXT.our.website.com), and then use a tool like tcpdump to capture any incoming traffic and decode the sub-domain string to get the data. Granted, this method is more advanced and requires more effort to exfiltrate data through.
Copy the request from burp suite and add XXEINJECT after it and save it in a file
Then run:
Tag
The keys of an XML document, usually wrapped with (</>) characters.
<date>
Entity
XML variables, usually wrapped with (&/;) characters.
<
Element
The root element or any of its child elements, and its value is stored in between a start-tag and an end-tag.
<date>01-01-2022</date>
Attribute
Optional specifications for any element that are stored in the tags, which may be used by the XML parser.c
version="1.0"/encoding="UTF-8"
Declaration
Usually the first line of an XML document, and defines the XML version and encoding to use when parsing it.
<?xml version="1.0" encoding="UTF-8"?>