githubEdit

XXE

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:

XXE (XML External Entity)

XXE is a type of attack against an application that parses XML input.

Read Files

PHP Filter

Remote Code Execution

SSRF attack

Also we can use the Blind XXE for exfiltrating data. Please refer to the Blind XXEarrow-up-right page.

XInclude

File upload

Checklist

Objective

Attack surface discovery

Testing

Impact

Exploitation

Sources

  • My pentest notes

  • PortSwigger

  • PayloadsAllTheThings

Detect XXE

Include files &#xNAN;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

Summary

circle-info

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 backend or external systems that the application itself can access.

Detection:

Check:

If works, then:

Blind XXE

What is it?

Blind XML External Entity (XXE) vulnerabilities arise when an application processes XML input that includes references to an external entity, but does not return the outcome of the entity processing in the response. This makes the exploitation less direct since the attacker does not receive an immediate output from the injected payload. Blind XXE can be exploited to exfiltrate data, scan internal systems, or execute remote requests within the network that hosts the vulnerable application.

Exploitation

Blind XXE using OOB

Blind XXE using OOB with XML parameter entities

chevron-rightSolutionhashtag

Tools

Attacks

Blind XXE

XXE is a type of vulnerability that allows an attacker to inject and execute malicious XML code on a server that parses XML input, without directly receiving any feedback or response from the server.

Data Exfiltration via Out-Of-Band

1. Create a Malicious DTD

We need to prepare the dtd file (named "exploit.dtd" here) to retrieve the target file. Replace the ip address with your own.

Then host it on web server.

2. Insert XXE

In http request body, insert the following XXE payload. Same as above DTD, replace the ip address with your own

Now send request. We might retrieve the local file of the target system via web server.

Data Exfiltration via Out-Of-Band (Error-based)

If the website shows error messages when performing XXE, we can use the following malicious DTD.

For the rest, please refer to the section above.

Inside XLSX File

An XLSX file is a Microsoft Excel spreadsheet.

1. Create a XLSX File

First we need to create a XLSX file using some software such as LibreOffice Calc.

2. Extract the XLSX File

We should get files such as “.xml”.

3. Add Blind XXE Payload in the XML File.

Insert the following payload into the xl/workbook.xml. Replace the “10.0.0.1” with your local ip address.

4. Rebuild the XLSX File.

5. Create XXE inside a DTD File

Create “xxe.dtd”. Replace “10.0.0.1” with your local ip address.

6. Start a local server

Serve the DTD file using xxeservarrow-up-right.

In another terminal, start a web server in the directory where “xxe.dtd” located.

Now upload “xxe.xlsx” file in the website. We should get the content of the desired file.

References

Mindmap

Last updated