Cracking and decryption? How To Decrypt WeChat EnMicroMsg. db Database?
WeChat is a smartphone application where users can chat with their friends, share pictures, videos and audio chats. users can also make free video calland voice callwith their friends as long as they have Internet connection.
Recently, we requested ed a request from the law enforcement agency to extract WeChat chat messages from an Android mobile phone.
Although this mobile phone model is supported by XRY (a mobile phone forensics tool), but it cocould not extract the WeChat chat messages. Only Whatsapp, and other text messages were successfully extracted.
We have also conducting CTED keyword search using EnCase, but to no avail. Although we can see the chat messages directly from the mobile phone display, EnCase still cannot find the keyword that we searched.
Figure 1:The encrypted data inEnMicroMsg. db
However, during the analysis in EnCase, we found a. DB file named,EnMicroMsg. dbIn the WeChat application folder. This file size is about 3.7 MB.
This curiosity leads us to conducting CT a research on the Internet and we found that the file is an encrypted SQLite database file for WeChat chat messages.
EnMicroMsg. db and SQLCipher
EnMicroMsg. dbIs an encrypted SQLite database file that contains the WeChat chat messages. This file is encrypted usingSQLCipher, An open source extension for SQLite database that provides transparent 256-bit AES encryption of database files.
Figure 2:Parameters to decryptEnMicroMsg. dbFile
Below are the parameters needed to encrypt and decrypt the data inEnMicroMsg. dbFile.
- PRAGMA key = KEY;
- PRAGMA cipher_use_hmac = off;
- PRAGMA cipher_page_size = 1024;
- PRAGMA kdf_iter = 4000;
The simple explanations for these parameters are described below:
- PRAGMA key-Set the key to use with the database.
- PRAGMA cipher_use_hmac-Disable the usage of per-page HMAC checks for backwards compatibility with SQLCipher 1.1.x on a specific database.
- PRAGMA cipher_page_size-Alter the page size used for the database from the default of 1024 bytes to improve performance for some query types.
- PRAGMA kdf_iter-Change the number of iterations used with PBKDF2 key derivation.
Kindly go to SQLCipher API page for a better understanding about these parameters and their usage in SQLCipher.
KEY to decrypt
EnMicroMsg. db
KEY is the most important parameter to decrypt the EnMicroMsg. db file. this KEY is generated from the MD5 hash, combination of IMEI and UIN (a unique identifier of the WeChat user ). however, only the first 7-characters of the MD5 hash will be used as the KEY to decrypt it.
Figure 3:The process to generate the KEY
IMEI is the 15-digits unique number that you can usually get at the back of the mobile phone. Or you can enter * #06 # to get the mobile phone IMEI number.
UIN is the unique identifier that you can get fromSystem_config_prefs.xmlFile in the WeChat application folder.
Figure 4:Example to generate the KEY
In short, the KEY generation can be summarized as follows:
KEY = MD5 (IMEI + UIN) [0: 7]
For an example, the IMEI number for the mobile phone is,357725678854269And the UIN number which you get fromSystem_config_prefs.xmlFile is,-1881034049.
- IMEI: 357725678854269.
- UIN:-1881034049
So the MD5 hash value for these IMEI and UIN is,4bc36a03296a8b4fc63e5bb8e74db2a2
Therefore the KEY to decryptEnMicroMsg. dbIs,4bc36a0.
Python script,
Fmd_wechatdecipher.py
To make it easier for you to decrypt this file, we have wrote a Python script,Fmd_wechatdecipher.py, Which you can use it in your lab.
This script runs on Python and you need to install an additional package, pysqlcipher. Pysqlcipher will allows you to use SQLCipher function in Python.
Figure 5:Input and OutputFmd_wechatdecipher.pyScript
Before you can use this script, there are several things that you need to know aboutFmd_wechatdecipher.py.
This script requires two input files and one input from the user.
The Input Files are:
- EnMicroMsg. db-The WeChat database file that contains the encrypted chat messages.
- System_config_prefs.xml-The WeChat file that contains the UIN number.
The Input that you need to enter:
- IMEI-The 15-digits IMEI number of the mobile phone
And the Output Files after you executed the script:
- EnMicroMsg-decrypted.db-Decrypted database file that contains WeChat chat messages.
- EnMicroMsg-decrypted.log-Log file that contains all information to decrypt the file such as IMEI, UIN, and KEY. It also provided des with the MD5 and SHA1 hash valuesEnMicroMsg-decrypted.dbFile.
How to use the script?
In order to use this script, you must put all the Input Files in the same folder with the Python script.
When the script prompts you to enter the IMEI number, just enter the correct IMEI number and it will generate the KEY and decryptEnMicroMsg. dbFile automatically.
Figure 6:The decrypted data stored inEnMicroMsg-decrypted.db
Once the process is done, you will see two files are generated,EnMicroMsg-decrypted.dbAndEnMicroMsg-decrypted.log, In the same folder.
All the encrypted WeChat chat messages have been decrypted and are stored inEnMicroMsg-decrypted.dbFile. You can extract the chat messages by using your favorite SQLite Browser to analyze this file.
References
- Http://blog.emaze.net/2013/09/a-look-at-wechat-security.html
- Https://www.zetetic.net/sqlcipher/sqlcipher-api
- Https://pypi.python.org/pypi/pysqlcipher
- Https://gist.github.com/scturtle/7248017