做了什么 - 确认 collect 的加密算法就是教科书 XTEA (32 轮, delta=0x9E3779B9), 并证明 crypto.py 原有的"带加盐"写法只是把两个密钥字折叠: K' = [k0, k1+salt1, k2+salt2, k3] - tdc_worker.js 新增 captureKey 模式: 正则改写 VM 的 ADD/XOR opcode 为带日志版本, 用反向引用自动识别栈变量名 (样本=g/雨云实时=j/1ms=M, 版本无关); 匹配数不为 1 时显式报错, 不静默失败 - 密钥反推: (sum + K[j]) 是一次 ADD, 两操作数必有一个等于 r*DELTA, 另一个就是密钥字; 再对 Top-N 候选做 4! 排列 + 明文内容特征验证 - 新增 recover_payload_template / generate_collect_from_template: 运行时标定一次明文模板, 之后轨迹生成/组包/加密/编码全部在 Python - 新增 tcaptcha/proxy.py 代理提取, client 支持 --proxy-api 遇 12 自动换 IP 为什么 - 服务端只认 collect 的解密结果, 而密钥是每构建随机的; 把算法做成纯 Python 后, 只有"取密钥"依赖 Node, 抗发版能力最强 怎么验证的 - 纯 Python XTEA 加密结果与真实 tdc.js 产物前 48 字节逐字节一致 - 密钥按构建固定的证据: 同一脚本 3 次运行密文首块均为 f6a24e3e4fb5dd2b - 三份脚本 (样本/雨云实时/1ms实时) 均成功复原密钥 - 雨云 aid 端到端: 纯 Python 出包 -> errorCode=0 + 真实 ticket - 回归测试: tcaptcha/tests/test_xtea_key.py 11 项断言全过, 文字点选求解 8/8; 新增 tcaptcha/selftest.py 一键复验 已知未解 - 1ms aid=195672344 在答案正确时仍返回 errorCode=12; 已排除密钥、 遥测引擎、出口 IP (4 个住宅代理)、短时频控、静默窗口
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
文字点选求解器回归测试 (真实线上样本)
|
|
|
|
fixtures 里的 6 张图全部来自真实线上环境:
|
|
* har_round1..4 —— 用户 `点选.har` 抓包中的 4 道题 (672x480 背景图)
|
|
* live_probe —— 本次逆向期间实时抓取的一道题
|
|
* live_hard_rare_char —— 含生僻字 "筹" 且整题带斜切变形, 用于验证 ddddocr+PP-OCRv4 集成
|
|
|
|
运行:
|
|
uv run python -m tcaptcha.tests.test_glyph_solver
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
FIXTURES = Path(__file__).resolve().parent / "fixtures"
|
|
MANIFEST = FIXTURES / "manifest.json"
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent.parent
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from tcaptcha.glyph_solver import TextClickSolver, parse_instruction # noqa: E402
|
|
|
|
TOLERANCE = 22 # 像素容差 (汉字包围盒中心 vs 人工标注中心)
|
|
|
|
|
|
def run(verbose: bool = False) -> int:
|
|
logging.basicConfig(level=logging.WARNING)
|
|
cases = json.loads(MANIFEST.read_text(encoding="utf-8"))
|
|
solver = TextClickSolver()
|
|
passed = 0
|
|
failed = []
|
|
|
|
for case in cases:
|
|
img = (FIXTURES / case["image"]).read_bytes()
|
|
result = solver.solve_ex(img, case["instruction"])
|
|
ok_points = result.ok and all(
|
|
abs(p[0] - e[0]) <= TOLERANCE and abs(p[1] - e[1]) <= TOLERANCE
|
|
for p, e in zip(result.points, case["expected_points"])
|
|
)
|
|
if verbose:
|
|
print(f" {case['image']:24s} {case['instruction']}")
|
|
print(f" pred={result.points}")
|
|
print(f" exp ={case['expected_points']} post={result.posterior:.4f} "
|
|
f"{'OK' if ok_points else 'MISMATCH'}")
|
|
if ok_points:
|
|
passed += 1
|
|
else:
|
|
failed.append((case["image"], result.points, case["expected_points"]))
|
|
|
|
total = len(cases)
|
|
print(f"\n文字点选求解器回归: {passed}/{total} 通过")
|
|
for image, pred, exp in failed:
|
|
print(f" ✗ {image}: pred={pred} exp={exp}")
|
|
return 0 if passed == total else 1
|
|
|
|
|
|
def test_parse_instruction():
|
|
"""提示语解析的边界用例 (图标点选/滑块的模板串不能解析出目标字)"""
|
|
assert parse_instruction("请依次点击:虫 呈 般") == ["虫", "呈", "般"]
|
|
assert parse_instruction("请依次点击:虫呈般") == ["虫", "呈", "般"]
|
|
assert parse_instruction("请依次点击:") == [] # 图标点选
|
|
assert parse_instruction("拖动下方滑块完成拼图") == [] # 滑块
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("-v", "--verbose", action="store_true")
|
|
args = ap.parse_args()
|
|
test_parse_instruction()
|
|
print("提示语解析边界用例: OK")
|
|
sys.exit(run(verbose=args.verbose))
|