🟩XML External Entity (XXE) Injection
Intro
The XML document type definition (DTD) contains declarations that can define the structure of an XML document. The DTD is declared within the optional DOCTYPE element at the start of the XML document.
XXE are a type of custom XML entity whose defined values are loaded from outside of the DTD.
Allows an attacker to interfere with an application's processing of XML data.
Examples
Custom entities to be defined within the DTD
<!DOCTYPE foo [ <!ENTITY
myentity
"
my entity value
" > ]>
XML external entities uses the "SYSTEM" keyword and must specify a URL
<!DOCTYPE foo [ <!ENTITY
NAME
SYSTEM "
http://normal-website.com
" > ]>
<!DOCTYPE foo [ <!ENTITY
NAME
SYSTEM "
file:///path/to/file
" > ]>
Types of XXE attacks
Exploiting XXE to retrieve files
Exploiting XXE to perform SSRF attacks
Blind XXE vulnerabilities
Does not return the values of any defined external entities within its responses.
Use the FTP protocol instead of HTTP, it will be possible to exfiltrate data containing newline character
Exploiting blind XXE exfiltrate data out-of-band
Attacker create a malicious DTD on his server (malicious.dtd) like:
Attacker must submit the following XXE payload to the vulnerable application:
Use the FTP protocol instead of HTTP, it will be possible to exfiltrate data containing newline characters
Exploiting blind XXE to retrieve data via error messages
First method
Attacker create a malicious DTD on his server (malicious.dtd) like:
Attacker must submit the following XXE payload to the vulnerable application:
Second method
Retrieve data via repurposing a local DTD
Finding hidden attack surface for XXE injection
XInclude attacks
Some applications receive client-submitted data, embed it on the server-side into an XML document like: backend SOAP service.
"XInclude" is a part of the XML specification that allows an XML document to be built from sub-documents.
XXE attacks via file upload
If uploaded files which are then processed server-side, it can be vulnerable. Examples of XML-based formats are office document formats like DOCX and image formats like SVG.
Create a SVG image with this payload and upload it. The result will be on the image.
XXE attacks via modified content type
You might be able submit the following request, with the same result.
Server parses the body content as XML, then you can reach the hidden XXE attack surface
Last updated