Android渗透测试frida——Brida插件加解密实战演示
字数 1443 2025-08-22 12:22:24

Android渗透测试:使用Brida插件实现加解密实战教程

一、Brida简介与环境准备

1.1 Brida概述

Brida是一个Burpsuite插件,用于将Frida的功能集成到Burpsuite中,主要功能包括:

  • Brida.jar:Burpsuite插件
  • bridaServicePyro:用于Frida适配到Burpsuite的Python脚本
  • script.js:注入到目标应用的JavaScript脚本

1.2 环境要求

  • Android 8.1.0 (Pixel设备)
  • Burpsuite 1.7
  • Windows 10
  • Python 2.7 (仅支持2.7版本)
  • Frida
  • Pyro4 (pip install Pyro4)

1.3 安装步骤

  1. 安装Frida:参考Frida安装指南
  2. 在Burpsuite中安装Brida插件
  3. 安装Pyro4:pip install Pyro4

二、实战环境搭建

2.1 测试APK安装

  1. 安装测试APK:adb install -t esebrida.apk
  2. APK功能:包含服务器地址设置功能

2.2 服务端准备

  1. 使用phpstudy在www目录下运行AndroidLogin.php
  2. 浏览器访问验证服务是否正常:http://192.168.3.254/AndroidLogin.php
  3. 将服务器地址填入APK设置中

2.3 代理设置

  1. Burpsuite设置代理
  2. 手机WiFi设置代理指向Burpsuite

三、APK逆向分析

3.1 反编译分析

使用JEB反编译APK,发现关键类:

  • com.ese.http.encrypt.AesEncryptionBase64:加解密实现类
  • 密钥硬编码:9876543210123456

3.2 加解密流程

  1. 加密:AES加密后Base64编码
  2. 解密:Base64解码后AES解密

四、Brida脚本开发

4.1 基础脚本框架

'use strict';

// 1 - FRIDA EXPORTS
rpc.exports = {
    exportedFunction: function() {
    },
    contextcustom1: function(message) {
        console.log("Brida start :--->");
        return "Brida test1";
    },
    getplatform: function() {
        if (Java.available) {
            return 0;
        } else if (ObjC.available) {
            return 1;
        } else {
            return 2;
        }
    }
}

4.2 加密函数实现

contextcustom2: function(message) {
    console.log("Brida Java Starting script ---->ok");
    var enc;
    Java.perform(function() {
        try {
            var key = "9876543210123456";
            var text = "admin";
            //hook class
            var AesEncryptionBase64 = Java.use('com.ese.http.encrypt.AesEncryptionBase64');
            console.log("Brida start : encrypt before--->" + text);
            //hook method
            enc = AesEncryptionBase64.encrypt(key, text);
            console.log("Brida start : encrypt after--->" + enc);
        } catch(error) {
            console.log("[!]Exception:" + error.message);
        }
    });
    return enc;
}

4.3 完整脚本实现

'use strict';

// 1 - FRIDA EXPORTS
rpc.exports = {
    //AesEncryptionBase64 encrypt
    contextcustom1: function(message) {
        console.log("Brida start :0--->" + message);
        var data = hexToString(message)
        console.log("Brida start :1--->" + data);
        var enc;
        Java.perform(function() {
            try {
                var key = "9876543210123456";
                var text = data;
                //hook class
                var AesEncryptionBase64 = Java.use('com.ese.http.encrypt.AesEncryptionBase64');
                console.log("Brida start : AesEncryptionBase64 ---> success");
                console.log("Brida start : encrypt before--->" + text);
                //hook method
                enc = AesEncryptionBase64.encrypt(key, text);
                console.log("Brida start : encrypt after--->" + enc);
            } catch(error) {
                console.log("[!]Exception:" + error.message);
            }
        });
        return stringToHex(enc);
    },
    
    //AesEncryptionBase64 decrypt
    contextcustom2: function(message) {
        console.log("Brida start :0--->" + message);
        var data = hexToString(message)
        console.log("Brida start :1--->" + data);
        var text;
        Java.perform(function() {
            try {
                var key = "9876543210123456";
                var enc = data;
                //hook class
                var AesEncryptionBase64 = Java.use('com.ese.http.encrypt.AesEncryptionBase64');
                console.log("Brida start : AesEncryptionBase64 ---> success");
                console.log("Brida start : decrypt before--->" + enc);
                //hook method
                text = AesEncryptionBase64.decrypt(key, enc);
                console.log("Brida start : decrypt after--->" + text);
            } catch(error) {
                console.log("[!]Exception:" + error.message);
            }
        });
        console.log("Brida start : decrypt after--->" + stringToHex(text));
        return stringToHex(text);
    },
    
    getplatform: function() {
        if (Java.available) {
            return 0;
        } else if (ObjC.available) {
            return 1;
        } else {
            return 2;
        }
    }
}

// Convert a ASCII string to a hex string
function stringToHex(str) {
    return str.split("").map(function(c) {
        return ("0" + c.charCodeAt(0).toString(16)).slice(-2);
    }).join("");
}

// Convert a hex string to a ASCII string
function hexToString(hexStr) {
    var hex = hexStr.toString(); //force conversion
    var str = '';
    for (var i = 0; i < hex.length; i += 2)
        str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
    return str;
}

五、Burpsuite集成与使用

5.1 启动流程

  1. 运行Frida服务:python startFridaService.py
  2. 在Burpsuite中启动Brida
  3. 加载并执行编写好的JS脚本

5.2 功能对应关系

Burpsuite右键菜单中的四个方法与脚本函数对应:

  1. Brida Custom 1 → contextcustom1 (加密)
  2. Brida Custom 2 → contextcustom2 (解密)
  3. Brida Custom 3 → contextcustom3 (加密)
  4. Brida Custom 4 → contextcustom4 (解密)

5.3 使用效果

  1. 解密:对加密的请求/响应数据进行解密
  2. 加密:对修改后的明文数据进行加密

六、注意事项

  1. 数据格式转换:Burpsuite传递的数据是hex格式,需要先转换为字符串再进行加解密操作
  2. 脚本加载:修改脚本后需要重启Burpsuite才能生效
  3. 错误处理:脚本中应包含完善的错误处理机制
  4. 密钥管理:实际应用中应避免硬编码密钥

七、扩展应用

  1. 自动化测试:结合Burpsuite的Intruder模块实现自动化爆破
  2. 动态分析:实时监控应用的加解密过程
  3. 协议分析:逆向分析未知的通信协议

通过本教程,您已经掌握了使用Brida插件在Android渗透测试中实现加解密操作的全流程,这将极大提升对加密通信应用的测试效率。

Android渗透测试:使用Brida插件实现加解密实战教程 一、Brida简介与环境准备 1.1 Brida概述 Brida是一个Burpsuite插件,用于将Frida的功能集成到Burpsuite中,主要功能包括: Brida.jar:Burpsuite插件 bridaServicePyro:用于Frida适配到Burpsuite的Python脚本 script.js:注入到目标应用的JavaScript脚本 1.2 环境要求 Android 8.1.0 (Pixel设备) Burpsuite 1.7 Windows 10 Python 2.7 (仅支持2.7版本) Frida Pyro4 ( pip install Pyro4 ) 1.3 安装步骤 安装Frida:参考 Frida安装指南 在Burpsuite中安装Brida插件 安装Pyro4: pip install Pyro4 二、实战环境搭建 2.1 测试APK安装 安装测试APK: adb install -t esebrida.apk APK功能:包含服务器地址设置功能 2.2 服务端准备 使用phpstudy在www目录下运行AndroidLogin.php 浏览器访问验证服务是否正常:http://192.168.3.254/AndroidLogin.php 将服务器地址填入APK设置中 2.3 代理设置 Burpsuite设置代理 手机WiFi设置代理指向Burpsuite 三、APK逆向分析 3.1 反编译分析 使用JEB反编译APK,发现关键类: com.ese.http.encrypt.AesEncryptionBase64 :加解密实现类 密钥硬编码: 9876543210123456 3.2 加解密流程 加密:AES加密后Base64编码 解密:Base64解码后AES解密 四、Brida脚本开发 4.1 基础脚本框架 4.2 加密函数实现 4.3 完整脚本实现 五、Burpsuite集成与使用 5.1 启动流程 运行Frida服务: python startFridaService.py 在Burpsuite中启动Brida 加载并执行编写好的JS脚本 5.2 功能对应关系 Burpsuite右键菜单中的四个方法与脚本函数对应: Brida Custom 1 → contextcustom1 (加密) Brida Custom 2 → contextcustom2 (解密) Brida Custom 3 → contextcustom3 (加密) Brida Custom 4 → contextcustom4 (解密) 5.3 使用效果 解密 :对加密的请求/响应数据进行解密 加密 :对修改后的明文数据进行加密 六、注意事项 数据格式转换 :Burpsuite传递的数据是hex格式,需要先转换为字符串再进行加解密操作 脚本加载 :修改脚本后需要重启Burpsuite才能生效 错误处理 :脚本中应包含完善的错误处理机制 密钥管理 :实际应用中应避免硬编码密钥 七、扩展应用 自动化测试 :结合Burpsuite的Intruder模块实现自动化爆破 动态分析 :实时监控应用的加解密过程 协议分析 :逆向分析未知的通信协议 通过本教程,您已经掌握了使用Brida插件在Android渗透测试中实现加解密操作的全流程,这将极大提升对加密通信应用的测试效率。