Loading... # Brida 实战:一键解密 APP HTTPS 流量教程 # 一、概述 ## 1. 简介 ### A. 是什么 Brida 是 Burp Suite 的一个插件,用于连接 Burp 和 Frida 框架。Frida 是一个轻量级的动态 hook 框架,因其灵活性和动态特性,在移动端安全测试中广泛应用。Brida 作为两者之间的桥梁,使安全测试人员能够在 Burp Suite 中直接调用 Frida 的 hook 能力。 ### B. 为什么学 在日常 APP 安全测试中,经常遇到以下挑战场景: - 数据包经过加密处理,无法直接查看明文内容 - 请求带有签名验证,直接修改会导致验签失败 - 需要逆向 APP 分析加解密算法,耗费大量时间 - APP 经过加壳、混淆、加固,逆向难度极大 Brida 提供了一种高效的解决方案,通过直接 hook APP 中的加解密或签名函数,绕过复杂的逆向分析过程,极大提升测试效率。 ### C. 学完能做什么 - 使用 Frida hook 获取 APP 中的加解密函数和密钥 - 编写自定义 JS 脚本实现数据包的自动加解密 - 在 Burp Suite 中创建右键菜单、标签页等便捷工具 - 结合 Burp Suite 的 Intruder、Repeater 等工具进行 fuzz 测试 - 绕过 SSL Pinning、root 检测、指纹检测等安全特性 ## 2. 前置知识 ### A. 必备技能 - 基本的移动应用安全测试概念 - 熟悉 Burp Suite 的基本操作 - 了解 Android/iOS 应用结构 - 基础的 JavaScript 编程能力 ### B. 推荐知识 - Frida 框架的基本使用 - Android/iOS 逆向分析基础 - 常见的加密算法(AES、RSA 等) # 二、环境准备 ## 1. 系统要求 - 操作系统:Windows、macOS 或 Linux - Python:2.7 或 3.x - Burp Suite:Pro 或 Community 版本 - 测试设备:Android 或 iOS 设备(需 root 或越狱) ## 2. 安装步骤 ### A. 安装 Frida 客户端 在本地电脑安装 Frida 及相关工具: ```bash pip install frida pip install frida-tools pip install Pyro4 npm install frida-compile ``` 验证安装: ```bash frida --version ``` ### B. 手机端安装 Frida 服务端 1. 确认手机 CPU 架构: ```bash adb shell getprop ro.product.cpu.abi ``` 2. 从 Frida GitHub Releases 下载对应的 frida-server: https://github.com/frida/frida/releases 注意:下载的 frida-server 版本需与本机 frida 版本和手机 CPU 架构匹配。 3. 将 frida-server 推送到手机并启动: ```bash adb root adb push frida-server /data/local/tmp/ adb shell "chmod 755 /data/local/tmp/frida-server" adb shell "/data/local/tmp/frida-server &" ``` 4. 配置端口转发: ```bash adb forward tcp:27042 tcp:27042 adb forward tcp:27043 tcp:27043 ``` ## 3. 安装 Brida 插件 在 Burp Suite 中通过 BApp Store 安装 Brida 插件: 1. 打开 Burp Suite 2. 进入 Extensions → BApp Store 3. 搜索 Brida 并点击安装 # 三、核心概念 ## 1. 基本术语 - Frida:动态代码插桩框架,支持在运行时 hook 应用函数 - Brida:Burp 与 Frida 之间的通信插件 - Pyro4:Python 远程对象库,作为 Brida 与 Frida 通信的中间件 - Hook:在函数调用前后插入自定义代码的技术 - Spawn:以启动模式附加到目标应用 - Attach:附加到正在运行的目标应用 ## 2. 工作原理 ```mermaid graph TB A[Burp Suite] -->|Pyro4 协议| B[Brida 插件] B -->|IPC 通信| C[Frida Server] C -->|Hook 调用| D[目标 APP] D -->|函数执行结果| C C -->|返回数据| B B -->|加解密数据| A E[Brida JS 脚本] -->|定义 Hook| B F[androidDefaultHooks.js] -->|预定义 Hook| B G[iosDefaultHooks.js] -->|预定义 Hook| B ```  **工作流程说明**: 1. Brida 在 Burp Suite 中启动 Pyro4 服务器 2. Frida Server 在手机端运行,与目标 APP 建立连接 3. Brida 加载 JS 脚本,定义要 hook 的函数 4. 当 Burp Suite 发送请求时,Brida 通过 Frida 调用 APP 中的加解密函数 5. 加解密结果返回给 Burp Suite,实现自动处理 ## 3. 架构图 ```mermaid graph LR subgraph 本地环境 A[Burp Suite] B[Brida 插件] C[Pyro4 服务器] D[JS 脚本] end subgraph 手机环境 E[Frida Server] F[目标 APP] end A --> B B --> C B --> D C <-->|ADB 端口转发| E E --> F ```  # 四、快速上手 ## 1. Brida 基础配置 ### A. 配置 Python 环境 在 Burp Suite 中打开 Brida 配置页面: - Python binary path:选择 Python 2.7 或 3.x 的可执行文件路径 - Pyro host/port:默认为 localhost:9999 - frida-compile path:frida-compile 二进制文件路径 - Frida JS files folder:选择存放 JS 文件的目录,点击 Create default js file 生成默认文件 ### B. 获取目标应用信息 **获取 Application ID(Spawn 模式)**: Android 设备: ```bash frida-ps -Uai ``` 或查看 AndroidManifest.xml 中的 package 包名。 iOS 设备: ```bash frida-ps -Rai ``` **获取目标进程 PID(Attach 模式)**: 1. 运行目标应用 2. 执行命令查看进程列表: Android: ```bash frida-ps -U ``` iOS: ```bash frida-ps -R ``` ### C. 连接目标应用 1. 点击 Start Server 启动 Pyro4 服务器 2. 点击 Spawn application / Compile & Spawn 或 Attach application / Compile & Attach 3. 注意:连接前需要编译 JS 文件,否则不会生效 4. 修改 JS 文件后,需要点击 Compile & reload 按钮 ## 2. Brida JS 文件说明 点击 Create default js file 后,会在指定目录生成以下文件: - brida.js:主文件,引入其他 JS 文件的所有 hooks,用户在此自定义编写 hooks/functions/exports - bridaFunctions.js:包含 Brida 各部件使用的所有 hooks - androidDefaultHooks.js:包含大量 Android 用于绕过安全特性的 hooks(SSL Pinning 绕过、root 检测绕过、指纹检测绕过等) - iosDefaultHooks.js:包含大量 iOS 用于绕过安全特性的 hooks ## 3. Hello World 示例 编写一个简单的加密测试脚本: ```javascript // contextcustom1: 加密函数 contextcustom1: function(message) { var enc; Java.perform(function() { try { var key = "9876543210123456"; var text = message; // hook class var AesEncryptionBase64 = Java.use('com.ese.http.encrypt.AesEncryptionBase64'); // hook method enc = AesEncryptionBase64.encrypt(key, text); console.log("Encrypt: " + text + "--->" + enc); } catch (error) { console.log("[!]Exception: " + error.message); } }); return enc; }, // contextcustom2: 解密函数 contextcustom2: function(message) { var text; Java.perform(function() { try { var key = "9876543210123456"; var enc = message; // hook class var AesEncryptionBase64 = Java.use('com.ese.http.encrypt.AesEncryptionBase64'); // hook method text = AesEncryptionBase64.decrypt(key, enc); console.log("Decrypt: " + enc + "--->" + text); return text; } catch (error) { console.log("[!]Exception: " + error.message); } }); return text; } ``` # 五、实战案例 ## 1. 场景描述 某 APP 的登录请求和响应都经过 AES 加密处理,无法直接在 Burp Suite 中查看明文内容或进行 fuzz 测试。目标是通过 Brida 实现数据包的自动加解密。 **原始加密流量**: 请求:username 和 password 字段均为密文 响应:body 为密文 **目标效果**: 在 Burp Suite 中自动将密文解密显示,并在发送请求时自动加密参数。 ## 2. 实现步骤 ### A. 获取加解密函数信息 **方法一:反编译分析** 使用 JADX 等工具反编译 APK,查找加解密函数: 1. 找到加密调用点:AesEncryptionBase64.encrypt 2. 找到解密调用点:AesEncryptionBase64.decrypt 3. 确认加密方式:AES/CBC/PKCS5Padding 4. 获取密钥和 IV: ```java public static final String AesKey = "9876543210123456"; public static final String Aesiv = "0102030405060708"; ``` **方法二:使用 Brida hook crypto** 1. Spawn 到目标程序 2. 在 Brida 中选择 Graphical Analysis → Load tree 3. 查看 javax.crypto 相关内容的调用堆栈 4. 根据堆栈信息获取加解密函数和密钥 ### B. 编写加解密 JS 脚本 参考"四、快速上手"中的示例代码,编写 contextcustom1(加密)和 contextcustom2(解密)函数。 ### C. 创建 IContextMenu 菜单 在 Brida 的 IContextMenu 标签页创建右键菜单项: **解密菜单**: - 菜单名称:Decrypt - 动作类型:Show message - Context:custom2(调用解密函数) 效果:选中密文后右键点击 Decrypt,弹框显示解密结果。 **加密菜单**: - 菜单名称:Encrypt - 动作类型:Replace selected text - Context:custom1(调用加密函数) 效果:选中明文后右键点击 Encrypt,自动替换为密文。 ### D. 创建 IMessageEditorTab 在 IMessageEditorTab 标签页创建自定义标签页: - 标签名称:Decrypted - Context:custom2(解密函数) 效果:在响应标签页中新增 Decrypted 标签,显示解密后的内容。 ### E. 创建 IHttpListener 在 IHttpListener 标签页配置自动加解密规则: **处理请求**: 1. 加密 username 字段: - Action: Execute custom1 and replace - What: Field - Field: username 2. 加密 password 字段: - Action: Execute custom1 and replace - What: Field - Field: password **处理响应**: 1. 解密响应 body: - Action: Execute custom2 and replace - What: Body ### F. 整体效果 配置完成后,在 Burp Suite 中的效果: - 发送请求时,username 和 password 自动加密 - 接收响应时,body 自动解密显示 - 可以直接使用 Intruder 进行爆破测试 ## 3. 完整代码 ```javascript // brida.js 栌心内容 var functions = { // 加密函数 contextcustom1: function(message) { var enc; Java.perform(function() { try { var key = "9876543210123456"; var text = message; var AesEncryptionBase64 = Java.use('com.ese.http.encrypt.AesEncryptionBase64'); enc = AesEncryptionBase64.encrypt(key, text); console.log("Encrypt: " + text + "--->" + enc); } catch (error) { console.log("[!]Exception: " + error.message); } }); return enc; }, // 解密函数 contextcustom2: function(message) { var text; Java.perform(function() { try { var key = "9876543210123456"; var enc = message; var AesEncryptionBase64 = Java.use('com.ese.http.encrypt.AesEncryptionBase64'); text = AesEncryptionBase64.decrypt(key, enc); console.log("Decrypt: " + enc + "--->" + text); return text; } catch (error) { console.log("[!]Exception: " + error.message); } }); return text; } }; ``` # 六、高级功能 ## 1. 常用功能 ### A. SSL Pinning 绕过 在 Hooks and functions → Android 标签页,启用 SSL Pinning 相关 hook。 ### B. Root 检测绕过 在 Hooks and functions → Android 标签页,启用 Root detection 相关 hook。 ### C. 自定义 Hook 在 brida.js 中编写自定义 hook 逻辑: ```javascript // Hook 特定方法 Java.perform(function() { var targetClass = Java.use('com.example.TargetClass'); targetClass.targetMethod.implementation = function(param) { console.log("Original param: " + param); var result = this.targetMethod(param); console.log("Original result: " + result); return result; }; }); ``` ## 2. 最佳实践 1. **版本匹配**:确保本地 Frida 版本与 frida-server 版本一致 2. **调试技巧**:使用 console.log 输出调试信息 3. **错误处理**:在 Java.perform 中使用 try-catch 捕获异常 4. **性能优化**:避免在 hook 中执行耗时操作 5. **脚本管理**:为不同应用维护独立的 JS 文件 ## 3. 性能优化 - 使用 spawn 模式而非 attach 模式,稳定性更好 - 及时关闭不需要的 hook,减少性能开销 - 合理使用 Frida 的 setTimeout/setInterval 进行异步处理 # 七、常见问题 ## 1. 安装问题 ### Q: pip install frida 失败 A: 尝试使用国内镜像源或升级 pip 版本: ```bash pip install -i https://pypi.tuna.tsinghua.edu.cn/simple frida ``` ### Q: frida-server 无法启动 A: 检查设备是否 root,文件权限是否正确(755) ## 2. 连接问题 ### Q: Brida 无法连接到 Frida Server A: 检查端口转发是否配置正确: ```bash adb forward tcp:27042 tcp:27042 adb forward tcp:27043 tcp:27043 ``` ### Q: spawn 模式启动失败 A: 检查 Application ID 是否正确,确保 APP 未被系统杀死 ## 3. 运行问题 ### Q: Hook 不生效 A: 确保点击了 Compile & reload JS 按钮,检查 JS 语法是否正确 ### Q: 加解密结果异常 A: 检查密钥、IV 是否正确,确认加密算法和模式匹配 # 八、参考资料 1. [Frida 官方文档](https://frida.re/docs/) 2. [Brida GitHub 项目](https://github.com/federicodotta/Brida) 3. [frida-compile 使用指南](https://github.com/iddoeldor/frida-compile) 4. [微信公众号原文:Brida 实战:一键解密APP HTTPS流量](https://mp.weixin.qq.com/s/RT8xhVEsv6gKWYB_BXKRbQ) 最后修改:2026 年 02 月 03 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏