45

我正在尝试实现一个应用程序,它将在文本视图中显示从 Whatsapp 收到的所有消息。有什么办法吗?是否可以从 Whatsapp 中提取所有消息?

4

8 回答 8

31

Whatsapp 将所有消息存储在加密数据库 (pyCrypt) 中,使用 Python 很容易破译。

您可以在 Android、iPhone、Blackberry 上轻松获取此数据库并将其转储到 html 文件中。以下是完整说明:在 Android、iPhone、Blackberry 上阅读、提取 WhatsApp 消息备份

免责声明:我研究并编写了这份详尽的指南。

于 2013-03-15T07:37:30.520 回答
19

工作Android代码:(无需root)

一旦您可以访问 dbcrypt5 文件,这里是解密它的 android 代码:

private byte[] key = { (byte) 141, 75, 21, 92, (byte) 201, (byte) 255,
        (byte) 129, (byte) 229, (byte) 203, (byte) 246, (byte) 250, 120,
        25, 54, 106, 62, (byte) 198, 33, (byte) 166, 86, 65, 108,
        (byte) 215, (byte) 147 };

private final byte[] iv = { 0x1E, 0x39, (byte) 0xF3, 0x69, (byte) 0xE9, 0xD,
        (byte) 0xB3, 0x3A, (byte) 0xA7, 0x3B, 0x44, 0x2B, (byte) 0xBB,
        (byte) 0xB6, (byte) 0xB0, (byte) 0xB9 };
   long start = System.currentTimeMillis();

    // create paths
    backupPath = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/WhatsApp/Databases/msgstore.db.crypt5";
    outputPath = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/WhatsApp/Databases/msgstore.db.decrypt";

    File backup = new File(backupPath);

    // check if file exists / is accessible
    if (!backup.isFile()) {
        Log.e(TAG, "Backup file not found! Path: " + backupPath);
        return;
    }

    // acquire account name
    AccountManager manager = AccountManager.get(this);
    Account[] accounts = manager.getAccountsByType("com.google");

    if (accounts.length == 0) {
        Log.e(TAG, "Unable to fetch account!");
        return;
    }

    String account = accounts[0].name;

    try {
        // calculate md5 hash over account name
        MessageDigest message = MessageDigest.getInstance("MD5");
        message.update(account.getBytes());
        byte[] md5 = message.digest();

        // generate key for decryption
        for (int i = 0; i < 24; i++)
            key[i] ^= md5[i & 0xF];

        // read encrypted byte stream
        byte[] data = new byte[(int) backup.length()];
        DataInputStream reader = new DataInputStream(new FileInputStream(
                backup));
        reader.readFully(data);
        reader.close();

        // create output writer
        File output = new File(outputPath);
        DataOutputStream writer = new DataOutputStream(
                new FileOutputStream(output));

        // decrypt file
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        SecretKeySpec secret = new SecretKeySpec(key, "AES");
        IvParameterSpec vector = new IvParameterSpec(iv);
        cipher.init(Cipher.DECRYPT_MODE, secret, vector);
        writer.write(cipher.update(data));
        writer.write(cipher.doFinal());
        writer.close();
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "Could not acquire hash algorithm!", e);
        return;
    } catch (IOException e) {
        Log.e(TAG, "Error accessing file!", e);
        return;
    } catch (Exception e) {
        Log.e(TAG, "Something went wrong during the encryption!", e);
        return;
    }

    long end = System.currentTimeMillis();

    Log.i(TAG, "Success! It took " + (end - start) + "ms");
于 2014-04-30T05:16:46.277 回答
12

编辑

随着 WhatsApp 努力改进他们的加密系统,获取数据不再那么容易了。对于较新版本的 WhatsApp,它不再可能使用adb backup. 应用程序可以拒绝备份,而 WhatsApp 客户端会这样做。如果你碰巧有一部 root 手机,你可以使用 root shell 来获取未加密的数据库文件。

如果您没有 root,如果您有旧的 WhatsApp APK,您仍然可以解密数据。找到一个仍然允许备份的版本。然后,您可以备份应用程序的数据文件夹,其中将包含一个名为,好吧,key.

现在您需要加密数据库。使用您选择的文件资源管理器,或者,如果您更喜欢命令行,请使用 adb:

adb pull /sdcard/WhatsApp/Databases/msgstore.db.crypt12

使用这两个文件,您现在可以使用https://gitlab.com/digitalinternals/whatsapp-crypt12来获取纯文本数据库。不再可能使用 Linux 板工具,openssl因为 WhatsApp 似乎使用了修改版本的Spongy Castle API来进行 openssl 无法理解的密码学。

原始答案(仅适用于旧 crypt7)

由于 whatsapp 现在使用的是 crypt7 格式,因此获取和解密数据库不再那么容易了。有一种使用 ADB 和 USB 调试的工作方法。

您可以通过 ADB 获取加密密钥并解密存储在 /sdcard 上的消息数据库,或者您只需通过 ADB 备份获取数据库的普通版本,这似乎是更简单的选择。

要获取数据库,请执行以下操作:

将您的 Android 手机连接到计算机。现在运行

adb backup -f whatsapp_backup.ab -noapk com.whatsapp

备份 WhatsApp 在其私人文件夹中创建的所有文件。
您将获得一个使用 tar 格式和一些 ADB 头文件的 zlib 压缩文件。我们需要先去掉这些头文件,因为它们会混淆解压命令:

dd if=whatsapp_backup.ab ibs=1 skip=24 of=whatsapp_backup.ab.nohdr

现在可以解压缩该文件:

cat whatsapp_backup.ab.nohdr | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" 1> whatsapp_backup.tar

此命令运行 Python 并使用 zlib 将文件解压缩到 whatsapp_backup.tar
现在我们可以解压缩文件:

tar xf whatsapp_backup.tar

存档现在被提取到您当前的工作目录,您可以在 apps/com.whatsapp/db/ 中找到数据库(msgstore.db 和 wa.db)

于 2014-06-01T19:22:31.077 回答
8

我认为您只能以 root 用户身份访问位于 SD 卡上的 WhatsApp 数据库。如果你打开 "\data\data\com.whatsapp" 你会看到 "databases" 链接到 "\firstboot\sqlite\com.whatsapp\"

于 2012-02-20T04:53:02.777 回答
4

如果您真的想要一些简单的东西并且知道如何编写/运行 Python,请查看脚本 Bas Bosschert:来源

#!/usr/bin/env python

import sys
from Crypto.Cipher import AES

try:
    wafile=sys.argv[1]
except:
    print "Usage: %s <msgstore.db.crypt>" % __file__
    sys.exit(1)

key = "346a23652a46392b4d73257c67317e352e3372482177652c".decode('hex')
cipher = AES.new(key,1)
open('msgstore.db',"wb").write(cipher.decrypt(open(wafile,"rb").read()))

全面运行:

(scratch)ehtesh@ackee:/tmp/whatsapp$ mkvirtualenv whatsapp_decrypt
New python executable in whatsapp_decrypt/bin/python
Installing setuptools, pip...done.
(whatsapp_decrypt)ehtesh@ackee:/tmp/whatsapp$ pip install pycrypto >/dev/null
(whatsapp_decrypt)ehtesh@ackee:/tmp/whatsapp$ wget https://gist.githubusercontent.com/shurane/ffa15e959e2d134086c9/raw/bc99a9997123bea0ea0acde185e24c7e89133559/whatsapp_decrypt.py >/dev/null
(whatsapp_decrypt)ehtesh@ackee:/tmp/whatsapp$ ls
msgstore.db.crypt  whatsapp_decrypt.py
(whatsapp_decrypt)ehtesh@ackee:/tmp/whatsapp$ python whatsapp_decrypt.py msgstore.db.crypt
(whatsapp_decrypt)ehtesh@ackee:/tmp/whatsapp$ ls
msgstore.db.crypt  msgstore.db  whatsapp_decrypt.py
(whatsapp_decrypt)ehtesh@ackee:/tmp/whatsapp$ sqlite3 msgstore.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA table_info(messages);
0|_id|INTEGER|0||1
1|key_remote_jid|TEXT|1||0
2|key_from_me|INTEGER|0||0
3|key_id|TEXT|1||0
4|status|INTEGER|0||0
5|needs_push|INTEGER|0||0
6|data|TEXT|0||0
7|timestamp|INTEGER|0||0
8|media_url|TEXT|0||0
9|media_mime_type|TEXT|0||0
10|media_wa_type|TEXT|0||0
11|media_size|INTEGER|0||0
12|media_name|TEXT|0||0
13|media_hash|TEXT|0||0
14|media_duration|INTEGER|0||0
15|origin|INTEGER|0||0
16|latitude|REAL|0||0
17|longitude|REAL|0||0
18|thumb_image|TEXT|0||0
19|remote_resource|TEXT|0||0
20|received_timestamp|INTEGER|0||0
21|send_timestamp|INTEGER|0||0
22|receipt_server_timestamp|INTEGER|0||0
23|receipt_device_timestamp|INTEGER|0||0
24|raw_data|BLOB|0||0
25|recipient_count|INTEGER|0||0
sqlite>

Pritam Baral 提到了一种更简单的方法:

openssl aes-192-ecb -d -in msgstore.db.crypt -out msgstore.db -K 346a23652a46392b4d73257c67317e352e3372482177652c
于 2014-05-27T22:05:44.837 回答
3

对于 root 用户:whats app 以纯文本形式将所有消息和联系人存储在 msgstore.db 和 wa.db 文件中。这些文件位于 /data/data/com.whatsapp/databases/ 中。您可以使用任何 sqlite 浏览器(如 SQLite 数据库浏览器)打开这些文件。

于 2014-01-04T14:05:49.567 回答
1

是的,它必须是从 WhatsApp 获取消息的方法,因为市场上有一些工具可以帮助 WhatsApp 用户将 WhatsApp 聊天记录备份到他们的计算机上,我从这里知道这一点。因此,您必须能够实现此类应用程序。也许您可以在市场上找到这些工具,看看它们是如何工作的。

于 2017-02-15T08:09:56.730 回答
1

如果我们从字面上理解这个问题:

从 Whatsapp 获取所有消息。是否可以从 Whatsapp 中提取所有消息?

那么简单的答案是您可以从 WhatsApp 导出聊天(请参阅常见问题解答)。

现在您可以构建一个应用程序,它会监听 WhatsApp Share 事件并显示所有消息。对于一个简单的 PWA,它可能如下所示:

    workbox.addEventListener("message", (m) => {
      if (_this.$route.query.hasOwnProperty("receiving-file-share")) {
        let files = m.data.file;
        _this.$refs.filehandler.processFileList(files, true);
      }
    });
    workbox.messageSW("SHARE_READY");
于 2021-03-17T08:53:38.323 回答