做了什么 - 确认 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 个住宅代理)、短时频控、静默窗口
92 lines
3.0 KiB
Python
92 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
代理 IP 提取与格式化 (用于绕过腾讯天御的 IP 级滚动风控)
|
|
|
|
腾讯验证码按出口 IP 做滚动窗口风控, 触发时会返回 `errorCode=12` (f_limit)。
|
|
本模块从常见的「代理 IP 提取 API」取一个可用代理, 供 `TencentCaptchaClient(proxy=...)`
|
|
与 `OneMsAdapter(proxy=...)` 使用。
|
|
|
|
已适配的返回格式:
|
|
* JSON: {"status":100,"data":[{"ip":"1.2.3.4","port":"8080"}]} (讯客 xkdaili 等)
|
|
* JSON: {"data":{"ip":"1.2.3.4","port":8080}} / [{"ip":..,"port":..}]
|
|
* 纯文本: 一行一个 "1.2.3.4:8080" 或 "1.2.3.4,8080"
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from typing import List, Optional
|
|
|
|
import httpx
|
|
|
|
_IP_PORT_RE = re.compile(r"(\d{1,3}(?:\.\d{1,3}){3})\s*[:,]\s*(\d{1,5})")
|
|
|
|
|
|
def format_proxy(ip: str, port, scheme: str = "http") -> str:
|
|
return f"{scheme}://{ip}:{port}"
|
|
|
|
|
|
def parse_proxies(payload: str, scheme: str = "http") -> List[str]:
|
|
"""从 API 返回体里解析出全部代理 (兼容 JSON 与纯文本两种格式)"""
|
|
out: List[str] = []
|
|
text = (payload or "").strip()
|
|
if not text:
|
|
return out
|
|
|
|
try:
|
|
import json
|
|
|
|
data = json.loads(text)
|
|
|
|
def walk(node):
|
|
if isinstance(node, dict):
|
|
ip = node.get("ip") or node.get("host") or node.get("server")
|
|
port = node.get("port")
|
|
if ip and port:
|
|
out.append(format_proxy(str(ip), port, scheme))
|
|
for key in ("data", "result", "proxy", "list", "proxies"):
|
|
if key in node:
|
|
walk(node[key])
|
|
elif isinstance(node, list):
|
|
for item in node:
|
|
walk(item)
|
|
|
|
walk(data)
|
|
if out:
|
|
return out
|
|
except Exception:
|
|
pass
|
|
|
|
for ip, port in _IP_PORT_RE.findall(text):
|
|
out.append(format_proxy(ip, port, scheme))
|
|
return out
|
|
|
|
|
|
def fetch_proxy(api_url: str, scheme: str = "http", timeout: float = 15.0) -> Optional[str]:
|
|
"""调用代理提取 API 并返回第一个可用代理字符串, 例如 http://1.2.3.4:8080"""
|
|
resp = httpx.get(api_url, timeout=timeout, trust_env=False, follow_redirects=True)
|
|
proxies = parse_proxies(resp.text, scheme=scheme)
|
|
return proxies[0] if proxies else None
|
|
|
|
|
|
def check_proxy(proxy: str, url: str = "https://turing.captcha.qcloud.com/",
|
|
timeout: float = 20.0) -> bool:
|
|
"""探测代理是否可用 (能连上目标域名即可, 不判断业务状态码)"""
|
|
try:
|
|
httpx.get(url, proxy=proxy, timeout=timeout, trust_env=False,
|
|
follow_redirects=True, headers={"User-Agent": "Mozilla/5.0"})
|
|
return True
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
|
|
ap = argparse.ArgumentParser(description="从代理 API 取一个可用代理")
|
|
ap.add_argument("api_url")
|
|
ap.add_argument("--scheme", default="http")
|
|
args = ap.parse_args()
|
|
proxy = fetch_proxy(args.api_url, scheme=args.scheme)
|
|
print(proxy or "未取到代理")
|