feat(huya): 分身 CK 支持 cred0 解密补全,WSS 帧改为 JCE WebSocketCommand

- scripts/huya_clone_ck.py: root 读取小X分身/真身 WebView Cookie,默认
  用 AES-128-ECB(UDB 主密钥前 16B) 解 cred0 注入 udb_cred,新增
  --anon-device 补匿名设备字段、--no-cred0 退回旧行为
- core/huya/wss_client.py: 帧层改用浏览器 HUYA.WebSocketCommand(JCE)
  结构,vData 直接放 Wup 原包,按 WUP iRequestId 匹配响应,初始化顺序
  对齐 RegisterGroup→wsLaunch→VerifyCookie→getConfig→UpdateUserExps
- tests: 帧级断言改为新结构,假 WS 按 requestId 兑现
- docs: 新增分身 CK 提取、HAR 提取 CK 与积分中心说明

实测:四个分身 cred0 解出 udb_cred(39/43 字段),WSS
PlayMallUI.queryAllocation 返回 code=200、18 个商品;tests -k huya 394 passed
This commit is contained in:
yml2213
2026-10-26 11:23:29 +08:00
parent 6fc453017c
commit 03bc0818dd
9 changed files with 1188 additions and 156 deletions
+27 -15
View File
@@ -29,12 +29,13 @@ COOKIE = f"udb_uid={UID}; yyuid={UID}; guid={GUID}"
PID = 1199650619883
# 抓包字面值(不要引用实现常量,否则断言会与实现一起漂移)
POINTS_UA_LITERAL = "webh5&0.0.1&websocket&&h5_/points.html"
# 旧版本在 vData 末尾拼的尾部字节;JCE 帧不需要,保留常量用于确认已移除
TAIL_LITERAL = bytes.fromhex("2c36004c5c6600")
BIZ_PARAMS_LITERAL = '{ "jifencenter": 1 }'
# 抓包实测:RegisterGroup(live:0) 与 UpdateUserExps(版本 map) 的 body 逐字节一致
HEARTBEAT_BODY = bytes.fromhex("09000106066c6976653a3016002c36004c5c6600")
UPDATE_EXPS_BODY = bytes.fromhex("0800010605353836363416063130373236332c36004c5c6600")
HEARTBEAT_BODY = bytes.fromhex("09000106066c6976653a301600")
UPDATE_EXPS_BODY = bytes.fromhex("080001060535383636341606313037323633")
CONFIG_VERSIONS = {"58664": "107263"}
@@ -48,10 +49,17 @@ class _FakeWs:
async def send(self, data: bytes):
self.sent.append(data)
while self.client.rpc_queue:
future = self.client.rpc_queue.popleft()
if not future.done():
future.set_result(self.response)
message = WssMessage.decode(data)
if message.command != WssCommand.RPC_REQUEST:
return
try:
wup = WupResponse()
wup.decode(_extract_wup(message.body))
except Exception: # noqa: BLE001 测试替身:无法解析的帧不兑现
return
future = self.client._pending.pop(wup.iRequestId, None)
if future is not None and not future.done():
future.set_result(self.response)
def last_body(self) -> bytes:
return WssMessage.decode(self.sent[-1]).body
@@ -106,8 +114,9 @@ def test_register_group_frame_matches_capture():
await client.send_heartbeat()
message = WssMessage.decode(client.ws.sent[-1])
assert message.command == WssCommand.HEARTBEAT_SEND
assert message.sequence == 0x1D00000D
assert message.sequence == 0
assert message.body == HEARTBEAT_BODY
assert not message.body.endswith(TAIL_LITERAL)
asyncio.run(run())
@@ -119,8 +128,8 @@ def test_shop_ws_launch_carries_real_identity_and_points_ua():
message = WssMessage.decode(client.ws.sent[-1])
assert message.command == WssCommand.RPC_REQUEST
# 抓包:wsLaunch 帧 seq=0x1d000100,iRequestId=-1
assert message.sequence == 0x1D000100
# JCE 帧 lRequestId 固定 0,真正的请求号是 WUP iRequestId=-1
assert message.sequence == 0
wup = WupResponse()
wup.decode(_extract_wup(message.body))
assert wup.iRequestId == -1
@@ -182,8 +191,7 @@ def test_create_order_v5_matches_points_capture():
)
message = WssMessage.decode(client.ws.sent[-1])
# 抓包:下单帧用 0x1d000108(其余业务帧 0x1d000107)
assert message.sequence == 0x1D000108
assert message.command == WssCommand.RPC_REQUEST
decoded = _decode_wup_body(message.body)
assert (decoded["servant"], decoded["func"]) == (
@@ -223,7 +231,7 @@ def test_pay_order_submit_v5_callback_points_page():
)
message = WssMessage.decode(client.ws.sent[-1])
assert message.sequence == 0x1D000108
assert message.command == WssCommand.RPC_REQUEST
decoded = _decode_wup_body(message.body)
assert (decoded["servant"], decoded["func"]) == (
@@ -338,11 +346,15 @@ def test_new_points_rpcs_match_capture():
asyncio.run(run())
def test_confirm_frame_ends_with_capture_tail():
def test_confirm_frame_carries_version_map_without_legacy_tail():
async def run():
client = _points_client()
await client.send_confirm({})
assert client.ws.last_body().endswith(TAIL_LITERAL)
await client.send_confirm(CONFIG_VERSIONS)
message = WssMessage.decode(client.ws.sent[-1])
assert message.command == WssCommand.CONFIRM_SEND
assert message.sequence == 0
assert message.body == UPDATE_EXPS_BODY
assert not message.body.endswith(TAIL_LITERAL)
asyncio.run(run())