网址:https://fanyi.youdao.com/index.html#/

解析流程

可以很明显的看到sign 和 响应都做了加密处理

image-20230517184506461

image-20230517184511837

然后再控制台发现 它竟然把解密的结果给打印出来了

image-20230517184821697

那我们直接搜索console.log定位到这里

image-20230517184902260

1
2
3
4
const n = an["a"].decodeData(o, sn["a"].state.text.decodeKey, sn["a"].state.text.decodeIv), a = n ? JSON.parse(n) : {};

sn["a"].state.text.decodeKey 和 sn["a"].state.text.decodeIv都是固定值

查看一下 an[“a”].decodeData()方法,t是响应体

image-20230517185235102

crypto.createDecipheriv()是内置的加密算法,o和n使用md5加密后转换成数组,这里直接copy下面,补一下环境即可

1
2
3
4
5
6
7
8
9
10
11
const crypto=require('crypto')
function gerT(t){
const o = 'ydsecret://query/key/B*RGygVywfNBwpmBaZg*WT7SIOUP2T0C9WHMZN39j^DAdaZhAnxvGcCY6VYFwnHl';
const n = 'ydsecret://query/iv/C@lZe2YzHtZ2CYgaXKSVfsb7Y4QWHjITPPZ0nQp87fBeJ!Iv6v^6fvi2WN@bYpJ4';

const a = Buffer.alloc(16, crypto.createHash("md5").update(o).digest())
, r = Buffer.alloc(16, crypto.createHash("md5").update(n).digest())
, i = crypto.createDecipheriv("aes-128-cbc", a, r);
let s = i.update(t, "base64", "utf-8");
return s += i.final("utf-8"), s
}

关键字搜索sign,点进去看一下,看到合适的打上断点查看

image-20230517185907424

h方法传进两个参数,一个是时间戳,一个是e,这个e固定, 然后拼接几个参数,交给v方法,v方法也是md5,直接copy补全即可

image-20230517190140624

1
2
3
4
5
6
7
const crypto = require('crypto')
function p(x) {
return crypto.createHash("md5").update(x.toString()).digest("hex")
}
function sign(e, time) {
return p(`client=${"fanyideskweb"}&mysticTime=${time}&product=${"webfanyi"}&key=${"fsdsogkndfokasodnaso"}`)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# coding:utf-8
import requests, re, random, json, time
from user_agents import user_agents
import re, execjs
import time

"""
1.正常的md5加密都可以通过上下两种方式进行解析,hex的参数意味着(md5加密32位小写)
2.require('crypto') 导包,导入node的crypto包
3.当看到不常见的js代码的时候,可以查一下是不是js的内置代码, 特别是当处于js混淆的时候,有时候百度比找js代码更合适
例如 e.alloc 它就是js的内置代码Buffer.alloc()
4.这次出现一个编码的问题,来自于execjs的内置方法buffer.append(fh.read()),可以通过改变里面的编码格式来解决问题
代码在subprocess.py的738行,修改编码格式使之为"utf-8"
5.请求不成功的时候不一定是加密的参数解析失败,有可能是请求头的问题,拆解请求头以尝试获取请求成功
"""


def exec_js(str1, time_stamp):
ctx = execjs.compile("""
const crypto = require('crypto')
function p(x) {
return crypto.createHash("md5").update(x.toString()).digest("hex")
}
function sign(e, time) {
return p(`client=${"fanyideskweb"}&mysticTime=${time}&product=${"webfanyi"}&key=${"fsdsogkndfokasodnaso"}`)
}
""")
result_str = ctx.call("sign", str1, time_stamp)
return result_str


def exec_js2(str1):
ctx = execjs.compile("""
const crypto=require('crypto')
function gerT(t){
const o = 'ydsecret://query/key/B*RGygVywfNBwpmBaZg*WT7SIOUP2T0C9WHMZN39j^DAdaZhAnxvGcCY6VYFwnHl';
const n = 'ydsecret://query/iv/C@lZe2YzHtZ2CYgaXKSVfsb7Y4QWHjITPPZ0nQp87fBeJ!Iv6v^6fvi2WN@bYpJ4';

const a = Buffer.alloc(16, crypto.createHash("md5").update(o).digest())
, r = Buffer.alloc(16, crypto.createHash("md5").update(n).digest())
, i = crypto.createDecipheriv("aes-128-cbc", a, r);
let s = i.update(t, "base64", "utf-8");
return s += i.final("utf-8"), s
}
""")
result_str = json.loads(ctx.call("gerT", str1))
return result_str


def get_translate(str1):
list_url = 'https://dict.youdao.com/webtranslate'
print(list_url)
user_agent = random.choice(user_agents)
time_stamp = int(time.time() * 1000)
print(time_stamp)
sign = exec_js("fsdsogkndfokasodnaso", str(time_stamp))
print(sign)
post_data = {
'i': str1,
'from': 'auto',
'to': '',
'domain': '0',
'dictResult': 'true',
'keyid': 'webfanyi',
'sign': sign,
'client': 'fanyideskweb',
'product': 'webfanyi',
'appVersion': '1.0.0',
'vendor': 'web',
'pointParam': 'client,mysticTime,product',
'mysticTime': time_stamp,
'keyfrom': 'fanyi.web',

}
list_headers = {
'accept': 'application/json, text/plain, */*',
'User-Agent': user_agent,
'Host': 'dict.youdao.com',
'Origin': 'https://fanyi.youdao.com',
'Referer': 'https://fanyi.youdao.com/',
'Cookie': 'OUTFOX_SEARCH_USER_ID=-1512055292@10.108.162.133; OUTFOX_SEARCH_USER_ID_NCOO=51976831.82152718',
}
res = requests.post(url=list_url, headers=list_headers, timeout=5, data=post_data)
encode_str = res.text
print(encode_str)
res_txt = exec_js2(encode_str)
print(res_txt)


get_translate("时间")