wechat_hook2.js
2.73 KB
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
/*
* 策略1: hook 系统 libsqlite3 的 sqlite3_key (可能不被调用)
* 策略2: 在 WeChat 主二进制里搜索 sqlite3_key 的函数签名并 hook
* 策略3: hook CCCryptorCreate (CommonCrypto AES 初始化)
*/
// 策略1: 系统 libsqlite3
var lib_sqlite3 = Process.findModuleByName('libsqlite3.dylib');
if (lib_sqlite3) {
['sqlite3_key', 'sqlite3_key_v2', 'sqlite3_rekey', 'sqlite3_rekey_v2'].forEach(function(fn) {
var sym = lib_sqlite3.findExportByName(fn);
if (sym) {
Interceptor.attach(sym, {
onEnter: function(args) {
var n = fn === 'sqlite3_key' ? args[2].toInt32() : args[3].toInt32();
var p = fn === 'sqlite3_key' ? args[1] : args[2];
if (n > 0 && n <= 256) {
var hex = Array.from(new Uint8Array(p.readByteArray(n)))
.map(b => ('0'+b.toString(16)).slice(-2)).join('');
send({type:'system_sqlite3_key', func:fn, len:n, hex:hex});
}
}
});
send({type:'hooked_system', func:fn, addr:sym.toString()});
}
});
}
// 策略3: hook CommonCrypto CCCryptorCreate - 捕获 AES-256 key 设置
// 这能捕获 WeChat 的 AES 密钥初始化,包括 SQLCipher 的数据库加密 key
var cc = Process.findModuleByName('libSystem.B.dylib');
var cc_create = null;
if (cc) {
// CCCryptorCreate(op, alg, options, key, keyLength, iv, cryptorRef)
cc_create = cc.findExportByName('CCCryptorCreate');
}
if (!cc_create) {
// Try directly
cc_create = Module.findExportByName(null, 'CCCryptorCreate');
}
if (cc_create) {
Interceptor.attach(cc_create, {
onEnter: function(args) {
try {
var op = args[0].toInt32(); // 0=encrypt, 1=decrypt
var alg = args[1].toInt32(); // 0=AES, 1=DES, etc.
var keyLen = args[4].toInt32();
// AES-256 key = 32 bytes
if (alg === 0 && keyLen === 32) {
var key = args[3].readByteArray(32);
var hex = Array.from(new Uint8Array(key))
.map(b => ('0'+b.toString(16)).slice(-2)).join('');
send({type:'aes_key', op:op, len:keyLen, hex:hex});
}
} catch(e) {}
}
});
send({type:'hooked', func:'CCCryptorCreate', addr:cc_create.toString()});
}
// 策略4: 在 WeChat 主二进制中搜索 sqlite3_key 函数
// ARM64/x86_64 下 sqlite3_key 的典型开头字节
var wechat = Process.findModuleByName('WeChat');
if (wechat) {
send({type:'info', msg:'WeChat module base: ' + wechat.base.toString() +
' size: ' + wechat.size.toString()});
}
send({type:'ready'});