AES动态加密

6 阅读1分钟

www.coinglass.com/zh/BitcoinO…

const zlib = require("pako")  
const ee = require("crypto-js")  
  
  
var getE = function () {  
header_user = "QzwFvyFANPusLHNr5pejdVicai7D+9/6OG/upcio3wR/UDUoiTOfkPwwxCNuSzik"  
e = "/api/openInterest/v3/chart"  
n = btoa("coinglass".concat(e, "coinglass"))  
n = n.substring(0, 16)  
n = Yt(header_user, n);  
return n;  
};  
var Yt = function (t, e) {  
$t = ee;  
var n = function (t) {  
var e, n = zlib.inflate(new Uint8Array(t.match(/[\da-f]{2}/gi).map((function (t) {  
return parseInt(t, 16)  
}  
)))), r = "", i = 16384;  
for (e = 0; e < n.length / i; e++)  
r += String.fromCharCode.apply(null, n.slice(e * i, (e + 1) * i));  
return r += String.fromCharCode.apply(null, n.slice(e * i)),  
decodeURIComponent(escape(r))  
}  
(ee.AES.decrypt(t, $t.enc.Utf8.parse(e), {  
mode: $t.mode.ECB,  
padding: $t.pad.Pkcs7  
}).toString($t.enc.Hex));  
return '"' == n.charAt(0) && (n = n.substring(1, n.length)),  
'"' == n.charAt(n.length - 1) && (n = n.substring(0, n.length - 1)),  
n  
};
#!/usr/bin/env python3  
# -*- coding: utf-8 -*-  
# ETH 合约总持仓 https://www.coinglass.com/zh/BitcoinOpenInterest  
  
import requests  
# pip install pyexecjs2  
import execjs  
  
if __name__ == '__main__':  
headers = {  
'accept': 'application/json',  
'accept-language': 'zh-CN,zh;q=0.9',  
'cache-control': 'no-cache',  
'cache-ts': '1734419103955',  
'encryption': 'true',  
'language': 'zh',  
'origin': 'https://www.coinglass.com',  
'pragma': 'no-cache',  
'priority': 'u=1, i',  
'referer': 'https://www.coinglass.com/',  
'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',  
'sec-ch-ua-mobile': '?0',  
'sec-ch-ua-platform': '"Windows"',  
'sec-fetch-dest': 'empty',  
'sec-fetch-mode': 'cors',  
'sec-fetch-site': 'same-site',  
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',  
}  
  
params = {  
'symbol': 'ETH',  
}  
  
response = requests.get('https://capi.coinglass.com/api/openInterest/ex/info', params=params, headers=headers)  
# 密文  
encrypt_data = response.json()['data']  
  
scrypt_js = decrypt_data = execjs.compile(open("scrypt.js", "r", encoding="utf-8").read())  
e = scrypt_js.call('getE')  
print(scrypt_js.call("Yt", encrypt_data, e))