Sunday, July 20, 2014

Decrypt WhatsApp crypt5 file

Decrypt WhatsApp crypt5 file, with Python and M2Crypto.

(In Ubuntu, for example ... )
1. Install Python, install M2Crypto (Also install SQLite database browser)
2. Copy the script at the bottom of this page, save it in your local directory as <name>.py
(example: WaDecr.py)
3. Open terminal and run:
python ./WaDecr.py ./msgstore.db.crypt5
(Replace the token "msgstore.db.crypt5" with your own file name)
In Windows: (Please notice that you have to use the "current-folder" specifier in Linux)
 python WaDecr.py msgstore.db.crypt5

4. Voila!


Once you get your decrypted file, use a SQLite database browser to view your chats.

Au revoir!


#!/usr/bin/python

import sys
import hashlib
import StringIO
import os.path
from M2Crypto import EVP

ngKy=bytearray([
0x8D,0x4B,0x15,0x5C,0xC9,0xFF,0x81,0xE5,
0xCB,0xF6,0xFA,0x78,0x19,0x36,0x6A,0x3E,
0xC6,0x21,0xA6,0x56,0x41,0x6C,0xD7,0x93])
ngIv=bytearray([
0x1E,0x39,0xF3,0x69,0xE9,0x0D,0xB3,0x3A,
0xA7,0x3B,0x44,0x2B,0xBB,0xB6,0xB0,0xB9])

def fFil(p):
    return p+".decr.db"

def fBCryp(pDB,pAc):
    lDB=fFil(pDB)
    lb_=True
    for i in xrange(10):
        if os.path.isfile(lDB):
            lDB=fFil(pDB+"."+str(i))
        else:
            lb_=False
            break
    if lb_:
        print "ERROR: Cannot find a directory for your decrypted file, to safely write ... :("
        return
    try:
        lFH=file(pDB,'rb')
    except:
        print "ERROR: Cannot open your encrypted file ... Check directory again ... !   -.-"
        return  
    lED=lFH.read()
    lFH.close()
    l_M=hashlib.md5()
    l_M.update(pAc)
    lM5=bytearray(l_M.digest())
    for i in xrange(24):ngKy[i]^=lM5[i&0xF]
    try:
        lCi=EVP.Cipher('aes_192_cbc',key=ngKy,iv=ngIv,op=0)
        lFI=file(lDB,'wb')
        lFI.write(lCi.update(lED))
        lFI.write(lCi.final())
        lFI.close()
    except:
        print "ERROR: Cannot decrypt ...\nDid you put the correct account name,\nhave you checked if it is the \"crypt5\" file and not the \"crypt\" file,\nor are you sure that the file is not corrupted  ... ?  o.O"
        return
    print "SUCCESS! =D"

if __name__ == '__main__':
    if len(sys.argv) == 3:
        fBCryp(sys.argv[1],sys.argv[2])
    else:
        print 'Parameter:   %s <crypt5-file> <name-of-account>' %sys.argv[0]

No comments:

Post a Comment