netease-comment-requests.png 请求中发送的数据如下图,看⼀眼,啥都看不懂,肯定是加密过了。
netease-comment-post-data.png
同样,在network tab下⾯搜索encSecKey,搜到了⼀个js⽂件中的两个函数都有encSecKey。
netease-comment-encSecKey.png
下⾯列出这两个函数:
函数⼀
加密策略
加密策略是使⽤AES加密请求数据,然后⽤RSA加密AES密钥,我尝试分析了⼀下,发现分析得头⽪发⿇,后⾯在github到了。。。。。链接
在这:⽹易云新版webapi分析
网易云代码
代码是python2写的,改了⼀下,python3能⽤:
import requests
import os
import binascii
import base64
import requests
import json
from Crypto.Cipher import AES
modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ec nonce = b'0CoJUm6Qyw8W8jud'
pubKey = '010001'
"""
加密过程
随机⽣成加密密钥secKey
然后⽤secKey两次对post的查询数据进⾏两次AES加密
⽤RSA对secKey加密
最后把加密后的secKey和查询数据post到服务器
"""
def createSecretKey(size):
return binascii.hexlify(os.urandom(size))[:16]
def aesEncrypt(text, secKey):
pad = 16 - len(text) % 16
text = text + pad * str(chr(pad))
encryptor = w(secKey, AES.MODE_CBC, '0102030405060708'.encode('utf8'))
ciphertext = de('utf8'))
ciphertext = base64.b64encode(ciphertext).decode('utf8')
return ciphertext
def rsaEncrypt(text, pubKey, modulus):
text = text[::-1]
rs = int(bytes.hex(text), 16) ** int(pubKey, 16) % int(modulus, 16)
return format(rs, 'x').zfill(256)
def encrypted_request(text):
text = json.dumps(text)
secKey = createSecretKey(16)
encText = aesEncrypt(aesEncrypt(text, nonce), secKey)
encSecKey = rsaEncrypt(secKey, pubKey, modulus)
data = {
'params': encText,
'encSecKey': encSecKey
}
return data
def load_headers(filename):
headers = {}
with open(filename, 'r') as f:
for line adlines():
entry = line.split(':', 1)
if len(entry) != 2:
continue
headers[entry[0].strip()] = entry[1].strip()
return headers
def comment_post_url(song_id, csrf=''):
return 'music.163/weapi/v1/resource/comments/R_SO_4_' + \