π Description
XXE (XML External Entity) attacks are a type of injection attack in which an attacker attempts to exploit a vulnerability in an application that parses XML input. This vulnerability can allow an attacker to inject malicious code into the XML input, which is then executed by the application.
π΅οΈ Proof of Conceptt
In your application, XXE attack occurs when we inject in the input POST parameter : /v8APAA/AHgAbQBsACAAdgBlAHIAcwBpAG8AbgA9ACIAMQAuADAAIgA/AD4APAAhAEQATwBDAFQAWQBQAEUAIAByAG8AbwB0ACAAWwA8ACEARQBOAFQASQBUAFkAIAB0AGUAcwB0ACAAUwBZAFMAVABFAE0AIAAnAGYAaQBsAGUAOgAvAC8ALwB0AG0AcAAvAGYAbABhAGcALgB0AHgAdAAnAD4AXQA+ADwAcgBvAG8AdAA+ACYAdABlAHMAdAA7ADwALwByAG8AbwB0AD4=
Decoded the payload is as follow :
<?xml version="1.0"?><!DOCTYPE root [<!ENTITY test SYSTEM 'file:///tmp/flag.txt'>]>&test;
The vulnerability come from the bypass of restriction in the application code :
|
|
If we inject an XML encoded in UTF-16, wich start with b’\xff\xfe’, we can bypass the filters restriction and access the file in /tmp/flag.txt. Bellow the script to convert the xml file.
|
|
As shown in the image below, it is possible to access the /tmp/flag.txt file :
π§ Impacts
XXE attacks can be used to access sensitive information from the application or from the server on which it is running. For example, an attacker might use an XXE attack to read sensitive files from the file system, send HTTP requests to other servers, or even execute commands on the server.
π Mitigations
XXE vulnerabilities can occur when an application processes XML input without properly validating or sanitizing it. This can allow an attacker to inject malicious code into the XML input, which is then executed by the application.
To prevent XXE attacks, it is important to properly validate and sanitize all XML input to ensure that it does not contain any malicious code. This can be done using techniques such as input validation, input sanitization, and input whitelisting. It is also important to keep the application and its dependencies up to date to ensure that any known vulnerabilities are patched.
π References PortSwigger - XML external entity (XXE) CWE-611: Improper Restriction of XML External Entity Reference