解密聊天记录数据库

解密聊天记录数据库


微信6.2.5使用sqlcipher进行AES加密,所以咱们要获得密钥,根据编译的信息,能够得知微信使用 key=md5(IMEI+uin) | cut -c -7 , 即取md5的前7位作为密钥。解密微信聊天数据库就是简单的一行代码,(注意sqlcipher新版本(3.x)默认不向下兼容,须要使用,cipher_use_hmac 是兼容1.1.x,kdf_iter 是兼容2.1.x的)。html

1java

2android

3git

4github

5web

sqlcipher EnMicroMsg.db 'PRAGMA key = "key"; PRAGMA cipher_use_hmac = off; PRAGMA kdf_iter = 4000; ATTACH DATABASE "decrypted_database.db" AS decrypted_database KEY "";SELECT sqlcipher_export("decrypted_database");DETACH DATABASE decrypted_database;'sql

 

或者数据库

 

sqlcipher EnMicroMsg.db 'PRAGMA key = "key"; PRAGMA cipher_migrate; ATTACH DATABASE "decrypted_database.db" AS decrypted_database KEY "";SELECT sqlcipher_export("decrypted_database");DETACH DATABASE decrypted_database;'api

IMEI很容易获取,uin在shared_prefs/多个文件中存在,如com.tencent.mm_preferences.xml,auth_info_key_prefs.xml, system_config_prefs.xml。理论上是在system_config_prefs.xml文件中的default_uin,注意有多是负的,以前我没有意识到这个问题,致使一直解码不成功,直到看了这个博客。ps. 负数是由于溢出int32(2639833126) = -1655134170 。微信

 

这方面已经很人作了,好比github上的wechat-dump,效果仍是能够的,稍微有点问题,往后再改。

往后改了一些东西,最重要的是微信的头像文件再也不单一保存,而是用 avatar.index 来索引,保存在一个大文件中avatar.block.0000x。经测试,能够得知用户头像以avatar.index中的数值为起始位置,找到avatar.block.0000x相应连续的96×96×3×4个连续字节就算用户头像的bitmap(png.bm)。具体见代码

get avatar

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

    def read_bm_block(self, pos):

        hex_pos = hex(pos)

        fname = os.path.join(self.avt_dir,

                'avatar.block.0000' + hex_pos[2])

        f = open(fname, 'rb')

        start_pos = pos - 2 ** 34

        f.seek(start_pos+30)

        while f.read(1) != b"\x00":

            continue

 

        size = (96, 96, 3)

        img = np.zeros(size, dtype='uint8')

        for i in range(96):

            for j in range(96):

                r, g, b, a = map(ord, f.read(4))

                img[i,j] = (r, g, b)

        return img

 

 

 

相关文章
相关标签/搜索