Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert msgstore.db.crypt7 to msgstore.db from whatsapp in android?

I want add Automatically contacts that message to me in Whatsapp, so I need to access to Whatsapp's database for my program, but Whatsapp's database is not in .db format and is in .crypt7 format and I cannot use it. How can I use Whatsapp db or convert .crypt7 to .db?

like image 407
mahdi Avatar asked Feb 12 '23 15:02

mahdi


1 Answers

As Ashesh mentioned you can use the tool on the XDA developer website: [TOOL] Whatsapp Xtract: Backup Messages Extractor / Database Analyzer / Chat-Backup

Alternatively you can do this manually as follows:

The WhatsApp Database is stored unencrypted at this path on the Android device:

/data/data/com.whatsapp/databases/msgstore.db

Backups of the database are also stored encrypted on the SD card typically at the following location:

/sdcard/WhatsApp/Databases/msgstore.db.crypt7

The unique key for the encrypted backup databases is stored here:

/data/data/com.whatsapp/files/key

Access to the /data/data directory requires root access. Alternatively ADB (Android Debug Bridge) can be used to extract the above files after booting into recovery on the device.

How to Decrypt WhatsApp crypt7 Database Messages:

(commands below are run from a linux enviroment)

  1. Extract Key File: /data/data/com.whatsapp/files/key
  2. Extract crypt7 file: /sdcard/WhatsApp/Databases/msgstore.db.crypt7
  3. Extract Decryption Keys from "key" file extracted in step 1:

    • 256-bit AES key:

      hexdump -e '2/1 "%02x"' key | cut -b 253-316 > aes.txt

    • IV (initialisation vector):

      hexdump -e '2/1 "%02x"' key | cut -b 221-252 > iv.txt

  4. Strip Header in crypt7 File:

    dd if=msgstore.db.crypt7 of=msgstore.db.crypt7.nohdr ibs=67 skip=1

    Note: Size of header stripped file in bytes must be divisible by 16

  5. Decrypt crypt7 File:

    openssl enc -aes-256-cbc -d -nosalt -nopad -bufsize 16384 -in msgstore.db.crypt7.nohdr -K $(cat aes.txt) -iv $(cat iv.txt) > msgstore.db

like image 116
moo Avatar answered Feb 15 '23 09:02

moo