0x00 XPATH Injection 手工审计
XPATH Injection
和SQL Injection
有些类似,不同的是前者是使用XML
查询代替了SQL
查询,产生原因也是没有去验证用户的输入请求信息。 看源码!
<?php
$result = '';
if(isset($_POST['submit'])){
$doc = new DOMDocument;
$doc->load('coffee.xml');
$xpath = new DOMXPath($doc);
$input = $_POST['search'];
$query = "/Coffees/Coffee[@ID='".$input."']";
#$result = isset($xpath->query($query)) ? $xpath->query($query) : '';
$result = $xpath->query($query);
}
?>
熟悉的xml
,最近确实学习到了不少xml
相关的知识,学习需要积累!
看着很轻松,将提交的search
参数拼接到$query
中,然后用实例化的$xpath
进行查询。
coffee.xml
的内容如下
<Coffees>
<Coffee ID="1">
<ID>1</ID>
<Name>Affogato</Name>
<Desc>An affogato (Italian, "drowned") is a coffee-based beverage. It usually takes the form of a scoop of vanilla gelato or ice cream topped with a shot of hot espresso. Some variations also include a shot of Amaretto or other liqueur.</Desc>
<Price>$4.69</Price>
</Coffee>
<Coffee ID="2">
<ID>2</ID>
<Name>Americano</Name>
<Desc>An Americano is an espresso-based drink designed to resemble coffee brewed in a drip filter, considered popular in the United States of America. This drink consists of a single or double-shot of espresso combined with up to four or five ounces of hot water in a two-demitasse cup.</Desc>
<Price>$5.00</Price>
</Coffee>
<Coffee ID="3">
....
贴的并不完全,但是可以看出来,是完全符合xml
格式标准的。
了解下表达式的基本规则吧
表达式 | 描述 |
---|---|
nodename | 选取此节点的所有子节点 |
/ | 从根节点选取 |
// | 从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置 |
. | 选取当前节点 |
… | 选取当前节点的父节点 |
@ | 选取属性或 @*:匹配任何属性节点 |
* | 匹配任何元素节点 |
那么再看
$query = "/Coffees/Coffee[@ID='".$input."']";
这其实就很明了了,查根节点的Coffees
的子节点Coffee
,通过ID
来选举属性。
0x02 漏洞利用
这里能做的事情比较少,没有用户信息,只有Coffee
的信息,能做的事大概就只有一次读取所有的xml
信息了,如果是使用xml
做用户验证的话,应该也可以形成万能密码进行绕过登陆验证。接触这个比较少,所以也没有办法做一个比较好的总结,网上找了一些案例,感觉都大同小异,没有比较精彩的,在wooyun
上查到的XPATH
都是SQL注入
的updatexml
。。。。。。
这里直接放效果好了。
直接遍历所有的数据。
0x02 修复方案
修复方案的话就是过滤掉常用的/.*@<>... and or
等。
甚至会有xpath blind
的情况,放个以后可能用的上表。