数据泄露——江苏省第四届数据安全技术应用职业技能竞赛初赛

admin 2026-07-14 05:28:04 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 本文分析江苏省第四届数据安全技术应用职业技能竞赛初赛中的数据泄露题目,聚焦SQL布尔盲注日志分析。通过解析HTTP响应长度差异(24字节为True,47字节为False),利用二分法逐字符还原数据库内容,最终成功提取用户名admin和密码Adm1n@2026。文章提供了详细的日志分析步骤和自动化脚本,适用于CTF取证和应急响应场景。 综合评分: 83 文章分类: 漏洞分析,应急响应,实战经验


cover_image

数据泄露——江苏省第四届数据安全技术应用职业技能竞赛初赛

原创

一只岸上的鱼 一只岸上的鱼

一只岸上的鱼

2026年7月13日 21:07 江苏

在小说阅读器读本章

去阅读

数据泄露——江苏省第四届数据安全技术应用职业技能竞赛初赛

缘起

其实这次赛事组织的真不咋地,一会儿没插座,一会儿附件无法下载,还有题目是奇奇怪怪的,比如这题,附件使用usb拷贝的,有三问,但是实际试卷却只有俩问……

总的来说,这是一道经典的题目,就是sql注入日志分析,这题还算简单————因为题目常规,脚本是备好的,

可惜,还是没得分,第一问做出来了,但是题目没有,第二问也做出来了,但是一直答案不对……,第三问就没做了

题干

先说,题目附件我放在cnb了:https://cnb.cool/netvvorm/items/datasecurity26

第一问:

但是附件下载后,第一问实际是:

分析

这种sql注入是经典题目,有时候还会套一层流量分析:就是先要从流量包里面导出这些日志,notepad打开是这样的:

有个小技巧,使用notepad++自带的工具进行url decode:

这样比较容易看得清楚:

布尔盲注

什么叫盲注:就是select的信息内容不会实际返回

什么叫布尔:即使返回结果根据对错有无,返回只有2中情况,所以借以判断注入结果

一般数据库、表、字段命名,大部遵循ascii码,而ascii码的值的范围是0-127,所以有一种简单的办法就是将想要查询的字段的每个字符与所有的ascii码进行比较,如果返回的结果与预期不符,则说明该字符不存在,否则存在,这样就可以逐个字符的查询了,当然实用的方法是二分法,而不是真的顺序查询。

以本题的第一个字符为例:

实际执行的sql是这样的:

sql

-- 布尔条件:第1个字符的ASCII码是否大于97?
-- 注入字段
ORD(MID((SELECT IFNULL(CAST(username AS NCHAR),0x20) FROM user_data.`user` ORDER BY id LIMIT 0,1),1,1))>63 AND 'CWkt'='CWkt

-- 后台执行的sql(例)
SELECT * FROM user WHERE id = 1 AND ORD(MID((SELECT username FROM user LIMIT 0,1),1,1))>63

然后来分析日志:

  1. 先确认true和false

返回的结果都是http code=200,但是长短只有2个,一个是24,一个47,看一眼(这一眼是指根据二分法查找的值的变化来判断的),24=true,47=false,

小知识:判断一般有这几种情况

| 信号类型 | 示例 | | — | — | | 响应体长度不同 | True→24字节, False→47字节 | | HTTP状态码不同 | True→200, False→302 | | 响应时间差异 | True→<100ms, False→>500ms(时间盲注) | | 页面特征文本 | True含”Welcome”, False含”Error” |

  1. 二分法轮询
code

第1轮:> 63 ? &nbsp;→ &nbsp;True → 值在 (63, 127]
第2轮:> 95 ? &nbsp;→ &nbsp;True → 值在 (95, 127]
第3轮:> 111 ? → &nbsp;False → 值在 (95, 111]
第4轮:> 103 ? → &nbsp;False → 值在 (95, 103]
第5轮:> 99 ? &nbsp;→ &nbsp;False → 值在 (95, 99]
第6轮:> 97 ? &nbsp;→ &nbsp;False → 值在 (95, 97]
第7轮:> 96 ? &nbsp;→ &nbsp;True &nbsp;→ 值 = 97 &nbsp;✓

asscii码的值是97,所以第一个字符是a

后面就简单的了,最终结果:

+----------+------------+
| 字段 &nbsp; &nbsp; | 值 &nbsp; &nbsp; &nbsp; &nbsp; |
+----------+------------+
| username | admin &nbsp; &nbsp; &nbsp;|
| password | Adm1n@2026 |
+----------+------------+

脚本:

这个脚本是AI给的,因为他比我的脚本好看,就提供这个了:

python

#!/usr/bin/env python3
"""
SQL Boolean Blind Injection Log Analyzer
========================================
从Web访问日志中还原SQL布尔盲注(二分搜索模式)窃取的数据库内容。

适用场景:
&nbsp; - CTF取证题:给定access.log,还原被盲注窃取的数据
&nbsp; - 应急响应:分析攻击者通过盲注读取了哪些敏感字段

支持的Payload格式(sqlmap常见风格):
&nbsp; ORD(MID((SELECT IFNULL(CAST(field AS NCHAR),0x20)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM database.`table` ORDER BY col LIMIT row,1),pos,1))>threshold

用法:
&nbsp; python sqli_blind_log_analyzer.py -f access.log [--true-size 24] [--false-size 47] [--auto-detect]

作者:CTF Log Forensics Tool
"""

import&nbsp;re
import&nbsp;sys
import&nbsp;argparse
import&nbsp;urllib.parse
from&nbsp;collections&nbsp;import&nbsp;defaultdict

# ──────────────────────── 正则模式 ────────────────────────

# 匹配sqlmap风格的布尔盲注payload
PAYLOAD_PATTERN = re.compile(
&nbsp; &nbsp;&nbsp;r"ORD\(MID\(\(SELECT IFNULL\(CAST\((\w+) AS NCHAR\),0x20\)"
&nbsp; &nbsp;&nbsp;r" FROM (\w+)\.`(\w+)` ORDER BY \w+ LIMIT (\d+),1\)"
&nbsp; &nbsp;&nbsp;r",(\d+),1\)\)>(\d+)"
)

# 更宽松的匹配:不要求ORD/MID/IFNULL的具体格式,只要有关键结构
LOOSE_PATTERN = re.compile(
&nbsp; &nbsp;&nbsp;r"(?:ORD|ASCII)\(.*?MID\(.*?(?:SELECT|select).*?"
&nbsp; &nbsp;&nbsp;r"(\w+).*?LIMIT\s+(\d+),1.*?,(\d+),1\).*?>(\d+)",
&nbsp; &nbsp; re.IGNORECASE | re.DOTALL
)

# 日志行解析
LOG_PATTERN = re.compile(
&nbsp; &nbsp;&nbsp;r'(\S+).*?"(\w+)\s+(\S+)\s+HTTP[^"]*"\s+(\d+)\s+(\d+)'
)

# ──────────────────────── 核心逻辑 ────────────────────────

def&nbsp;parse_log(filepath, true_size=None, false_size=None, auto_detect=True):
&nbsp; &nbsp;&nbsp;"""
&nbsp; &nbsp; 解析日志文件,提取所有盲注请求并还原数据。

&nbsp; &nbsp; 参数:
&nbsp; &nbsp; &nbsp; &nbsp; filepath: &nbsp; &nbsp;日志文件路径
&nbsp; &nbsp; &nbsp; &nbsp; true_size: &nbsp; 响应True时的body长度(已知时传入)
&nbsp; &nbsp; &nbsp; &nbsp; false_size: &nbsp;响应False时的body长度(已知时传入)
&nbsp; &nbsp; &nbsp; &nbsp; auto_detect: 是否自动检测True/False对应的响应长度

&nbsp; &nbsp; 返回:
&nbsp; &nbsp; &nbsp; &nbsp; dict: {(field, db, table, row): {position: char}}
&nbsp; &nbsp; """
&nbsp; &nbsp;&nbsp;with&nbsp;open(filepath,&nbsp;'r', encoding='utf-8', errors='ignore')&nbsp;as&nbsp;f:
&nbsp; &nbsp; &nbsp; &nbsp; lines = f.readlines()

&nbsp; &nbsp;&nbsp;print(f"[*] 日志行数:&nbsp;{len(lines)}")

&nbsp; &nbsp;&nbsp;# 第一遍:收集所有请求信息
&nbsp; &nbsp; requests = []
&nbsp; &nbsp; size_counter = defaultdict(int)

&nbsp; &nbsp;&nbsp;for&nbsp;line&nbsp;in&nbsp;lines:
&nbsp; &nbsp; &nbsp; &nbsp; m = LOG_PATTERN.search(line)
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;not&nbsp;m:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue

&nbsp; &nbsp; &nbsp; &nbsp; ip, method, url, status_code, body_size = m.groups()
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;method !=&nbsp;'GET'&nbsp;or&nbsp;int(status_code) !=&nbsp;200:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue

&nbsp; &nbsp; &nbsp; &nbsp; body_size =&nbsp;int(body_size)
&nbsp; &nbsp; &nbsp; &nbsp; decoded_url = urllib.parse.unquote(url)

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 尝试匹配payload
&nbsp; &nbsp; &nbsp; &nbsp; pm = PAYLOAD_PATTERN.search(decoded_url)
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;not&nbsp;pm:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue

&nbsp; &nbsp; &nbsp; &nbsp; field = pm.group(1) &nbsp; &nbsp; &nbsp;&nbsp;# 字段名
&nbsp; &nbsp; &nbsp; &nbsp; db = pm.group(2) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# 数据库名
&nbsp; &nbsp; &nbsp; &nbsp; table = pm.group(3) &nbsp; &nbsp; &nbsp;&nbsp;# 表名
&nbsp; &nbsp; &nbsp; &nbsp; row =&nbsp;int(pm.group(4)) &nbsp; &nbsp;# 行偏移
&nbsp; &nbsp; &nbsp; &nbsp; pos =&nbsp;int(pm.group(5)) &nbsp; &nbsp;# 字符位置
&nbsp; &nbsp; &nbsp; &nbsp; threshold =&nbsp;int(pm.group(6)) &nbsp;# 比较阈值

&nbsp; &nbsp; &nbsp; &nbsp; requests.append((field, db, table, row, pos, threshold, body_size))
&nbsp; &nbsp; &nbsp; &nbsp; size_counter[body_size] +=&nbsp;1

&nbsp; &nbsp;&nbsp;print(f"[*] 有效盲注请求数:&nbsp;{len(requests)}")
&nbsp; &nbsp;&nbsp;print(f"[*] 响应长度分布:&nbsp;{dict(sorted(size_counter.items(), key=lambda&nbsp;x: -x[1]))}")

&nbsp; &nbsp;&nbsp;# ── 自动检测 True/False 对应的响应长度 ──
&nbsp; &nbsp;&nbsp;if&nbsp;true_size&nbsp;is&nbsp;None&nbsp;or&nbsp;false_size&nbsp;is&nbsp;None:
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;auto_detect&nbsp;and&nbsp;len(size_counter) ==&nbsp;2:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sizes =&nbsp;sorted(size_counter.keys())
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 启发式:较小的size通常对应True(页面返回简化内容)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 但这不总是成立,需要验证
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f"[!] 响应只有两种长度:&nbsp;{sizes[0]}&nbsp;和&nbsp;{sizes[1]}")
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f"[!] 需要确定哪个是True,哪个是False")

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 尝试两种方向,用逻辑一致性验证
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;ts, fs&nbsp;in&nbsp;[(sizes[0], sizes[1]), (sizes[1], sizes[0])]:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;verify_consistency(requests, ts, fs):
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; true_size, false_size = ts, fs
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f"[+] 验证通过: True={true_size}, False={false_size}")
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;break
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;else:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 两种方向都无法完美验证,默认取较小值为True
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; true_size, false_size = sizes[0], sizes[1]
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f"[!] 无法自动验证,默认 True={true_size}, False={false_size}")
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f"[!] 如结果不正确,请用 --true-size 和 --false-size 手动指定")
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;else:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print("[!] 无法自动检测,请用 --true-size 和 --false-size 指定")
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;{}

&nbsp; &nbsp;&nbsp;# ── 按字符位置分组,执行二分搜索还原 ──
&nbsp; &nbsp; char_tests = defaultdict(list)
&nbsp; &nbsp;&nbsp;for&nbsp;field, db, table, row, pos, threshold, body_size&nbsp;in&nbsp;requests:
&nbsp; &nbsp; &nbsp; &nbsp; is_true = (body_size == true_size)
&nbsp; &nbsp; &nbsp; &nbsp; char_tests[(field, db, table, row, pos)].append((threshold, is_true))

&nbsp; &nbsp; reconstructed = defaultdict(dict)
&nbsp; &nbsp;&nbsp;for&nbsp;key, tests&nbsp;in&nbsp;char_tests.items():
&nbsp; &nbsp; &nbsp; &nbsp; field, db, table, row, pos = key
&nbsp; &nbsp; &nbsp; &nbsp; ascii_val = resolve_binary_search(tests)
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;ascii_val >&nbsp;0:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reconstructed[(field, db, table, row)][pos] =&nbsp;chr(ascii_val)

&nbsp; &nbsp;&nbsp;return&nbsp;reconstructed

def&nbsp;verify_consistency(requests, true_size, false_size, sample_limit=50):
&nbsp; &nbsp;&nbsp;"""
&nbsp; &nbsp; 验证True/False方向是否逻辑一致。

&nbsp; &nbsp; 原理:二分搜索的True/False序列应当形成合理的区间——
&nbsp; &nbsp; 所有True的阈值应当 < 所有False的阈值。
&nbsp; &nbsp; """
&nbsp; &nbsp; consistent =&nbsp;0
&nbsp; &nbsp; total =&nbsp;0

&nbsp; &nbsp;&nbsp;# 按字符分组
&nbsp; &nbsp; groups = defaultdict(list)
&nbsp; &nbsp;&nbsp;for&nbsp;field, db, table, row, pos, threshold, body_size&nbsp;in&nbsp;requests[:sample_limit *&nbsp;7]:
&nbsp; &nbsp; &nbsp; &nbsp; is_true = (body_size == true_size)
&nbsp; &nbsp; &nbsp; &nbsp; groups[(field, db, table, row, pos)].append((threshold, is_true))

&nbsp; &nbsp;&nbsp;for&nbsp;key, tests&nbsp;in&nbsp;groups.items():
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;len(tests) <&nbsp;3:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue
&nbsp; &nbsp; &nbsp; &nbsp; max_true =&nbsp;max((t&nbsp;for&nbsp;t, v&nbsp;in&nbsp;tests&nbsp;if&nbsp;v), default=-1)
&nbsp; &nbsp; &nbsp; &nbsp; min_false =&nbsp;min((t&nbsp;for&nbsp;t, v&nbsp;in&nbsp;tests&nbsp;if&nbsp;not&nbsp;v), default=256)

&nbsp; &nbsp; &nbsp; &nbsp; total +=&nbsp;1
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;max_true < min_false: &nbsp;# 合理区间
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; consistent +=&nbsp;1

&nbsp; &nbsp;&nbsp;if&nbsp;total ==&nbsp;0:
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;False

&nbsp; &nbsp; ratio = consistent / total
&nbsp; &nbsp;&nbsp;return&nbsp;ratio >&nbsp;0.8&nbsp;&nbsp;# 80%以上一致则通过

def&nbsp;resolve_binary_search(tests):
&nbsp; &nbsp;&nbsp;"""
&nbsp; &nbsp; 从一组 (threshold, is_true) 对中还原字符的ASCII值。

&nbsp; &nbsp; 算法:
&nbsp; &nbsp; &nbsp; max_true &nbsp;= 所有True阈值中的最大值
&nbsp; &nbsp; &nbsp; min_false = 所有False阈值中的最小值
&nbsp; &nbsp; &nbsp; 若 max_true + 1 == min_false → 值 = max_true + 1(精确命中)
&nbsp; &nbsp; &nbsp; 若 max_true == -1(全部False)→ 值 = 0(超出字符串长度)
&nbsp; &nbsp; &nbsp; 若 min_false == 256(全部True)→ 值 = max_true + 1
&nbsp; &nbsp; """
&nbsp; &nbsp; max_true =&nbsp;max((t&nbsp;for&nbsp;t, v&nbsp;in&nbsp;tests&nbsp;if&nbsp;v), default=-1)
&nbsp; &nbsp; min_false =&nbsp;min((t&nbsp;for&nbsp;t, v&nbsp;in&nbsp;tests&nbsp;if&nbsp;not&nbsp;v), default=256)

&nbsp; &nbsp;&nbsp;if&nbsp;max_true +&nbsp;1&nbsp;== min_false:
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;max_true +&nbsp;1
&nbsp; &nbsp;&nbsp;elif&nbsp;max_true == -1:
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;0&nbsp;&nbsp;# 字符串结束
&nbsp; &nbsp;&nbsp;elif&nbsp;min_false ==&nbsp;256:
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;max_true +&nbsp;1
&nbsp; &nbsp;&nbsp;else:
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 存在噪声/不一致,取最佳估计
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;max_true +&nbsp;1

# ──────────────────────── 输出格式化 ────────────────────────

def&nbsp;print_results(reconstructed, verbose=False):
&nbsp; &nbsp;&nbsp;"""打印还原结果"""
&nbsp; &nbsp;&nbsp;print("\n"&nbsp;+&nbsp;"="&nbsp;*&nbsp;65)
&nbsp; &nbsp;&nbsp;print(" &nbsp;SQL Boolean Blind Injection - Data Recovery Results")
&nbsp; &nbsp;&nbsp;print("="&nbsp;*&nbsp;65)

&nbsp; &nbsp;&nbsp;# 按表和行分组输出
&nbsp; &nbsp; tables = defaultdict(list)
&nbsp; &nbsp;&nbsp;for&nbsp;key&nbsp;in&nbsp;reconstructed:
&nbsp; &nbsp; &nbsp; &nbsp; field, db, table, row = key
&nbsp; &nbsp; &nbsp; &nbsp; tables[(db, table)].append((row, field, key))

&nbsp; &nbsp;&nbsp;for&nbsp;(db, table), entries&nbsp;in&nbsp;sorted(tables.items()):
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f"\n &nbsp;Database:&nbsp;{db}&nbsp;| Table:&nbsp;{table}")
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f" &nbsp;{'-'&nbsp;*&nbsp;50}")

&nbsp; &nbsp; &nbsp; &nbsp; rows = defaultdict(dict)
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;row, field, key&nbsp;in&nbsp;entries:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chars = reconstructed[key]
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value =&nbsp;''.join(chars[p]&nbsp;for&nbsp;p&nbsp;in&nbsp;sorted(chars.keys()))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rows[row][field] = value

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;row&nbsp;in&nbsp;sorted(rows.keys()):
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fields_str =&nbsp;' | '.join(f"{f}={v}"&nbsp;for&nbsp;f, v&nbsp;in&nbsp;sorted(rows[row].items()))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f" &nbsp;Row&nbsp;{row}:&nbsp;{fields_str}")

&nbsp; &nbsp;&nbsp;print("\n"&nbsp;+&nbsp;"="&nbsp;*&nbsp;65)

def&nbsp;print_detailed_trace(reconstructed, char_tests_cache, target_field=None, target_table=None, target_row=0):
&nbsp; &nbsp;&nbsp;"""打印详细的二分搜索轨迹"""
&nbsp; &nbsp;&nbsp;print(f"\n--- Detailed Binary Search Trace ---")

&nbsp; &nbsp;&nbsp;for&nbsp;key&nbsp;in&nbsp;sorted(char_tests_cache.keys()):
&nbsp; &nbsp; &nbsp; &nbsp; field, db, table, row, pos = key
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;target_field&nbsp;and&nbsp;field != target_field:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;target_table&nbsp;and&nbsp;table != target_table:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;row != target_row:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue

&nbsp; &nbsp; &nbsp; &nbsp; tests =&nbsp;sorted(char_tests_cache[key], key=lambda&nbsp;x: x[0])
&nbsp; &nbsp; &nbsp; &nbsp; steps =&nbsp;' '.join(f'>{t}={"T"&nbsp;if&nbsp;v&nbsp;else&nbsp;"F"}'&nbsp;for&nbsp;t, v&nbsp;in&nbsp;tests)
&nbsp; &nbsp; &nbsp; &nbsp; ascii_val = resolve_binary_search(tests)
&nbsp; &nbsp; &nbsp; &nbsp; ch =&nbsp;chr(ascii_val)&nbsp;if&nbsp;ascii_val >&nbsp;0&nbsp;else&nbsp;'(end)'
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f" &nbsp;{field}&nbsp;Pos{pos}:&nbsp;{steps}&nbsp; => ASCII&nbsp;{ascii_val}&nbsp;= \"{ch}\"")

# ──────────────────────── 主入口 ────────────────────────

def&nbsp;main():
&nbsp; &nbsp; parser = argparse.ArgumentParser(
&nbsp; &nbsp; &nbsp; &nbsp; description='SQL Boolean Blind Injection Log Analyzer',
&nbsp; &nbsp; &nbsp; &nbsp; formatter_class=argparse.RawDescriptionHelpFormatter,
&nbsp; &nbsp; &nbsp; &nbsp; epilog="""
示例:
&nbsp; # 自动检测模式
&nbsp; python sqli_blind_log_analyzer.py -f access.log

&nbsp; # 手动指定True/False响应长度
&nbsp; python sqli_blind_log_analyzer.py -f access.log --true-size 24 --false-size 47

&nbsp; # 仅还原特定表
&nbsp; python sqli_blind_log_analyzer.py -f access.log --table user --field username,password
&nbsp; &nbsp; &nbsp; &nbsp; """
&nbsp; &nbsp; )
&nbsp; &nbsp; parser.add_argument('-f',&nbsp;'--file', required=True,&nbsp;help='日志文件路径')
&nbsp; &nbsp; parser.add_argument('--true-size',&nbsp;type=int, default=None,&nbsp;help='True条件对应的响应体长度')
&nbsp; &nbsp; parser.add_argument('--false-size',&nbsp;type=int, default=None,&nbsp;help='False条件对应的响应体长度')
&nbsp; &nbsp; parser.add_argument('--no-auto-detect', action='store_true',&nbsp;help='禁用自动检测')
&nbsp; &nbsp; parser.add_argument('--table',&nbsp;type=str, default=None,&nbsp;help='只还原指定表')
&nbsp; &nbsp; parser.add_argument('--field',&nbsp;type=str, default=None,&nbsp;help='只还原指定字段(逗号分隔)')
&nbsp; &nbsp; parser.add_argument('-v',&nbsp;'--verbose', action='store_true',&nbsp;help='显示详细二分搜索轨迹')

&nbsp; &nbsp; args = parser.parse_args()

&nbsp; &nbsp; reconstructed = parse_log(
&nbsp; &nbsp; &nbsp; &nbsp; args.file,
&nbsp; &nbsp; &nbsp; &nbsp; true_size=args.true_size,
&nbsp; &nbsp; &nbsp; &nbsp; false_size=args.false_size,
&nbsp; &nbsp; &nbsp; &nbsp; auto_detect=not&nbsp;args.no_auto_detect
&nbsp; &nbsp; )

&nbsp; &nbsp;&nbsp;# 过滤
&nbsp; &nbsp;&nbsp;if&nbsp;args.table&nbsp;or&nbsp;args.field:
&nbsp; &nbsp; &nbsp; &nbsp; fields_set =&nbsp;set(args.field.split(','))&nbsp;if&nbsp;args.field&nbsp;else&nbsp;None
&nbsp; &nbsp; &nbsp; &nbsp; to_remove = []
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;key&nbsp;in&nbsp;reconstructed:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; field, db, table, row = key
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;args.table&nbsp;and&nbsp;table != args.table:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to_remove.append(key)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;fields_set&nbsp;and&nbsp;field&nbsp;not&nbsp;in&nbsp;fields_set:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to_remove.append(key)
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;key&nbsp;in&nbsp;to_remove:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;del&nbsp;reconstructed[key]

&nbsp; &nbsp; print_results(reconstructed, verbose=args.verbose)

if&nbsp;__name__ ==&nbsp;'__main__':
&nbsp; &nbsp; main()

使用方法

bash

# 基础用法:自动检测True/False并还原所有字段
python sqli_blind_log_analyzer.py -f access.log

# 手动指定响应长度(当自动检测不确定时)
python sqli_blind_log_analyzer.py -f access.log --true-size 24 --false-size 47

# 只还原user表的username和password字段
python sqli_blind_log_analyzer.py -f access.log --table user --field username,password

试试效果

#

第二问:

实际上这才是试题的第一问,可惜做出来答案不对,这里记录一下做题的过程,也有回来用ai溯源的新的代码:

其实只要第一个做出来了,这个就很简单了,这里就不放代码,免得有水文的嫌疑

不过很可惜,这问也没得分,因为md5计算不对,不过因为数据太多,感觉哪儿有点小问题导致的,就不折腾了。

第三问:

这题没做,不过可惜了,这题真应该做的,因为回来复盘,这个答案个位数,计算md5应该不会错/(ㄒoㄒ)/~~

卢恩算法:

这个也就名字唬人,实际上就是模10,数据安全最基数的算法之一(还有一个是计算身份证校验码的)

这是ai优化后的,感觉还没有我写的简单:

python

def&nbsp;luhn_check_optimized(card_number):
&nbsp; &nbsp;&nbsp;"""
&nbsp; &nbsp; 优化版卢恩算法校验,使用反向遍历和更高效的计算方式
&nbsp; &nbsp; """
&nbsp; &nbsp;&nbsp;# 清洗输入
&nbsp; &nbsp; cleaned =&nbsp;''.join(filter(str.isdigit,&nbsp;str(card_number)))
&nbsp; &nbsp;&nbsp;if&nbsp;not&nbsp;cleaned&nbsp;or&nbsp;len(cleaned) <&nbsp;12: &nbsp;# 银行卡号通常至少12位
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;False

&nbsp; &nbsp; total =&nbsp;0
&nbsp; &nbsp;&nbsp;# 反转字符串,从右向左处理
&nbsp; &nbsp; reversed_num = cleaned[::-1]

&nbsp; &nbsp;&nbsp;for&nbsp;i, digit&nbsp;in&nbsp;enumerate(reversed_num):
&nbsp; &nbsp; &nbsp; &nbsp; n =&nbsp;int(digit)
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 偶数位(反向后的第2、4、6...位,即原卡号从右数偶数位)
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;i %&nbsp;2&nbsp;==&nbsp;1:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n *=&nbsp;2
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 如果大于9,各位数字相加
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;n >&nbsp;9:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n = n //&nbsp;10&nbsp;+ n %&nbsp;10
&nbsp; &nbsp; &nbsp; &nbsp; total += n

&nbsp; &nbsp;&nbsp;return&nbsp;total %&nbsp;10&nbsp;==&nbsp;0

小结

这次比赛,感觉运气也是背到家,好几个感觉做的是正确的,但是最后计算md5提交答案,都错了,郁闷。


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:一只岸上的鱼 一只岸上的鱼 一只岸上的鱼《数据泄露——江苏省第四届数据安全技术应用职业技能竞赛初赛》

评论:0   参与:  0