XXE - TairinySimeonato/WebAuditing GitHub Wiki
- XXE is an attack against an application that parses XML input
- XML input containing reference to an external entity (file path or URL, for example) is processed by a misconfigured XML parser
- The attack can cause DoS, SSRF, disclosure of sensitive data, RCE, LFI, port scanning and internal network mapping, etc.
- Extend XML file can load local files and external URLs
- Can lead to LFI and RCE, causing a higher impact
- XML allows people to create documents easily read both by computers and humans
- The contents of XML are kept inside and tags
- Usually characters are escaped:
-
<
-> < -
>
--> > -
&
--> & -
'
--> ' -
"
--> "e;
-
- However, it is still possible to perform XXE without these chars
- A misconfigured parser might allow a malicious user to input a file path instead of a string. The parser can display the contents of the file.
<!ENTITY body "Example here" >
can be changed to:
<!ENTITY body SYSTEM "file:///etc/passwd" >
- QUESTION XXE --> LFI --> RCE ??
Some parses might display contents of /etc/passwd
If you replace "file://" with "http://...", the server might request the URL. This can result in a SSRF.
The attacker can request internal web servers, scan for open ports and map the internal network.'
1) LFI
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<foo>&xxe;</foo>
2.SSRF
<!ENTITY xxe SYSTEM "https://www.test.com" >]>
3. DoS (uploading a endless file)
<!ENTITY xxe SYSTEM "file:///dev/random" >]>
- Disallow XXE in XML parser or server configuration (double-check)
- if possible use less complex data formats, such JSON
- XML parser should use a local static DTD (document type definition)
- Server-side whitelist for input validation, filtering, or sanitization
- XXEserv is a FTP/HTTP server used to identify XXE requests
- SAST helps to identify XXE in source code
- https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing
- https://www.owasp.org/images/7/72/OWASP_Top_10-2017_%28en%29.pdf.pdf
- https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md
- https://en.wikipedia.org/wiki/XML_external_entity_attack
- https://medium.com/bugbountywriteup/devoops-an-xml-external-entity-xxe-hackthebox-walkthrough-fb5ba03aaaa2
- https://medium.com/@jonathanbouman/xxe-at-bol-com-7d331186de54