XXE (XML external entity) injection

What is it?

XML External Entity (XXE) vulnerabilities occur when an application processes XML input that includes a reference to an external entity. This vulnerability can occur in any technology that parses XML. By exploiting an XXE vulnerability, an attacker can read local files on the server, interact with internal systems, or conduct denial of service attacks.

A simple example

A vulnerable application might parse XML input from a user without disabling external entities. An attacker could then send XML like the following:

<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
<foo>&xxe;</foo>

In this case, the XML parser will replace &xxe; with the contents of the /etc/passwd file and include it in the output.

XXE can often lead to:

  • Disclosure of internal files

  • Server Side Request Forgery (SSRF)

  • Denial of Service

  • Remote Code Execution in some rare cases

Other learning resources:

Writeups:

Checklist

Objective

Attack surface discovery

Testing

Impact

Exploitation

Sources

  • My pentest notes

  • PortSwigger

  • PayloadsAllTheThings

Detect XXE

Include files Note: You might need "file:///etc/passwd"

List files: Note: Restricted to Java applications

Out-of-band:

Parameter entities:

Load an external DTD:

Execute code Note: Only works in the PHP 'expect' module is available

Include XML as a parameter value

Other sources

  • Fuzzing for XXE https://github.com/xmendez/wfuzz/blob/master/wordlist/Injections/XML.txt

  • Fuzzing for local DTDs https://github.com/GoSecure/dtd-finder/tree/master/list

Last updated

Was this helpful?