How to Decrypt Whatsapp Database File

WhatsApp: how to decode the *.db.crypt files?

$crypt = file_get_contents('msgstore.db.crypt');
$key = pack('H*', '346a23652a46392b4d73257c67317e352e3372482177652c');
$decrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $crypt, MCRYPT_MODE_ECB);

Whatsapp database decryption on Android

You need to convert the hex strings to byte arrays properly:

private static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i+1), 16));
}
return data;
}

public void decryptDatabase(String k, String iv) throws InvalidKeyException, InvalidAlgorithmParameterException,
NoSuchAlgorithmException, NoSuchPaddingException, IOException {

File extStore = Environment.getExternalStorageDirectory();
FileInputStream fis = new FileInputStream(extStore
+ "/WhatsApp/Databases/msgstore.db.crypt7.nohdr");
FileOutputStream fos = new FileOutputStream(extStore + "/Decrypted.db");

SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(k), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, sks,
new IvParameterSpec(hexStringToByteArray(iv)));
CipherInputStream cis = new CipherInputStream(fis, cipher);
int b;
byte[] d = new byte[8];
while ((b = cis.read(d)) != -1) {
fos.write(d, 0, b);
}
fos.flush();
fos.close();
cis.close();
}

How to decrypt sent binary message by whatsapp web

I removed the first two bytes from sent binary data and the rest got decrypted properly.

As per the code here,

payload = bytearray(messageId) + bytearray(",") + bytearray(to_bytes(WAMetrics.MESSAGE, 1)) + bytearray(
[0x80]) + encryptedMessage

The WebSocket payload to be sent is concatenation of messageid and comma followed by two bytes i.e. bytearray(to_bytes(WAMetrics.MESSAGE, 1)) and bytearray([0x80]) and then the encrypted message.

Considering this format, I copied payload from Google Chrome, splitted on first comma and then removed two bytes as above. The remaining binary was encrypted message which could be directly decrypted by the keys.

 def reverseDecryptMessage(message):
messageSplit = message.split(",", 1)
if len(messageSplit) == 1:
return
messageContent = messageSplit[1]
messageContent = messageContent[2:]
decryptBinary(messageContent)

Android Read WhatsApp Data

I have done this by using following :

Root your device and try this code::

public void copyDbToSdcard()
{
try
{
String comando = "cp -r /data/data/com.whatsapp/databases/msgstore.db /sdcard/My_Custom_Folder/";
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
os.writeBytes(comando + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
try
{
int suProcessRetval = suProcess.waitFor();
if(255 != suProcessRetval)
{
//
}
else
{
//
}
}
catch (Exception ex)
{
Log.e("ERROR-->", ex.toString());
}
}
catch (Exception e)
{
e.printStackTrace();
}
}


private void openAndQueryDatabase()
{
try
{
DataBaseHelper dbHelper = new DataBaseHelper(this.getApplicationContext());
newDB = dbHelper.getWritableDatabase();

Cursor c = newDB.rawQuery("SELECT data FROM messages where data!=''", null);

if(c != null)
{
if(c.moveToFirst())
{
do
{

String data = c.getString(c.getColumnIndex("data"));

results.add(data); //adding to arrayList

}
while (c.moveToNext());
}
}

while (c3.moveToNext());
}
}
}

catch (SQLiteException se)
{
Log.e(getClass().getSimpleName(), "Could not create or Open the database");
}
}

And then display results in your TextView or wherever you want.



Related Topics



Leave a reply



Submit