1. 获取微信路径
打开微信 以此点击 三横杆 -> 文件管理 -> 文件管理
这个文件中包括数据库、图片、视频、文件等等,我们主要讨论的是存放于wxid_xxxxxx/Msg/Multi文件夹下的数据库文件,如MSG0.db。这些文件是经过AES加密,所以需要找到秘钥进行解密。秘钥通过微信key获取。
2. 获取微信key
首先获取 pywxdumpmini 此源代码。
git clone https://github.com/xaoyaoo/PyWxDumpMini.git
cd PyWxDumpMini
pip install -r requirements.txt
cd pywxdump_mini
python simplify_wx_info.py
会输出如下内容:
key 为我们寻找的结果。
3. 编写解密python文件
文件名:weixin_decrypt.py
from Crypto.Cipher import AES
import hashlib, hmac, ctypes, sys, getopt
input_pass = '4eacd623b*********************************a369d6d6033b'
input_dir = r'***********\\Msg\\Multi\\MSG0.db'
SQLITE_FILE_HEADER = bytes('SQLite format 3', encoding='ASCII') + bytes(1)
IV_SIZE = 16
HMAC_SHA1_SIZE = 20
KEY_SIZE = 32
DEFAULT_PAGESIZE = 4096
DEFAULT_ITER = 64000
opts, args = getopt.getopt(sys.argv[1:], 'hk:d:')
password = bytes.fromhex(input_pass.replace(' ', ''))
with open(input_dir, '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_dir, '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:])
执行代码:
python weixin_decrypt.py
4. 查看聊天内容
然后将解压后的文件在sqllite查看器中查看内容