微信PC端数据库文件解密
概述
获取密钥
(根据作者描述,这只是把上面那个项目使用 Go 重构的版本)
[+] WeChatMobile: 1********** [+] WeChatMail: ?M??@魢#??M????????????T?B??L???3??????f7i?J???M??h?v??M??`?v????????T?B?J?3?????f7 [+] WeChatKey: 92AD63A674************************222544426[+] Done
WeChat Version: 3.9.2.23 WeChat NickName: XXX WeChat Account: wxid_xxxxx WeChat Mobile: 1**********WeChat Key: 92AD63A674************************222544426
解密数据库
input_pass = '92AD63A674************************222544426'input_dir = r'D:\微信数据库文件'import ctypesimport hashlibimport hmacfrom pathlib import Pathfrom Crypto.Cipher import AES
SQLITE_FILE_HEADER = bytes('SQLite format 3', encoding='ASCII') + bytes(1)
IV_SIZE = 16HMAC_SHA1_SIZE = 20KEY_SIZE = 32DEFAULT_PAGESIZE = 4096DEFAULT_ITER = 64000password = bytes.fromhex(input_pass.replace(' ', ''))def decode_one(input_file):
input_file = Path(input_file) with open(input_file, 'rb') as (f):
blist = f.read() print(len(blist))
salt = blist[:16]
key = hashlib.pbkdf2_hmac('sha1', password, salt, DEFAULT_ITER, KEY_SIZE)
first = blist[16:DEFAULT_PAGESIZE]
mac_salt = bytes([x ^ 58 for x in salt])
mac_key = hashlib.pbkdf2_hmac('sha1', key, mac_salt, 2, KEY_SIZE)
hash_mac = hmac.new(mac_key, digestmod='sha1')
hash_mac.update(first[:-32])
hash_mac.update(bytes(ctypes.c_int(1))) if hash_mac.digest() == first[-32:-12]: print('Decryption Success') else: print('Password Error')
blist = [
blist[i:i + DEFAULT_PAGESIZE] for i in range(DEFAULT_PAGESIZE, len(blist), DEFAULT_PAGESIZE)
] with open(input_file.parent / f'decoded_{input_file.name}', 'wb') as (f):
f.write(SQLITE_FILE_HEADER)
t = AES.new(key, AES.MODE_CBC, first[-48:-32])
f.write(t.decrypt(first[:-48]))
f.write(first[-48:]) for i in blist:
t = AES.new(key, AES.MODE_CBC, i[-48:-32])
f.write(t.decrypt(i[:-48]))
f.write(i[-48:])if __name__ == '__main__':
input_dir = Path(input_dir) for f in input_dir.glob('*.db'):
decode_one(f)



