XXE / XSLT

XML External Entity

ko-fi

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE email [
  <!ENTITY company SYSTEM "http://localhost/company.txt">
  <!ENTITY signature SYSTEM "file:///var/www/html/signature.txt">
]>

We may also use the PUBLIC keyword instead of SYSTEM for loading external resources, which is used with publicly declared entities and standards, such as a language code (lang="en").

Detection

In your proxy interceptor, add a match&replace rule to change content type "application/json" to "text/xml"

All you have to do now is look for XML parsing errors

Change content type "application/json" to "application/xml"

Burp Extension - Content Type Converter

Read File

Read the content of sensitive files, like configuration files that may contain passwords or other sensitive files like an id_rsa SSH key of a specific user

Read the source code of the web application

Tip: In certain Java web applications, we may also be able to specify a directory instead of a file, and we will get a directory listing instead, which can be useful for locating sensitive files. See Basic XXE

If a file contains some of XML's special characters (e.g. </>/&), it would break the external entity reference and not be used for the reference. Furthermore, we cannot read any binary data, as it would also not conform to the XML format. Solution for PHP app: Base64

PHP Filters:

File Inclusion LFI / RFI

For Java app, see Bad characters - wrapper

Using SVG Image

Remote Code Execution with XXE

PHP://expect filter

Note: We replaced all spaces in the above XML code with $IFS, to avoid breaking the XML syntax. Furthermore, many other characters like |, >, and { may break the code, so we should avoid using them

Other XXE Attacks

Port scan, SSRF

DoS:

This attack no longer works with modern web servers (e.g., Apache), as they protect against entity self-reference

Advanced Exfiltration with CDATA

Note: In some modern web servers, we may not be able to read some files (like index.php), as the web server would be preventing a DOS attack caused by file/entity self-reference (i.e., XML entity reference loop), as mentioned in the previous section.

See Bad Character - Wrappers

Error Based XXE

DTD file - xxe.dtd

payload

This method is not as reliable as the previous method for reading source files, as it may have length limitations, and certain special characters may still break it

Out-of-band Data Exfiltration

Dtd file:

Payload:

Tip: In addition to storing our base64 encoded data as a parameter to our URL, we may utilize DNS OOB Exfiltration by placing the encoded data as a sub-domain for our URL (e.g. ENCODEDTEXT.our.website.com), and then use a tool like tcpdump to capture any incoming traffic and decode the sub-domain string to get the data. Granted, this method is more advanced and requires more effort to exfiltrate data through.

Automation - XXEInjector

See Tools

Copy the HTTP request from Burp and write it to a file. Not include the full XML data, only the first line, and write XXEINJECT after it as a position locator for the tool:

All exfiltrated files get stored in the Logs folder under the tool

Tools

After identifying a Blind XXE for example in Burpsuite it is pretty straight forward with this tool. Simply save the request into a file (req.txt for example) and insert XXEINJECT at the location of the identified injectible parameter. https://blog.kennyjansson.com/2018/03/31/automating-blind-xxe-injection/


More payloads

Basic XXE

Lister des répertoires

file:/// : liste la racine file:///home/ : liste /home

XXE to SSRF

Blind XXE

Tool: XXEInjector

Nuclei Template

https://github.com/coffinxp/priv8-Nuclei/blob/main/blind-xxe.yaml

Out of Band

OOB Detection

OOB using SVG Image

DTD Exfiltration

  • FTP

also: https://github.com/cyberaz0r/XXE-OOB-Exfiltrator

Not able to exfiltrate /etc/passwd over http, or ftp on java/tomcat:

Bad characters - Wrapper DTD - CDATA

https://assets.ctfassets.net/wcxs9ap8i19s/0L47QKLLc07wzvjOBwo4ul/bfee1a0db2c65a02d7ac0b042ebe97e7/XXE-An-overlooked-threat_WhitePaper.pdf

Repurposing Loacl DTD

Find a local DTD to repurpose

RCE in PHP

Try to use the expect package

Resources


XSLT Recon

Determine the Vendor and Version

Fingerprinting

File Read

XSS

RCE

SSRF

Payloads

Interesting Books

Interesting Books

Disclaimer: As an Amazon Associate, I earn from qualifying purchases. This helps support this GitBook project at no extra cost to you.

Support this Gitbook

I hope it helps you as much as it has helped me. If you can support me in any way, I would deeply appreciate it.

ko-fi

buymeacoffee

Resources

Last updated