(function() {
// 保存原始的decrypt函数引用
const originalDecrypt = crypto.subtle.decrypt;
// 重写decrypt函数
crypto.subtle.decrypt = async function(algorithm, key, data) {
// 在解密之前执行你的代码
console.log('Decrypting data...');
debugger;
// 假设你在断点处
// 查看algorithm对象
console.log('Algorithm object:', algorithm);
// 如果algorithm是AES-CBC,你可以这样获取iv
const iv = algorithm.iv;
console.log('Initialization Vector (IV):', new Uint8Array(iv)); // 将iv转换为Uint8Array以便查看
// 查看data
const encryptedData = new Uint8Array(data);
console.log('Encrypted data:', encryptedData); // 将data转换为Uint8Array以便查看
// 导出key(这需要原始的CryptoKey是可导出的)
crypto.subtle.exportKey('raw', key).then(exportedKey => {
console.log('Exported key:', new Uint8Array(exportedKey)); // 将导出的密钥转换为Uint8Array以便查看
}).catch(error => {
console.error('Key export failed:', error);
});
// 调用原始的decrypt函数进行解密
const result = await originalDecrypt.apply(this, arguments);
// 在解密之后执行你的代码
console.log('Data decrypted.');
// 返回解密结果
return result;
};
})();
我们需要的参数如下,通过脚本可以断点并获取值:
- iv = b'...' # 初始化向量(从JavaScript中获取)
- encrypted_data = b'...' # 要解密的数据(从JavaScript中获取,也可以从接口获取)
- key = b'...' # 密钥(从JavaScript中获取)
转换成python代码:
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
# JavaScript对象转换为Python字节序列
iv = bytes([57, 233, 12, 46, 56, 33, 70, 15, 47, 149, 127, 207, 122, 98, 220, 249]) # 替换你hook的值
data = bytes([
21, 78, 114, 236, 56, 217, 136, 85, 191, 7, 36, 20, 10, 30, 147, 102,
231, 4, 127, 144, 17, 36, 62, 31, 145, 41, 3, 213, 237, 150, 184, 195,
108, 187, 30, 241, 205, 52, 5, 91, 225, 54, 138, 63, 59, 57, 211, 169,
243, 46, 65, 237, 8, 190, 186, 81, 43, 241, 194, 162, 61, 30, 227, 146
]) # 替换你hook的值
key = bytes([74, 53, 219, 97, 50, 91, 239, 53, 232, 81, 58, 18, 137, 197, 11, 220]) # 替换你hook的值
# 创建一个AES-CBC解密器
cipher = AES.new(key, AES.MODE_CBC, iv)
# 解密数据并去除填充
try:
original_data = unpad(cipher.decrypt(data), AES.block_size)
print('Decrypted data:', original_data)
except ValueError as e:
print('Unpad error:', e)
但是我们从接口拿到的,一般是base64格式,需要转换成bytes格式:
import base64
# Base64编码的字符串
base64_data = "1d0KbgHFAg6tvG/pSUlIUfrN6N+5VP+XLB+FH6m/aOfAmDTzelb/77oaBKHP7fsylmvaQr4j1TB3Jn106PPAyHBZNDZWsp0Kh27BCl3Km0jBzoc2Y5LmQjZAR9pAb426"
# 解码Base64字符串
data = base64.b64decode(base64_data)