5. XXE - Local file disclosure

When webapps trust unfiltered XML data from user input we can reference external XML DTD docs and define new custom XML entities.

First step in identifying a potential XXE vuln is finding webpages that accept XML user input. ![](/img/Pasted image 20241230133232.png)

Assume outdated XML libraries used to parse our xml data. Assume no filters or sanitization on our XML input. Potentially exploitable.

Sending request we get:

![](/img/Pasted image 20241230133336.png)

The value email is reflected back to us from user input. To print content of ext. file to page - note which elements get displayed back to us, and use that element to inject.

So, let's define a new entity and use it as a variable in the email element.

Note: In our example, the XML input in the HTTP request had no DTD being declared within the XML data itself, or being referenced externally, so we added a new DTD before defining our entity. If the DOCTYPE was already declared in the XML request, we would just add the ENTITY element to it.

![](/img/Pasted image 20241230133627.png)

Now we should have an xml entity named company reference-able with &company;

![](/img/Pasted image 20241230133715.png)

This confirms we are dealing with a webapp that is vulnerable to XXE

Leveraging XXE to read sensitive files

![](/img/Pasted image 20241230133916.png)

Same steps as above. XML variable referring to a local file, and referencing that xml variable.

We can read content of sensitive files using this, like config files that may contain passwords or other sensitive files like an SSH private key of a specific user. NOTE:

Same concept applies for reading the source code of the webapplication, enabling a Whitebox pentest to unveil more vulnerabilities in the webapplication or at the very least reveal secret configs or api keys.

![](/img/Pasted image 20241230134128.png)

On first attempt this doesn't work: Why?

![](/img/Pasted image 20241230134528.png)

we can decode this right from burp

![](/img/Pasted image 20241230134625.png)

This trick only works for PHP.

Module exercise: Read connection.php

![](/img/Pasted image 20241230141056.png)