Skip to content
Back to search

wechat-decrypt

微信4.0数据库解密工具 | WeChat 4.0 Database Decryptor — memory-based key extraction, real-time message monitoring, MCP Server for Claude AI

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/328336690--wechat-decrypt/badge.svg)](/listings/328336690--wechat-decrypt)

HTML

<a href="/listings/328336690--wechat-decrypt"><img src="/api/listings/328336690--wechat-decrypt/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 204 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # WeChat 4.0 Database Decryptor
  2. [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
  3. [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org/)
  4. [![Platform](https://img.shields.io/badge/Platform-Windows%2010%2F11-lightgrey.svg)](#)
  5. [![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](CONTRIBUTING.md)
  6. [![CI](https://github.com/328336690/wechat-decrypt/actions/workflows/ci.yml/badge.svg)](https://github.com/328336690/wechat-decrypt/actions/workflows/ci.yml)
  7. 微信 4.0 (Windows) 本地数据库解密工具。从运行中的微信进程内存提取加密密钥,解密所有 SQLCipher 4 加密数据库,并提供实时消息监听。
  8. ## 原理
  9. 微信 4.0 使用 SQLCipher 4 加密本地数据库:
  10. - **加密算法**: AES-256-CBC + HMAC-SHA512
  11. - **KDF**: PBKDF2-HMAC-SHA512, 256,000 iterations
  12. - **页面大小**: 4096 bytes, reserve = 80 (IV 16 + HMAC 64)
  13. - **每个数据库有独立的 salt 和 enc_key**
  14. WCDB (微信的 SQLCipher 封装) 会在进程内存中缓存派生后的 raw key,格式为 `x'<64hex_enc_key><32hex_salt>'`。本工具通过扫描进程内存中的这种模式,匹配数据库文件的 salt,并通过 HMAC 验证来提取正确的密钥。
  15. ## 使用方法
  16. ### 环境要求
  17. - Windows 10/11
  18. - Python 3.10+
  19. - 微信 4.0 (正在运行)
  20. - 需要管理员权限 (读取进程内存)
  21. ### 安装依赖
  22. ```bash
  23. pip install pycryptodome
  24. ```
  25. ### 1. 配置
  26. 复制配置模板并修改:
  27. ```bash
  28. copy config.example.json config.json
  29. ```
  30. 编辑 `config.json`:
  31. ```json
  32. {
  33. "db_dir": "D:\\xwechat_files\\你的微信ID\\db_storage",
  34. "keys_file": "all_keys.json",
  35. "decrypted_dir": "decrypted",
  36. "wechat_process": "Weixin.exe"
  37. }
  38. ```
  39. `db_dir` 路径可以在 微信设置 → 文件管理 中找到。
  40. ### 2. 提取密钥
  41. 确保微信正在运行,以**管理员权限**运行:
  42. ```bash
  43. python find_all_keys.py
  44. ```
  45. 密钥将保存到 `all_keys.json`。
  46. ### 3. 解密数据库
  47. ```bash
  48. python decrypt_db.py
  49. ```
  50. 解密后的数据库保存在 `decrypted/` 目录,可以直接用 SQLite 工具打开。
  51. ### 4. 实时消息监听
  52. #### Web UI (推荐)
  53. ```bash
  54. python monitor_web.py
  55. ```
  56. 打开 http://localhost:5678 查看实时消息流。
  57. - 30ms 轮询 WAL 文件变化 (mtime)
  58. - 检测到变化后全量解密 + WAL patch (~70ms)
  59. - SSE 实时推送到浏览器
  60. - 总延迟约 100ms
  61. - **图片消息内联预览**(支持旧 XOR / V1 / V2 三种 .dat 加密格式)
  62. #### 命令行
  63. ```bash
  64. python monitor.py
  65. ```
  66. 每 3 秒轮询一次,在终端显示新消息。
  67. ### 5. MCP Server (Claude AI 集成)
  68. 将微信数据查询能力接入 [Claude Code](https://claude.ai/claude-code),让 AI 直接读取你的微信消息。
  69. ```bash
  70. pip install mcp
  71. ```
  72. 注册到 Claude Code:
  73. ```bash
  74. claude mcp add wechat -- python C:\Users\你的用户名\wechat-decrypt\mcp_server.py
  75. ```
  76. 或手动编辑 `~/.claude.json`:
  77. ```json
  78. {
  79. "mcpServers": {
  80. "wechat": {
  81. "type": "stdio",
  82. "command": "python",
  83. "args": ["C:\\Users\\你的用户名\\wechat-decrypt\\mcp_server.py"]
  84. }
  85. }
  86. }
  87. ```
  88. 注册后在 Claude Code 中即可使用以下工具:
  89. | Tool | 功能 |
  90. |------|------|
  91. | `get_recent_sessions(limit)` | 最近会话列表(含消息摘要、未读数) |
  92. | `get_chat_history(chat_name, limit)` | 指定聊天的消息记录(支持模糊匹配名字) |
  93. | `search_messages(keyword, limit)` | 全库搜索消息内容 |
  94. | `get_contacts(query, limit)` | 搜索/列出联系人 |
  95. | `get_new_messages()` | 获取自上次调用以来的新消息 |
  96. 前置条件:需要先完成步骤 1-2(配置 + 提取密钥)。
  97. **[查看使用案例 →](USAGE.md)**
  98. ### 6. 图片解密 (V2 格式)
  99. 微信 4.0 (2025-08+) 的 .dat 图片文件使用 AES-128-ECB + XOR 混合加密 (V2 格式)。AES 密钥需要从运行中的微信进程内存中提取:
  100. ```bash
  101. # 1. 在微信中打开查看 2-3 张图片(点击看大图)
  102. # 2. 立即运行密钥提取(持续监控版):
  103. python find_image_key_monitor.py
  104. # 或单次扫描版:
  105. python find_image_key.py
  106. ```
  107. 密钥会自动保存到 `config.json` 的 `image_aes_key` 字段。之后 `monitor_web.py` 启动时会自动加载密钥,图片消息将显示内联预览。
  108. > **注意**: AES 密钥仅在微信查看图片时临时加载到内存中。如果扫描未找到密钥,请先在微信中查看几张图片,然后立即重新运行脚本。
  109. ## 文件说明
  110. | 文件 | 说明 |
  111. |------|------|
  112. | `config.py` | 配置加载器 |
  113. | `find_all_keys.py` | 从微信进程内存提取所有数据库密钥 |
  114. | `decrypt_db.py` | 全量解密所有数据库 |
  115. | `mcp_server.py` | MCP Server,让 Claude AI 查询微信数据 |
  116. | `monitor_web.py` | 实时消息监听 (Web UI + SSE + 图片预览) |
  117. | `monitor.py` | 实时消息监听 (命令行) |
  118. | `decode_image.py` | 图片 .dat 文件解密模块 (XOR / V1 / V2) |
  119. | `find_image_key.py` | 从微信进程内存提取图片 AES 密钥 |
  120. | `find_image_key_monitor.py` | 持续监控版密钥提取(推荐) |
  121. | `latency_test.py` | 延迟测量诊断工具 |
  122. ## 技术细节
  123. ### WAL 处理
  124. 微信使用 SQLite WAL 模式,WAL 文件是**预分配固定大小** (4MB)。检测变化时:
  125. - 不能用文件大小 (永远不变)
  126. - 使用 mtime 检测写入
  127. - 解密 WAL frame 时需校验 salt 值,跳过旧周期遗留的 frame
  128. ### 图片 .dat 加密格式
  129. 微信本地图片 (.dat) 有三种加密格式:
  130. | 格式 | 时期 | Magic | 加密方式 | 密钥来源 |
  131. |------|------|-------|---------|---------|
  132. | 旧 XOR | ~2025-07 | 无 | 单字节 XOR | 自动检测 (对比 magic bytes) |
  133. | V1 | 过渡期 | `07 08 V1 08 07` | AES-ECB + XOR | 固定 key: `cfcd208495d565ef` |
  134. | V2 | 2025-08+ | `07 08 V2 08 07` | AES-128-ECB + XOR | 从进程内存提取 |
  135. V2 文件结构: `[6B signature] [4B aes_size LE] [4B xor_size LE] [1B padding]` + `[AES-ECB encrypted] [raw unencrypted] [XOR encrypted]`
  136. ### 数据库结构
  137. 解密后包含约 26 个数据库:
  138. - `session/session.db` - 会话列表 (最新消息摘要)
  139. - `message/message_*.db` - 聊天记录
  140. - `contact/contact.db` - 联系人
  141. - `media_*/media_*.db` - 媒体文件索引
  142. - 其他: head_image, favorite, sns, emoticon 等
  143. ## 免责声明
  144. 本工具仅用于学习和研究目的,用于解密**自己的**微信数据。请遵守相关法律法规,不要用于未经授权的数据访问。

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.