├── LICENSE ├── README.md └── hook.js /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 陈宣宇 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | frida_with_wechat_applet 2 | ===== 3 | [![License](https://img.shields.io/github/license/kksanyu/frida_with_wechat_applet)](https://github.com/kksanyu/frida_with_wechat_applet) 4 | 5 | ### 概述 6 | 7 | PC微信小程序未加密包提取方案 wxapkg frida版本 8 | 9 | ***该解决方案只支持 `Windows` 系统哦*** 10 | 11 | ### 准备工作 12 | 13 | 你得知道frida是啥? [不知道的同学可以戳这里进官网](https://frida.re/) 14 | 15 | 第1步: 删除 `C:\Users\{用户名}\Documents\WeChat Files\Applet` 下的所有历史小程序缓存, 避免受到干扰。 16 | 17 | ***注意: 如果你变更过 `我的文档` 路径的话, 这个地址会有变动, 以自己电脑上的地址为准。*** 18 | 19 | 第2步: 手动点击一下微信小程序PC版本左下角的 `小程序面板`, 让程序先初始化小程序模块。 20 | 21 | ### 使用 22 | 23 | 完成了准备工作之后, 就可以愉快的使用脚本了 24 | 25 | ```shell 26 | # 加载脚本 27 | $ frida WeChat.exe -l hook.js 28 | ``` 29 | 30 | 在小程序面板点击想要提取 `wxapkg` 包的小程序, 在 `WeChat Files\Applet` 目录下会自动存储未加密的源代码包。 31 | 32 | ### 原理 33 | 34 | 通过HOOK `WeChatAppHost.dll` 中的 `EncryptBufToFile` 函数, 在加密函数调用之前,拿到未加密的源代码包数据, 加密生成文件后,覆盖生成后的文件实现解密。 35 | 36 | ~~这个方法比较取巧,当然有能力的大神可以去硬杠解密算法。~~ 37 | 找到 `BlackTrace` 大神的方案, 继续往下看。 38 | 39 | #### wxapkg包 解密工具 40 | 41 | 这里借鉴了 `BlackTrace` 的 `GO` 版本解密代码, 翻译为 `python` 版本。 42 | 43 | 传送门: 44 | 45 | - [python版本 戳这里](https://github.com/kksanyu/pc_wxapkg_decrypt_python) 46 | 47 | - [GO版本 戳这里](https://github.com/BlackTrace/pc_wxapkg_decrypt) 48 | 49 | ### License 50 | 51 | The MIT License(http://opensource.org/licenses/MIT) 52 | 53 | 请自由地享受和参与开源 54 | 55 | -------------------------------------------------------------------------------- /hook.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @name 微信小程序PC版 wxapkg提取 3 | * @author kksanyu 4 | * @url https://github.com/kksanyu/frida_with_wechat_applet 5 | */ 6 | 7 | var baseAddr = Module.findBaseAddress('WeChatAppHost.dll'); 8 | console.log('WeChatAppHost.dll baseAddr: ' + baseAddr); 9 | 10 | if (baseAddr) { 11 | 12 | // EncryptBufToFile函数偏移地址, 从DLL中查看 13 | var EncryptBufToFile = baseAddr.add(0x1800F); 14 | console.log('EncryptBufToFile 函数地址: ' + EncryptBufToFile); 15 | 16 | // HOOK函数, 监听参数 17 | Interceptor.attach(EncryptBufToFile, { 18 | onEnter: function (args) { 19 | // 微信小程序AppId 20 | this.appId = ptr(args[0]).readPointer().readAnsiString(); 21 | // 微信小程序本地缓存文件路径 22 | this.apkgFilePath = ptr(args[1]).readPointer().readAnsiString(); 23 | // 小程序代码原始内容(未加密) 24 | this.originalData = Memory.readByteArray(args[2], args[3].toInt32()); 25 | }, 26 | onLeave: function (retval) { 27 | console.log('文件解密成功', this.apkgFilePath); 28 | 29 | // 将文件替换为未加密的wxapkg包 30 | var f = new File(this.apkgFilePath, 'wb'); 31 | f.write(this.originalData); 32 | f.flush(); 33 | f.close(); 34 | 35 | // 释放内存 36 | delete this.appId; 37 | delete this.apkgFilePath; 38 | delete this.originalData; 39 | } 40 | }); 41 | 42 | } else { 43 | console.log('WeChatAppHost.dll 模块未加载, 请先打开界面中的小程序面板'); 44 | } 45 | --------------------------------------------------------------------------------