luckfun233 commited on
Commit ·
5db4eb7
1
Parent(s): 90df7df
feat: 更新数美 SDK 相关文档,添加复现手册及工具链,修复解析逻辑
Browse files- deepseek-recall-research.md +43 -0
- docs/shumei-device-id-research.md +78 -0
- docs/web-endpoint-upgrade.md +1 -1
- internal/deepseek/client/client_auth.go +15 -1
- internal/deepseek/protocol/constants_shared.json +1 -1
- internal/deepseek/protocol/constants_web.json +3 -3
- scripts/shumei-re/capture_payload.js +319 -0
- scripts/shumei-re/crack_des_keys.py +93 -0
- scripts/shumei-re/decode_payload.py +114 -0
deepseek-recall-research.md
CHANGED
|
@@ -446,3 +446,46 @@ data: {"click_behavior":"none","auto_resume":false}
|
|
| 446 |
```
|
| 447 |
|
| 448 |
**对比结论**:正常完成时最后一个数据事件是 `status=FINISHED`,撤回时则多出一个含 `CONTENT_FILTER` 的 BATCH 事件。这是唯一差异。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
```
|
| 447 |
|
| 448 |
**对比结论**:正常完成时最后一个数据事件是 `status=FINISHED`,撤回时则多出一个含 `CONTENT_FILTER` 的 BATCH 事件。这是唯一差异。
|
| 449 |
+
|
| 450 |
+
---
|
| 451 |
+
|
| 452 |
+
## 附录 C:联网模式(DEEP_SEARCH)的片段结构与解析坑位
|
| 453 |
+
|
| 454 |
+
> 来源:2026-09-25 的真实联网抓包 + `internal/sse/search_mode_test.go` 回归用例。
|
| 455 |
+
> 背景:解析器曾把"片段级 status"误判成"整条流结束",导致联网模式正文为空。
|
| 456 |
+
|
| 457 |
+
### C.1 片段类型
|
| 458 |
+
|
| 459 |
+
| 片段 type | 含义 | 是否产出正文/思考 |
|
| 460 |
+
|-----------|------|------------------|
|
| 461 |
+
| `THINK` / `THINKING` | 各阶段思考过程(联网时按 `stage_id` 分多段) | 思考内容 |
|
| 462 |
+
| `RESPONSE` | 回答正文(联网时可能晚于多个搜索片段才出现) | 正文 |
|
| 463 |
+
| `SEARCH` | 联网搜索卡片(非思考流程使用该类型) | ❌ 前端卡片文案 |
|
| 464 |
+
| `TOOL_SEARCH` | 联网搜索卡片(思考流程使用该类型),带 `queries`/`results` | ❌ |
|
| 465 |
+
| `TOOL_OPEN` | "打开网页"卡片,带 `result` | ❌ |
|
| 466 |
+
|
| 467 |
+
其余类型(`TOOL_*` 前缀、`SEARCH*` 前缀)按卡片处理,不进入正文。
|
| 468 |
+
|
| 469 |
+
### C.2 坑位一:patch 路径是相对的
|
| 470 |
+
|
| 471 |
+
```json
|
| 472 |
+
{"p":"response/fragments/-1","o":"BATCH","v":[{"p":"status","v":"FINISHED"},{"p":"content","v":"搜索到 19 个网页"}]}
|
| 473 |
+
```
|
| 474 |
+
|
| 475 |
+
内层 `p:"status"` 实际指向 `response/fragments/-1/status`(**片段**状态),
|
| 476 |
+
不是 `response/status`(**整条流**结束)。解析时必须先把外层路径与内层路径拼起来再判断,
|
| 477 |
+
否则会在搜索阶段就把整条流判定为结束——表现为:联网模式思考内容只收到第一阶段,正文为空。
|
| 478 |
+
|
| 479 |
+
### C.3 坑位二:`-1` 指的是"最新追加的片段"
|
| 480 |
+
|
| 481 |
+
`fragments/-1` 随 `fragments APPEND` 不断变化:思考片段 → 搜索卡片 → 打开网页卡片 → 回答片段。
|
| 482 |
+
所以必须"先处理片段类型切换,再决定这段 content 归思考还是正文",
|
| 483 |
+
否则会把卡片文案("搜索到 N 个网页")混进回答,或把回答误判成思考。
|
| 484 |
+
|
| 485 |
+
### C.4 其他要点
|
| 486 |
+
|
| 487 |
+
- `results` 字段(`fragments/-N/results`)是搜索结果数组(`url`/`title`/`snippet`),
|
| 488 |
+
不含 `content` 键,不应参与正文解析。
|
| 489 |
+
- 根快照(首个 `data:` 事件)里就带着起始片段(思考流程为 `THINK`、非思考流程为 `SEARCH`),
|
| 490 |
+
片段类型状态要从这里初始化。
|
| 491 |
+
- `response/conversation_mode` = `DEEP_SEARCH` 可作为"本次是联网回答"的判定信号。
|
docs/shumei-device-id-research.md
CHANGED
|
@@ -602,3 +602,81 @@ uid -> md5(uid)[:16] = priId (AES 密钥)
|
|
| 602 |
登录侧行为:`device_id` 不再使用本地伪造值(旧实现的伪 Blob 会被判定为
|
| 603 |
`RISK_DEVICE_DETECTED`);改为向数美申请真实签发的 SMID 并写入账号配置复用,
|
| 604 |
同一账号后续登录保持设备身份稳定。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
登录侧行为:`device_id` 不再使用本地伪造值(旧实现的伪 Blob 会被判定为
|
| 603 |
`RISK_DEVICE_DETECTED`);改为向数美申请真实签发的 SMID 并写入账号配置复用,
|
| 604 |
同一账号后续登录保持设备身份稳定。
|
| 605 |
+
|
| 606 |
+
---
|
| 607 |
+
|
| 608 |
+
## 十六、复现手册(工具链 + 坑位清单)
|
| 609 |
+
|
| 610 |
+
> 本节是"下次协议再变时怎么快速跟上"的操作手册,工具已随仓库提供。
|
| 611 |
+
|
| 612 |
+
### 16.1 工具(`scripts/shumei-re/`)
|
| 613 |
+
|
| 614 |
+
| 工具 | 用途 | 用法 |
|
| 615 |
+
|------|------|------|
|
| 616 |
+
| `capture_payload.js` | Node 沙箱复跑真实 SDK,拦截并解密上报体(全程离线) | `node scripts/shumei-re/capture_payload.js <fp.min.js 路径> [输出目录]` |
|
| 617 |
+
| `decode_payload.py` | 解密任意 payload 并校验 `er`/tn | `python scripts/shumei-re/decode_payload.py payload.json --uid <uid> [--dump]` |
|
| 618 |
+
| `crack_des_keys.py` | 用 SDK 字符串池盲破解各字段 DES 密钥 | `python scripts/shumei-re/crack_des_keys.py fp.min.js decrypted.json [--json]` |
|
| 619 |
+
|
| 620 |
+
Python 工具依赖 `pycryptodome`(`pip install pycryptodome`)。
|
| 621 |
+
|
| 622 |
+
产物:
|
| 623 |
+
- `payload.json` —— 外层请求体 `{appId, organization, ep, data, os, encode, compress}`
|
| 624 |
+
- `decrypted.json` —— 解密后的明文指纹对象(混淆字段名 + 密文/明文值)
|
| 625 |
+
- `tn_parts.json` —— tn 拼接串的分段,用于与 `decrypted.json` 逐段对齐
|
| 626 |
+
|
| 627 |
+
### 16.2 完整流程(按顺序做,可复制到下一次)
|
| 628 |
+
|
| 629 |
+
1. **抓包**:Chrome DevTools → Network → 勾选"保留日志",登录一次并触发设备指纹,
|
| 630 |
+
然后"导出 HAR(包含内容)"。⚠️ 必须含响应体:SDK 脚本本身就是从 HAR 里取出来的。
|
| 631 |
+
2. **定位 SDK**:在页面主包(`fe-static.deepseek.com/chat/static/main.*.js`)里搜
|
| 632 |
+
`_smConf` / `deviceprofile`,当前加载地址是 `https://chat.deepseek.com/static/fp.min.js`。
|
| 633 |
+
⚠️ 直接 `curl` 该地址常常拿到 SPA 的 HTML(2023 字节),从 HAR 的
|
| 634 |
+
`log.entries[].response.content.text` 提取才可靠。
|
| 635 |
+
3. **跑沙箱**:`capture_payload.js` → 得到 `payload.json` / `decrypted.json` / `tn_parts.json`。
|
| 636 |
+
⚠️ 脚本把 `Math.random` 固定为 0.5,因此 uid 可预测
|
| 637 |
+
(`88888888-8888-4888-8888-888888888888`);换了固定策略就要同步脚本里的 UID 常量。
|
| 638 |
+
4. **校验 tn**:`decode_payload.py`,输出"一致 ✅"才说明拼接语义没变。
|
| 639 |
+
⚠️ 值为 `undefined` 的字段(当前是 `yu`)不在 JSON 里,但仍以字符串 `undefined`
|
| 640 |
+
参与 tn 拼接,缺了它一定校验失败。
|
| 641 |
+
5. **破解密钥**:`crack_des_keys.py`,把命中的密钥回填到
|
| 642 |
+
`internal/shumei/confusion.go` 的 `fieldDESKey` 表。
|
| 643 |
+
6. **服务端交叉验证**:把 `payload.json` 原样 POST 到
|
| 644 |
+
`https://fp-it-acc.portal101.cn/deviceprofile/v4`,返回 `1100` 才算格式正确:
|
| 645 |
+
|
| 646 |
+
```bash
|
| 647 |
+
curl -s -X POST https://fp-it-acc.portal101.cn/deviceprofile/v4 \
|
| 648 |
+
-H 'Content-Type: application/json;charset=UTF-8' \
|
| 649 |
+
--data-binary @payload.json
|
| 650 |
+
# 期望: {"code":1100,"detail":{"deviceId":"..."}}
|
| 651 |
+
```
|
| 652 |
+
7. **固化回归**:把真实产物追加成 `internal/shumei/device_id_test.go` 的黄金向量,
|
| 653 |
+
跑 `go test ./internal/shumei/...` 确认锁定。
|
| 654 |
+
|
| 655 |
+
### 16.3 坑位清单(本次全部踩过)
|
| 656 |
+
|
| 657 |
+
1. **`1902` 不是网络问题**,而是"数据不合法"。换 host(portal101 / fengkongcloud)、
|
| 658 |
+
换 `encode`/`compress`、换 `Content-Type`、换 UA 全都无效——已做过矩阵排除,
|
| 659 |
+
问题只可能在内容层(协议号 / 字段集 / tn / 编码)。
|
| 660 |
+
2. **`ep` 必须是 Base64**(JSEncrypt 的输出),不是 hex。旧实现输出 hex 是错的。
|
| 661 |
+
3. **tn 不是 `key=value` 拼接**,而是"只拼接值";数字 ×0x2710;嵌套对象记
|
| 662 |
+
`[object Object]`(不递归);数组按逗号连接(null/undefined → 空串)。
|
| 663 |
+
4. **ZeroPadding 语义**:CryptoJS 的计算式在"长度已对齐"时补 0 字节(不补整块),
|
| 664 |
+
DES 与 AES 都是如此;Go 侧不要无条件补块。
|
| 665 |
+
5. **空字符串的加密结果是空串**:字段保留但值为空,不要当成"缺字段"。
|
| 666 |
+
6. **密钥不一定挨着字段**:部分字段的密钥藏在采集函数里,例如 clientSize 字段
|
| 667 |
+
`lp` 的密钥是 `6wvopcsc`、status 字段 `fu` 的是 `a3l1z50h`,肉眼扫容易漏。
|
| 668 |
+
7. **vm 沙箱有独立内建对象**:劫持 `Array.prototype.join` 之类必须注入到沙箱内部
|
| 669 |
+
(`vm.runInContext`),在主进程打补丁无效。
|
| 670 |
+
8. **字段明文/密文混合**:`cdp`、`maxTouchPoints`、`connectionRtt`、`cpucount`、
|
| 671 |
+
`battery`、`incognito` 等是明文,别一律按密文猜。
|
| 672 |
+
9. **旧协议产物会被直接拒绝**:ConfusionInfo + `protocol=4` 那套已经不生效,
|
| 673 |
+
旧文档只能当历史参考。
|
| 674 |
+
10. **device_id 必须是服务端签发的**:登录时用假值/占位值 →
|
| 675 |
+
`RISK_DEVICE_DETECTED`(biz_code=11);真实 SMID 无论 web 还是安卓登录都可通过。
|
| 676 |
+
|
| 677 |
+
### 16.4 相关:DeepSeek 流式协议(SSE)的同类坑
|
| 678 |
+
|
| 679 |
+
数美之外,本次还修过一个同源问题:DeepSeek 的 SSE 也使用"相对 patch 路径",
|
| 680 |
+
`response/fragments/-1` 下的 `{p:"status", v:"FINISHED"}` 是**片段级状态**,
|
| 681 |
+
不是整条流结束;把它当成 `response/status` 会让联网模式在搜索阶段提前终止、
|
| 682 |
+
正文为空。片段类型与解析规则见 `deepseek-recall-research.md` 附录 C。
|
docs/web-endpoint-upgrade.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
|
| 9 |
| 特性 | Android端 | Web端 |
|
| 10 |
|------|-----------|-------|
|
| 11 |
-
| User-Agent | `DeepSeek/2.
|
| 12 |
| TLS指纹 | Safari | Chrome (HTTP/2) |
|
| 13 |
| x-client-platform | `android` | `web` |
|
| 14 |
| device_id | 数美签发的真实 device_id(与 Web 端同一套签发逻辑) | 数美签发的真实 device_id |
|
|
|
|
| 8 |
|
| 9 |
| 特性 | Android端 | Web端 |
|
| 10 |
|------|-----------|-------|
|
| 11 |
+
| User-Agent | `DeepSeek/2.5.2 Android/32` | Chrome 150 / Edge 150 浏览器 UA |
|
| 12 |
| TLS指纹 | Safari | Chrome (HTTP/2) |
|
| 13 |
| x-client-platform | `android` | `web` |
|
| 14 |
| device_id | 数美签发的真实 device_id(与 Web 端同一套签发逻辑) | 数美签发的真实 device_id |
|
internal/deepseek/client/client_auth.go
CHANGED
|
@@ -29,7 +29,7 @@ func (c *Client) Login(ctx context.Context, acc config.Account) (string, error)
|
|
| 29 |
func (c *Client) loginWithDevice(ctx context.Context, acc config.Account, regenerated bool) (string, error) {
|
| 30 |
clients := c.requestClientsForAccount(acc)
|
| 31 |
platform := c.Store.PlatformMode()
|
| 32 |
-
deviceID :=
|
| 33 |
if deviceID == "" || regenerated {
|
| 34 |
issued, err := c.issueDeviceID(ctx, acc)
|
| 35 |
if err != nil {
|
|
@@ -87,6 +87,20 @@ func (c *Client) loginWithDevice(ctx context.Context, acc config.Account, regene
|
|
| 87 |
return token, nil
|
| 88 |
}
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
// issueDeviceID 向数美申请一个真实签发的设备画像 ID(形如 "B...")。
|
| 91 |
func (c *Client) issueDeviceID(ctx context.Context, acc config.Account) (string, error) {
|
| 92 |
id, err := shumei.GetDeviceID(ctx)
|
|
|
|
| 29 |
func (c *Client) loginWithDevice(ctx context.Context, acc config.Account, regenerated bool) (string, error) {
|
| 30 |
clients := c.requestClientsForAccount(acc)
|
| 31 |
platform := c.Store.PlatformMode()
|
| 32 |
+
deviceID := c.persistedDeviceID(acc)
|
| 33 |
if deviceID == "" || regenerated {
|
| 34 |
issued, err := c.issueDeviceID(ctx, acc)
|
| 35 |
if err != nil {
|
|
|
|
| 87 |
return token, nil
|
| 88 |
}
|
| 89 |
|
| 90 |
+
// persistedDeviceID 返回账号当前生效的 device_id。以配置存储中的值为准:
|
| 91 |
+
// 调用方传入的 Account 可能是较早的快照,若直接按"空则新签发"处理,
|
| 92 |
+
// 会导致同一账号反复换设备身份。
|
| 93 |
+
func (c *Client) persistedDeviceID(acc config.Account) string {
|
| 94 |
+
if c.Store != nil && acc.Identifier() != "" {
|
| 95 |
+
if fresh, ok := c.Store.FindAccount(acc.Identifier()); ok {
|
| 96 |
+
if v := strings.TrimSpace(fresh.DeviceID); v != "" {
|
| 97 |
+
return v
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
return strings.TrimSpace(acc.DeviceID)
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
// issueDeviceID 向数美申请一个真实签发的设备画像 ID(形如 "B...")。
|
| 105 |
func (c *Client) issueDeviceID(ctx context.Context, acc config.Account) (string, error) {
|
| 106 |
id, err := shumei.GetDeviceID(ctx)
|
internal/deepseek/protocol/constants_shared.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
"client": {
|
| 3 |
"name": "DeepSeek",
|
| 4 |
"platform": "android",
|
| 5 |
-
"version": "2.
|
| 6 |
"android_api_level": "32",
|
| 7 |
"locale": "zh_CN"
|
| 8 |
},
|
|
|
|
| 2 |
"client": {
|
| 3 |
"name": "DeepSeek",
|
| 4 |
"platform": "android",
|
| 5 |
+
"version": "2.5.2",
|
| 6 |
"android_api_level": "32",
|
| 7 |
"locale": "zh_CN"
|
| 8 |
},
|
internal/deepseek/protocol/constants_web.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
"client": {
|
| 3 |
"name": "DeepSeek",
|
| 4 |
"platform": "web",
|
| 5 |
-
"version": "2.
|
| 6 |
"locale": "zh_CN"
|
| 7 |
},
|
| 8 |
"base_headers": {
|
|
@@ -11,12 +11,12 @@
|
|
| 11 |
"Content-Type": "application/json",
|
| 12 |
"accept-encoding": "gzip, deflate, br, zstd",
|
| 13 |
"accept-charset": "UTF-8",
|
| 14 |
-
"x-app-version": "2.
|
| 15 |
"x-client-bundle-id": "com.deepseek.chat",
|
| 16 |
"x-client-locale": "zh_CN",
|
| 17 |
"x-client-platform": "web",
|
| 18 |
"x-client-timezone-offset": "28800",
|
| 19 |
-
"x-client-version": "2.
|
| 20 |
},
|
| 21 |
"skip_contains_patterns": [
|
| 22 |
"quasi_status",
|
|
|
|
| 2 |
"client": {
|
| 3 |
"name": "DeepSeek",
|
| 4 |
"platform": "web",
|
| 5 |
+
"version": "2.5.0",
|
| 6 |
"locale": "zh_CN"
|
| 7 |
},
|
| 8 |
"base_headers": {
|
|
|
|
| 11 |
"Content-Type": "application/json",
|
| 12 |
"accept-encoding": "gzip, deflate, br, zstd",
|
| 13 |
"accept-charset": "UTF-8",
|
| 14 |
+
"x-app-version": "2.5.0",
|
| 15 |
"x-client-bundle-id": "com.deepseek.chat",
|
| 16 |
"x-client-locale": "zh_CN",
|
| 17 |
"x-client-platform": "web",
|
| 18 |
"x-client-timezone-offset": "28800",
|
| 19 |
+
"x-client-version": "2.5.0"
|
| 20 |
},
|
| 21 |
"skip_contains_patterns": [
|
| 22 |
"quasi_status",
|
scripts/shumei-re/capture_payload.js
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
/**
|
| 3 |
+
* 数美 Web SDK(fp.min.js)离线复跑工具
|
| 4 |
+
*
|
| 5 |
+
* 作用:把 DeepSeek 前端加载的数美 SDK 放进 Node vm 沙箱里跑起来,
|
| 6 |
+
* 拦截它要上报的 deviceprofile 请求体,并用已知 uid 反向解密,
|
| 7 |
+
* 还原出「加密前的明文 payload」——这是理解/跟进数美风控协议的关键一步。
|
| 8 |
+
*
|
| 9 |
+
* 用法:
|
| 10 |
+
* node capture_payload.js <fp.min.js 路径> [输出目录]
|
| 11 |
+
*
|
| 12 |
+
* 产物(输出目录下):
|
| 13 |
+
* payload.json —— 外层请求体 {appId, organization, ep, data, os, encode, compress}
|
| 14 |
+
* decrypted.json —— 解密还原的明文指纹对象(含逐字段混淆名与密文)
|
| 15 |
+
* tn_parts.json —— tn 完整性校验的拼接分段(用于与 decrypted.json 逐段对齐)
|
| 16 |
+
*
|
| 17 |
+
* 说明:
|
| 18 |
+
* - 全程离线:XMLHttpRequest 被替换为桩实现,不会真正请求数美接口。
|
| 19 |
+
* - Math.random 固定为 0.5,因此 uid 可预测(见下 UID 常量),
|
| 20 |
+
* 这样才能用 priId = md5(uid)[:16] 解密 data。
|
| 21 |
+
* - 若 SDK 版本更新导致字段/结构变化,本工具的输出可直接与新实现做逐字段对齐。
|
| 22 |
+
*/
|
| 23 |
+
"use strict";
|
| 24 |
+
|
| 25 |
+
const fs = require("fs");
|
| 26 |
+
const vm = require("vm");
|
| 27 |
+
const crypto = require("crypto");
|
| 28 |
+
const zlib = require("zlib");
|
| 29 |
+
const path = require("path");
|
| 30 |
+
|
| 31 |
+
const sdkPath = process.argv[2];
|
| 32 |
+
const outDir = process.argv[3] || process.cwd();
|
| 33 |
+
if (!sdkPath) {
|
| 34 |
+
console.error("用法: node capture_payload.js <fp.min.js 路径> [输出目录]");
|
| 35 |
+
process.exit(1);
|
| 36 |
+
}
|
| 37 |
+
fs.mkdirSync(outDir, { recursive: true });
|
| 38 |
+
|
| 39 |
+
const CODE = fs.readFileSync(sdkPath, "utf8");
|
| 40 |
+
|
| 41 |
+
// Math.random 固定 → uid 恒定,便于解密(与 SDK 内 getUid 的 UUID v4 实现对应)
|
| 42 |
+
Math.random = () => 0.5;
|
| 43 |
+
const UID = "88888888-8888-4888-8888-888888888888";
|
| 44 |
+
|
| 45 |
+
const captured = [];
|
| 46 |
+
|
| 47 |
+
function makeElement(tag) {
|
| 48 |
+
return {
|
| 49 |
+
tagName: tag,
|
| 50 |
+
style: {},
|
| 51 |
+
dataset: {},
|
| 52 |
+
attributes: {},
|
| 53 |
+
className: "",
|
| 54 |
+
id: "",
|
| 55 |
+
src: "",
|
| 56 |
+
children: [],
|
| 57 |
+
setAttribute(k, v) {
|
| 58 |
+
this.attributes[k] = v;
|
| 59 |
+
},
|
| 60 |
+
getAttribute(k) {
|
| 61 |
+
return this.attributes[k] || null;
|
| 62 |
+
},
|
| 63 |
+
removeAttribute(k) {
|
| 64 |
+
delete this.attributes[k];
|
| 65 |
+
},
|
| 66 |
+
appendChild(c) {
|
| 67 |
+
this.children.push(c);
|
| 68 |
+
return c;
|
| 69 |
+
},
|
| 70 |
+
removeChild(c) {
|
| 71 |
+
return c;
|
| 72 |
+
},
|
| 73 |
+
addEventListener() {},
|
| 74 |
+
removeEventListener() {},
|
| 75 |
+
remove() {},
|
| 76 |
+
querySelector() {
|
| 77 |
+
return null;
|
| 78 |
+
},
|
| 79 |
+
getContext() {
|
| 80 |
+
return {
|
| 81 |
+
textBaseline: "",
|
| 82 |
+
font: "",
|
| 83 |
+
fillStyle: "",
|
| 84 |
+
fillRect() {},
|
| 85 |
+
fillText() {},
|
| 86 |
+
strokeText() {},
|
| 87 |
+
measureText: () => ({ width: 100 }),
|
| 88 |
+
getImageData: () => ({ data: new Uint8Array([1, 2, 3, 4]) }),
|
| 89 |
+
putImageData() {},
|
| 90 |
+
drawImage() {},
|
| 91 |
+
save() {},
|
| 92 |
+
restore() {},
|
| 93 |
+
createLinearGradient: () => ({ addColorStop() {} }),
|
| 94 |
+
canvas: { width: 300, height: 150 },
|
| 95 |
+
};
|
| 96 |
+
},
|
| 97 |
+
toDataURL() {
|
| 98 |
+
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==";
|
| 99 |
+
},
|
| 100 |
+
getBoundingClientRect: () => ({ width: 1920, height: 943, top: 0, left: 0 }),
|
| 101 |
+
};
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
const documentStub = {
|
| 105 |
+
createElement: (tag) => makeElement(tag),
|
| 106 |
+
getElementById: () => null,
|
| 107 |
+
querySelector: () => null,
|
| 108 |
+
querySelectorAll: () => [],
|
| 109 |
+
addEventListener() {},
|
| 110 |
+
removeEventListener() {},
|
| 111 |
+
referrer: "https://chat.deepseek.com/",
|
| 112 |
+
cookie: "",
|
| 113 |
+
body: makeElement("body"),
|
| 114 |
+
head: makeElement("head"),
|
| 115 |
+
documentElement: makeElement("html"),
|
| 116 |
+
all: undefined,
|
| 117 |
+
hidden: false,
|
| 118 |
+
visibilityState: "visible",
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
const navigatorStub = {
|
| 122 |
+
userAgent:
|
| 123 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36 Edg/153.0.0.0",
|
| 124 |
+
platform: "Win32",
|
| 125 |
+
cookieEnabled: true,
|
| 126 |
+
webdriver: false,
|
| 127 |
+
maxTouchPoints: 0,
|
| 128 |
+
hardwareConcurrency: 8,
|
| 129 |
+
plugins: [],
|
| 130 |
+
languages: ["zh-CN", "zh", "en"],
|
| 131 |
+
connection: { rtt: 50, downlink: 10, effectiveType: "4g" },
|
| 132 |
+
getBattery: () =>
|
| 133 |
+
Promise.resolve({ charging: true, level: 1, chargingTime: 0, dischargingTime: Infinity, addEventListener() {} }),
|
| 134 |
+
sendBeacon: () => true,
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
const storageStub = () => {
|
| 138 |
+
const m = new Map();
|
| 139 |
+
return {
|
| 140 |
+
getItem: (k) => (m.has(k) ? m.get(k) : null),
|
| 141 |
+
setItem: (k, v) => m.set(k, String(v)),
|
| 142 |
+
removeItem: (k) => m.delete(k),
|
| 143 |
+
clear: () => m.clear(),
|
| 144 |
+
key: (i) => [...m.keys()][i] || null,
|
| 145 |
+
get length() {
|
| 146 |
+
return m.size;
|
| 147 |
+
},
|
| 148 |
+
};
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
function XHR() {
|
| 152 |
+
this.readyState = 0;
|
| 153 |
+
this.status = 0;
|
| 154 |
+
this.response = "";
|
| 155 |
+
this.responseText = "";
|
| 156 |
+
this.onreadystatechange = null;
|
| 157 |
+
this.onload = null;
|
| 158 |
+
this.onerror = null;
|
| 159 |
+
this._headers = {};
|
| 160 |
+
}
|
| 161 |
+
XHR.prototype.open = function (method, url) {
|
| 162 |
+
this._method = method;
|
| 163 |
+
this._url = url;
|
| 164 |
+
};
|
| 165 |
+
XHR.prototype.setRequestHeader = function (k, v) {
|
| 166 |
+
this._headers[k] = v;
|
| 167 |
+
};
|
| 168 |
+
XHR.prototype.getAllResponseHeaders = () => "content-type: application/json";
|
| 169 |
+
XHR.prototype.send = function (body) {
|
| 170 |
+
captured.push({ url: this._url, method: this._method, headers: this._headers, body: String(body) });
|
| 171 |
+
const self = this;
|
| 172 |
+
// 桩响应:code=1100 让 SDK 流程正常走完(不会真正发请求)
|
| 173 |
+
const resp = JSON.stringify({
|
| 174 |
+
code: 1100,
|
| 175 |
+
detail: { c: 0, deviceId: "REVERSEDEVICEID============================================================", t: 0 },
|
| 176 |
+
requestId: "local-harness",
|
| 177 |
+
});
|
| 178 |
+
setTimeout(() => {
|
| 179 |
+
self.readyState = 4;
|
| 180 |
+
self.status = 200;
|
| 181 |
+
self.response = resp;
|
| 182 |
+
self.responseText = resp;
|
| 183 |
+
if (self.onreadystatechange) self.onreadystatechange();
|
| 184 |
+
if (self.onload) self.onload();
|
| 185 |
+
}, 0);
|
| 186 |
+
};
|
| 187 |
+
|
| 188 |
+
const windowStub = {
|
| 189 |
+
document: documentStub,
|
| 190 |
+
navigator: navigatorStub,
|
| 191 |
+
location: {
|
| 192 |
+
href: "https://chat.deepseek.com/sign_in",
|
| 193 |
+
protocol: "https:",
|
| 194 |
+
host: "chat.deepseek.com",
|
| 195 |
+
hostname: "chat.deepseek.com",
|
| 196 |
+
origin: "https://chat.deepseek.com",
|
| 197 |
+
pathname: "/sign_in",
|
| 198 |
+
search: "",
|
| 199 |
+
hash: "",
|
| 200 |
+
toString: () => "https://chat.deepseek.com/sign_in",
|
| 201 |
+
},
|
| 202 |
+
screen: { width: 1920, height: 1080, availWidth: 1920, availHeight: 1040, colorDepth: 24, devicePixelRatio: 1 },
|
| 203 |
+
innerWidth: 1920,
|
| 204 |
+
innerHeight: 943,
|
| 205 |
+
outerWidth: 1920,
|
| 206 |
+
outerHeight: 1040,
|
| 207 |
+
devicePixelRatio: 1,
|
| 208 |
+
localStorage: storageStub(),
|
| 209 |
+
sessionStorage: storageStub(),
|
| 210 |
+
XMLHttpRequest: XHR,
|
| 211 |
+
addEventListener() {},
|
| 212 |
+
removeEventListener() {},
|
| 213 |
+
attachEvent() {},
|
| 214 |
+
setTimeout,
|
| 215 |
+
clearTimeout,
|
| 216 |
+
setInterval,
|
| 217 |
+
clearInterval,
|
| 218 |
+
performance: { now: () => Date.now() },
|
| 219 |
+
// 与 DeepSeek 页面 main.js 注入的 window._smConf 保持一致
|
| 220 |
+
_smConf: {
|
| 221 |
+
organization: "P9usCUBauxft8eAmUXaZ",
|
| 222 |
+
appId: "default",
|
| 223 |
+
publicKey:
|
| 224 |
+
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDetfEgYD4aE1ZjmWJ6/jnPurhzI+yeRoJHWrnNtQMte3stQ4VjG3yu21FuN75E6cDpA9KtDXwcB2M/FiGUAe3G0rNotbWI8+SjZfUbW/OILFTzY0uaeEkmVGW5WyJ6weQbbr1xTCPa2OO3YIMeZljWUYHG5h21WAm/PATg8im8cQIDAQAB",
|
| 225 |
+
protocol: "https",
|
| 226 |
+
apiHost: "fp-it-acc.portal101.cn",
|
| 227 |
+
apiPath: "/deviceprofile/v4",
|
| 228 |
+
},
|
| 229 |
+
SMSdk: undefined,
|
| 230 |
+
_smReadyFuncs: [],
|
| 231 |
+
crypto: {
|
| 232 |
+
getRandomValues: (a) => {
|
| 233 |
+
for (let i = 0; i < a.length; i++) a[i] = (i * 37 + 11) & 255;
|
| 234 |
+
return a;
|
| 235 |
+
},
|
| 236 |
+
},
|
| 237 |
+
Math,
|
| 238 |
+
JSON,
|
| 239 |
+
Date,
|
| 240 |
+
Promise,
|
| 241 |
+
Uint8Array,
|
| 242 |
+
ArrayBuffer,
|
| 243 |
+
DataView,
|
| 244 |
+
TextEncoder,
|
| 245 |
+
TextDecoder,
|
| 246 |
+
atob: (b64) => Buffer.from(b64, "base64").toString("binary"),
|
| 247 |
+
btoa: (bin) => Buffer.from(bin, "binary").toString("base64"),
|
| 248 |
+
console,
|
| 249 |
+
};
|
| 250 |
+
windowStub.window = windowStub;
|
| 251 |
+
windowStub.self = windowStub;
|
| 252 |
+
windowStub.globalThis = windowStub;
|
| 253 |
+
windowStub.top = windowStub;
|
| 254 |
+
windowStub.parent = windowStub;
|
| 255 |
+
|
| 256 |
+
const sandbox = vm.createContext(windowStub);
|
| 257 |
+
sandbox.console = console;
|
| 258 |
+
sandbox.setTimeout = setTimeout;
|
| 259 |
+
|
| 260 |
+
// 注意:vm 上下文有独立的内建对象,补丁必须注入到沙箱内部才生效。
|
| 261 |
+
// 这里劫持 Array.prototype.join,抓取 tn 的「值拼接串」用于逐段对齐。
|
| 262 |
+
vm.runInContext(
|
| 263 |
+
`(function(){
|
| 264 |
+
var origJoin = Array.prototype.join;
|
| 265 |
+
globalThis.__joins = [];
|
| 266 |
+
Array.prototype.join = function(sep){
|
| 267 |
+
var r = origJoin.call(this, sep);
|
| 268 |
+
if (sep === '' && this.length > 40 && this.length < 300 && typeof r === 'string' && r.length > 400 && globalThis.__joins.length < 40) {
|
| 269 |
+
globalThis.__joins.push({ n: this.length, len: r.length, parts: this.slice(0) });
|
| 270 |
+
}
|
| 271 |
+
return r;
|
| 272 |
+
};
|
| 273 |
+
})();`,
|
| 274 |
+
sandbox
|
| 275 |
+
);
|
| 276 |
+
|
| 277 |
+
try {
|
| 278 |
+
vm.runInContext(CODE, sandbox, { filename: path.basename(sdkPath) });
|
| 279 |
+
} catch (e) {
|
| 280 |
+
console.error("SDK 加载失败:", e && e.message);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
function writeJSON(name, data) {
|
| 284 |
+
fs.writeFileSync(path.join(outDir, name), JSON.stringify(data, null, 1));
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
setTimeout(() => {
|
| 288 |
+
if (!captured.length) {
|
| 289 |
+
console.error("未捕获到 deviceprofile 请求:SDK 版本可能已变化,或沙箱 stub 需要补充");
|
| 290 |
+
process.exit(2);
|
| 291 |
+
}
|
| 292 |
+
const last = captured[captured.length - 1];
|
| 293 |
+
const payload = JSON.parse(last.body);
|
| 294 |
+
writeJSON("payload.json", payload);
|
| 295 |
+
console.log("payload.json: 字段 =", Object.keys(payload).join(","), "| encode =", payload.encode, "| compress =", payload.compress);
|
| 296 |
+
|
| 297 |
+
const joins = sandbox.__joins || [];
|
| 298 |
+
if (joins.length) {
|
| 299 |
+
writeJSON("tn_parts.json", joins[joins.length - 1].parts);
|
| 300 |
+
console.log("tn_parts.json: 分段数 =", joins[joins.length - 1].parts.length);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// 解密 data:uid 已知 → priId = md5(uid)[:16]
|
| 304 |
+
try {
|
| 305 |
+
const priId = crypto.createHash("md5").update(UID).digest("hex").slice(0, 16);
|
| 306 |
+
const decipher = crypto.createDecipheriv("aes-128-cbc", Buffer.from(priId, "utf8"), Buffer.from("0102030405060708", "utf8"));
|
| 307 |
+
decipher.setAutoPadding(false);
|
| 308 |
+
const dec = Buffer.concat([decipher.update(Buffer.from(payload.data, "hex")), decipher.final()]);
|
| 309 |
+
const b64 = dec.toString("utf8").replace(/\0+$/, "");
|
| 310 |
+
const json = zlib.gunzipSync(Buffer.from(b64, "base64")).toString("utf8");
|
| 311 |
+
fs.writeFileSync(path.join(outDir, "decrypted.json"), json);
|
| 312 |
+
const obj = JSON.parse(json);
|
| 313 |
+
console.log("decrypted.json: 字段数 =", Object.keys(obj).length, "| protocol =", obj.protocol);
|
| 314 |
+
console.log("→ 接下来用 decode_payload.py 校验 tn/er,用 crack_des_keys.py 盲破解各字段 DES 密钥");
|
| 315 |
+
} catch (e) {
|
| 316 |
+
console.error("解密失败(uid 是否与固定随机数一致?):", e.message);
|
| 317 |
+
}
|
| 318 |
+
process.exit(0);
|
| 319 |
+
}, 1500);
|
scripts/shumei-re/crack_des_keys.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""盲破解数美 payload 中加密字段的 DES 密钥
|
| 3 |
+
|
| 4 |
+
原理:
|
| 5 |
+
SDK 里所有字段密钥都是 8 位小写字母数字字符串,且都硬编码在 fp.min.js 内。
|
| 6 |
+
对某个密文字段,用 SDK 字符串池里的全部候选密钥逐个尝试 DES-ECB 解密,
|
| 7 |
+
只有正确的密钥会得到「全部可打印 ASCII(去除零填充后)」的明文。
|
| 8 |
+
实测:单个字段通常唯一命中,误报率极低(随机密钥整块可打印的概率约 1e-4)。
|
| 9 |
+
|
| 10 |
+
依赖:pip install pycryptodome
|
| 11 |
+
|
| 12 |
+
用法:
|
| 13 |
+
python crack_des_keys.py fp.min.js decrypted.json
|
| 14 |
+
# decrypted.json 来自 capture_payload.js(明文 payload,其中密文字段是 base64)
|
| 15 |
+
|
| 16 |
+
输出:
|
| 17 |
+
每个加密字段命中的密钥与明文;--json 输出机器可读结果(便于回填 Go 侧密钥表)
|
| 18 |
+
"""
|
| 19 |
+
import argparse
|
| 20 |
+
import base64
|
| 21 |
+
import json
|
| 22 |
+
import re
|
| 23 |
+
import string
|
| 24 |
+
import sys
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
from Crypto.Cipher import DES
|
| 28 |
+
except ImportError: # pragma: no cover
|
| 29 |
+
print("需要 pycryptodome: pip install pycryptodome", file=sys.stderr)
|
| 30 |
+
sys.exit(1)
|
| 31 |
+
|
| 32 |
+
PRINTABLE = set((string.printable + " ").encode()) - {0x0B, 0x0C}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def looks_printable(raw: bytes) -> bool:
|
| 36 |
+
return all(b in PRINTABLE for b in raw.rstrip(b"\x00"))
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def is_des_blob(value) -> bool:
|
| 40 |
+
if not isinstance(value, str) or len(value) < 8:
|
| 41 |
+
return False
|
| 42 |
+
try:
|
| 43 |
+
raw = base64.b64decode(value, validate=True)
|
| 44 |
+
except Exception:
|
| 45 |
+
return False
|
| 46 |
+
return len(raw) > 0 and len(raw) % 8 == 0
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def main() -> int:
|
| 50 |
+
ap = argparse.ArgumentParser()
|
| 51 |
+
ap.add_argument("sdk", help="fp.min.js 路径(用于提取候选密钥池)")
|
| 52 |
+
ap.add_argument("payload", help="capture_payload.js 产出的 decrypted.json")
|
| 53 |
+
ap.add_argument("--json", action="store_true", help="以 JSON 输出结果")
|
| 54 |
+
args = ap.parse_args()
|
| 55 |
+
|
| 56 |
+
sdk = open(args.sdk, encoding="utf-8", errors="replace").read()
|
| 57 |
+
candidates = sorted(set(re.findall(r"'([a-z0-9]{8})'", sdk)))
|
| 58 |
+
obj = json.load(open(args.payload, encoding="utf-8"))
|
| 59 |
+
print("候选密钥数 =", len(candidates), "| 字段数 =", len(obj), file=sys.stderr)
|
| 60 |
+
|
| 61 |
+
result = {}
|
| 62 |
+
for field, value in sorted(obj.items()):
|
| 63 |
+
if not is_des_blob(value):
|
| 64 |
+
continue
|
| 65 |
+
raw = base64.b64decode(value)
|
| 66 |
+
hits = []
|
| 67 |
+
for key in candidates:
|
| 68 |
+
try:
|
| 69 |
+
dec = DES.new(key.encode(), DES.MODE_ECB).decrypt(raw)
|
| 70 |
+
except Exception:
|
| 71 |
+
continue
|
| 72 |
+
if looks_printable(dec):
|
| 73 |
+
hits.append({"key": key, "plain": dec.rstrip(b"\x00").decode("utf-8", "replace")})
|
| 74 |
+
if hits:
|
| 75 |
+
result[field] = hits
|
| 76 |
+
if not args.json:
|
| 77 |
+
for h in hits[:3]:
|
| 78 |
+
print("%-16s key=%-9s -> %r" % (field, h["key"], h["plain"][:80]))
|
| 79 |
+
|
| 80 |
+
if args.json:
|
| 81 |
+
print(json.dumps({k: v[0] for k, v in result.items()}, ensure_ascii=False, indent=1))
|
| 82 |
+
return 0
|
| 83 |
+
|
| 84 |
+
missed = [f for f, v in obj.items() if is_des_blob(v) and f not in result]
|
| 85 |
+
if missed:
|
| 86 |
+
print("\n未破解字段(可能是新密钥或密文长度异常):", ", ".join(missed))
|
| 87 |
+
print("\n提示:把命中的密钥回填到 internal/shumei/confusion.go 的 fieldDESKey 表中,")
|
| 88 |
+
print(" 并把真实 SDK 产物固化成 internal/shumei/device_id_test.go 的黄金向量测试。")
|
| 89 |
+
return 0
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
if __name__ == "__main__":
|
| 93 |
+
sys.exit(main())
|
scripts/shumei-re/decode_payload.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""解密并校验数美 deviceprofile 请求体(payload.json)
|
| 3 |
+
|
| 4 |
+
用途:
|
| 5 |
+
1. 用 uid 派生 priId 解密 data,还原明文指纹对象(对照 capture_payload.js 的输出)
|
| 6 |
+
2. 校验完整性字段 er/tn:按 JS 语义重算拼接串并比对
|
| 7 |
+
3. 校验各字段的 DES 明文(可选,需提供密钥表)
|
| 8 |
+
|
| 9 |
+
依赖:pip install pycryptodome
|
| 10 |
+
|
| 11 |
+
用法:
|
| 12 |
+
python decode_payload.py payload.json --uid 88888888-8888-4888-8888-888888888888 [--dump]
|
| 13 |
+
"""
|
| 14 |
+
import argparse
|
| 15 |
+
import base64
|
| 16 |
+
import gzip
|
| 17 |
+
import hashlib
|
| 18 |
+
import json
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
from Crypto.Cipher import DES
|
| 23 |
+
except ImportError: # pragma: no cover
|
| 24 |
+
print("需要 pycryptodome: pip install pycryptodome", file=sys.stderr)
|
| 25 |
+
sys.exit(1)
|
| 26 |
+
|
| 27 |
+
AES_IV = "0102030405060708"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def aes_cbc_decrypt_hex(pri_id: str, data_hex: str) -> bytes:
|
| 31 |
+
from Crypto.Cipher import AES
|
| 32 |
+
|
| 33 |
+
raw = bytes.fromhex(data_hex)
|
| 34 |
+
dec = AES.new(pri_id.encode(), AES.MODE_CBC, AES_IV.encode()).decrypt(raw)
|
| 35 |
+
return dec.rstrip(b"\x00")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def des_decrypt_b64(key: str, value: str) -> str:
|
| 39 |
+
raw = base64.b64decode(value)
|
| 40 |
+
out = DES.new(key.encode(), DES.MODE_ECB).decrypt(raw)
|
| 41 |
+
return out.rstrip(b"\x00").decode("utf-8", "replace")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def js_value_string(v) -> str:
|
| 45 |
+
"""复刻 JS 中 ``'' + value`` 的字符串化行为。"""
|
| 46 |
+
if isinstance(v, bool):
|
| 47 |
+
return "true" if v else "false"
|
| 48 |
+
if isinstance(v, dict):
|
| 49 |
+
return "[object Object]" # 嵌套对象不递归
|
| 50 |
+
if isinstance(v, list):
|
| 51 |
+
return ",".join("" if x is None else js_value_string(x) for x in v)
|
| 52 |
+
if v is None:
|
| 53 |
+
return "null"
|
| 54 |
+
return str(v)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def compute_tn(obj: dict) -> str:
|
| 58 |
+
"""复刻 SDK 的 tn:按键排序拼接值,数字 ×10000(键名与分隔符不参与)。"""
|
| 59 |
+
parts = []
|
| 60 |
+
for k in sorted(obj.keys()):
|
| 61 |
+
v = obj[k]
|
| 62 |
+
if isinstance(v, bool):
|
| 63 |
+
parts.append(js_value_string(v))
|
| 64 |
+
elif isinstance(v, (int, float)):
|
| 65 |
+
parts.append(str(int(v * 0x2710)))
|
| 66 |
+
else:
|
| 67 |
+
parts.append(js_value_string(v))
|
| 68 |
+
return hashlib.md5("".join(parts).encode("utf-8")).hexdigest()
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def main() -> int:
|
| 72 |
+
ap = argparse.ArgumentParser()
|
| 73 |
+
ap.add_argument("payload", help="capture_payload.js 产出的 payload.json")
|
| 74 |
+
ap.add_argument("--uid", required=True, help="签发时的 uid(priId = md5(uid)[:16])")
|
| 75 |
+
ap.add_argument("--dump", action="store_true", help="打印全部明文字段")
|
| 76 |
+
ap.add_argument("--er-key", default="2j48yowr", help="er/tn 字段的 DES 密钥(默认当前版本)")
|
| 77 |
+
ap.add_argument(
|
| 78 |
+
"--undefined-key",
|
| 79 |
+
action="append",
|
| 80 |
+
default=None,
|
| 81 |
+
help="值为 undefined、只在 tn 里以 \"undefined\" 出现的字段(默认 yu,可重复传)",
|
| 82 |
+
)
|
| 83 |
+
args = ap.parse_args()
|
| 84 |
+
|
| 85 |
+
payload = json.load(open(args.payload, encoding="utf-8"))
|
| 86 |
+
pri_id = hashlib.md5(args.uid.encode()).hexdigest()[:16]
|
| 87 |
+
b64 = aes_cbc_decrypt_hex(pri_id, payload["data"])
|
| 88 |
+
obj = json.loads(gzip.decompress(base64.b64decode(b64)))
|
| 89 |
+
|
| 90 |
+
print("解密成功:字段数 =", len(obj), "| protocol =", obj.get("protocol"))
|
| 91 |
+
|
| 92 |
+
er = obj.get("er")
|
| 93 |
+
if er:
|
| 94 |
+
got_tn = des_decrypt_b64(args.er_key, er)
|
| 95 |
+
# JSON 会丢弃值为 undefined 的字段,但 tn 拼接里仍以字符串 "undefined" 参与。
|
| 96 |
+
undefined_keys = args.undefined_key if args.undefined_key is not None else ["yu"]
|
| 97 |
+
tn_input = {k: v for k, v in obj.items() if k != "er"}
|
| 98 |
+
for k in undefined_keys:
|
| 99 |
+
tn_input.setdefault(k, "undefined")
|
| 100 |
+
calc_tn = compute_tn(tn_input)
|
| 101 |
+
print("er 解密 =", got_tn)
|
| 102 |
+
print("本地重算 =", calc_tn)
|
| 103 |
+
print("tn 校验:", "一致 ✅" if got_tn == calc_tn else "不一致 ❌(拼接语义或字段集合有差异)")
|
| 104 |
+
else:
|
| 105 |
+
print("payload 中没有 er 字段(旧版本协议可能是明文 tn/nb)")
|
| 106 |
+
|
| 107 |
+
if args.dump:
|
| 108 |
+
for k in sorted(obj.keys()):
|
| 109 |
+
print("%-16s %s" % (k, js_value_string(obj[k])[:100]))
|
| 110 |
+
return 0
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
sys.exit(main())
|