Coder Social home page Coder Social logo

qq-nt-db's Introduction

QQ NT Windows 数据库解密+图片/文件清理

笔者测试时使用的 QQ 版本:9.9.3-17412

经验证的 QQ 版本:9.9.3-17749

找到数据库 passphrase

  1. 使用 IDA Pro 打开 C:\Program Files\Tencent\QQNT\resources\app\versions\9.9.3-17412\wrapper.node。打开 Strings 视图,搜索 sqlite3_key_v2

  2. 跳转到主视图,再跳转到引用该字符串的位置

  3. 按下 F5 反编译此函数

    参考文档可知 sqlite3_key_v2 的参数为:

    int sqlite3_key_v2(
        sqlite3 *db,                   /* Database to be keyed */
        const char *zDbName,           /* Name of the database */
        const void *pKey, int nKey     /* The key */
    );

    可以猜测 a3 为我们所需的 passphrase。打上断点

  4. 退出 QQ 并重新打开,但不要登录。使用 IDA Debug 的 Attach to Process 功能,附加到 QQ 进程。之后登录,可以看到断点被命中

    打开一个 Locals 视图(调试器视图->本地变量)查看参数的值

  5. 命中后,跳转到 a3 对应的位置,直到看到如下图所示的 16 位字符串。#8xxxxxxxxxxx@uJ 即为我们需要的 passphrase (qq版本不同,不一定是这个格式,但总字符数是一样的)

导出/修复数据库

数据库位置:C:\Users\<USERNAME>\Documents\Tencent Files\<QQ>\nt_qq\nt_db

你需要的是 .db 格式的文件。

首先,每个数据库文件头部有 1024 个字符的纯文本内容,去除这部分内容:

  • Windows

    type nt_msg.db | more +1025 > nt_msg.clean.db
  • UNIX

    cat nt_msg.db | tail -c +1025 > nt_msg.clean.db

此时文件已经可以通过 DB Browser for SQLCipher 直接查看,注意迭代次数填写 4000。

下面解释直接解密数据库的方法。

考虑到在 Windows 上编译 sqlcipher 较为困难,笔者使用了 MSYS2 环境并直接安装了mingw-w64-x86_64-sqlcipher

笔者处理了 nt_msg.dbfiles_in_chat.db 两个文件,并将处理后的文件移动到 data/clean_db

根据 sqlcipher 的文档,解密数据的流程为:

  1. 打开数据库

    $ sqlcipher
    sqlite> .open nt_msg.clean.db
  2. 输入 passphrase

    sqlite> PRAGMA key = '#8xxxxxxxxxxx@uJ'; PRAGMA kdf_iter = '4000';
  3. 导出无加密的数据库

    sqlite> ATTACH DATABASE 'nt_msg.db' AS plaintext KEY ''; SELECT sqlcipher_export('plaintext'); DETACH DATABASE plaintext;
    sqlite> .exit 

不过,很有可能在导出时提示数据库损坏 Runtime error: database disk image is malformed。此时需要对数据库进行修复:

sqlite> .output nt_msg.sql
sqlite> .dump
sqlite> .exit

之后对得到的 nt_msg.sql 进行处理,并使用 sqlite3 生成无加密的数据库

$ cat nt_msg.sql | sed -e 's|^ROLLBACK;\( -- due to errors\)*$|COMMIT;|g' | sqlite3 nt_msg.db

将解密后的数据库移动到 data/decrypted_db

图片/文件清理

下图是 nt_msg.db 中的表:

注意 c2c/group_msg_table 中的 40800(消息内容)是 Protobuf 二进制。笔者暂时没有弄明白每个字段的意义

图片/文件清理可以参考仓库中的两个 Python 脚本

致谢

QQBackup/qq-win-db-key

https://lengyue.me/2023/09/19/ntqq-db/

qq-nt-db's People

Contributors

karanocave avatar mythologyli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

qq-nt-db's Issues

QQ NT Windows database decryption passphrase not working

The error message:
sqlite> .open nt_msg.clean.db
sqlite> pragma key = "################"; pragma kdf_iter = "4000";
ok
sqlite> attach database "nt_msg.db" as plaintext key ""; Select sqlcipher_export("plaintext"); Detach database plaintext;
Parse error: file is not a database (26)
sqlite>

When trying with DB Browser SQLCipher, the settings kept are shown in the image below.
321673466-f1819309-e338-4dfa-afd4-21299e3694b9
This is also not working to open nt_msg.db even after cleaning it by removing 1024 characters.

IDA Pro 无法 Attach

试过很多次了,我不知道是 QQ 的问题,还是我的 IDA 的问题。QQ 版本在图中了

图片

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.