一枚酸心果子

果子果子果子果子果子~~~

Objection使用指南:基于Frida的移动安全测试神器

Objection简介

什么是Objection

Objection是一个基于Frida的移动安全测试工具,主要特点:

核心优势

  • 易用性:简单的命令行操作
  • 功能丰富:内置多种安全测试功能
  • 基于Frida:继承Frida的强大能力
  • 社区活跃:持续更新和维护

Objection安装配置

1. 安装Objection

1
2
3
4
5
6
7
8
# 安装Objection
pip install objection

# 验证安装
objection --version

# 查看帮助
objection --help

2. Android环境配置

1
2
3
4
5
6
7
8
# 确保Frida Server已启动
adb shell /data/local/tmp/frida-server &

# 列出设备
frida-ls-devices

# 列出进程
frida-ps -U

3. 连接设备

1
2
3
4
5
6
7
8
# 连接Android设备
objection -g com.example.app explore

# 连接iOS设备
objection -g com.example.app -N explore

# 指定设备连接
objection -g com.example.app -d 设备ID explore

基础使用命令

1. 环境信息

1
2
3
4
5
6
7
8
9
10
11
# 查看环境信息
env

# 查看设备信息
device info

# 查看应用信息
app info

# 查看内存信息
memory list modules

2. 文件系统操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 列出文件
ls

# 查看文件内容
cat /path/to/file

# 下载文件
file download /path/to/file

# 上传文件
file upload local_file /path/to/remote

# 查看文件权限
ls -la

3. 进程管理

1
2
3
4
5
6
7
8
9
10
11
# 列出进程
ps

# 查看进程详情
ps | grep target

# 杀死进程
kill <pid>

# 查看进程内存
memory list modules

核心功能模块

1. 内存分析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 查看内存模块
memory list modules

# 搜索内存
memory search --string "target_string"

# 搜索模式
memory search --pattern "41 42 43 44"

# 查看内存区域
memory list ranges

# 读取内存
memory read <address> <size>

2. Hook功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Hook Java方法
android hooking list classes

# 搜索类
android hooking list classes | grep -i target

# Hook方法
android hooking watch class_method "com.example.TargetClass.targetMethod" --dump-args --dump-return

# Hook所有方法
android hooking watch class_method "com.example.TargetClass.*" --dump-args --dump-return

# Hook构造函数
android hooking watch class_method "com.example.TargetClass.$init" --dump-args --dump-return

3. 网络监控

1
2
3
4
5
6
7
8
# 监控网络
android hooking watch class_method "okhttp3.OkHttpClient.newCall" --dump-args --dump-return

# 监控HTTP请求
android hooking watch class_method "okhttp3.Request$Builder.build" --dump-args --dump-return

# 监控SSL
android hooking watch class_method "javax.net.ssl.SSLContext.init" --dump-args --dump-return

4. 加密分析

1
2
3
4
5
6
7
8
# Hook加密函数
android hooking watch class_method "javax.crypto.Cipher.doFinal" --dump-args --dump-return

# Hook哈希函数
android hooking watch class_method "java.security.MessageDigest.digest" --dump-args --dump-return

# Hook随机数生成
android hooking watch class_method "java.security.SecureRandom.nextBytes" --dump-args --dump-return

实用Hook技巧

1. 绕过Root检测

1
2
3
4
5
6
7
8
# Hook文件存在检查
android hooking watch class_method "java.io.File.exists" --dump-args --dump-return

# Hook系统属性获取
android hooking watch class_method "android.os.SystemProperties.get" --dump-args --dump-return

# Hook进程检查
android hooking watch class_method "java.lang.Runtime.exec" --dump-args --dump-return

2. 绕过SSL Pinning

1
2
3
4
5
6
7
8
# Hook证书验证
android hooking watch class_method "javax.net.ssl.X509TrustManager.checkServerTrusted" --dump-args --dump-return

# Hook SSL上下文
android hooking watch class_method "javax.net.ssl.SSLContext.init" --dump-args --dump-return

# Hook证书固定
android hooking watch class_method "okhttp3.CertificatePinner.check" --dump-args --dump-return

3. 监控数据库操作

1
2
3
4
5
6
7
8
# Hook SQLite操作
android hooking watch class_method "android.database.sqlite.SQLiteDatabase.execSQL" --dump-args --dump-return

# Hook数据库查询
android hooking watch class_method "android.database.sqlite.SQLiteDatabase.query" --dump-args --dump-return

# Hook数据库插入
android hooking watch class_method "android.database.sqlite.SQLiteDatabase.insert" --dump-args --dump-return

高级功能

1. 内存搜索

1
2
3
4
5
6
7
8
9
10
11
# 搜索字符串
memory search --string "password"

# 搜索十六进制
memory search --pattern "41 42 43 44"

# 搜索正则表达式
memory search --regex ".*password.*"

# 搜索范围
memory search --string "target" --range 0x1000 0x2000

2. 内存修改

1
2
3
4
5
6
7
8
# 修改内存
memory write <address> <value>

# 修改字符串
memory write_string <address> "new_string"

# 修改字节
memory write_bytes <address> "41 42 43 44"

3. 动态分析

1
2
3
4
5
6
7
8
# 动态Hook
android hooking watch class_method "com.example.TargetClass.targetMethod" --dump-args --dump-return

# 实时监控
android hooking watch class_method "com.example.TargetClass.*" --dump-args --dump-return

# 条件Hook
android hooking watch class_method "com.example.TargetClass.targetMethod" --dump-args --dump-return --dump-backtrace

实战案例

案例1:绕过银行APP检测

这个案例演示如何使用Objection绕过银行APP的各种安全检测机制:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 启动Objection并连接银行APP
objection -g com.bank.app explore

# 1. Hook Root检测 - 绕过Root权限检测
android hooking watch class_method "com.bank.security.RootDetector.isRooted" --dump-args --dump-return

# 2. Hook调试检测 - 绕过调试模式检测
android hooking watch class_method "com.bank.security.DebugDetector.isDebugging" --dump-args --dump-return

# 3. Hook文件检查 - 隐藏Root相关文件
android hooking watch class_method "java.io.File.exists" --dump-args --dump-return

# 4. Hook系统属性 - 伪造系统属性值
android hooking watch class_method "android.os.SystemProperties.get" --dump-args --dump-return

# 5. Hook进程检查 - 隐藏Root相关进程
android hooking watch class_method "java.lang.Runtime.exec" --dump-args --dump-return

# 6. Hook网络检测 - 绕过网络环境检测
android hooking watch class_method "android.net.ConnectivityManager.getActiveNetworkInfo" --dump-args --dump-return

案例2:分析加密算法

这个案例演示如何使用Objection分析应用的加密算法和密钥管理:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 启动Objection并连接目标APP
objection -g com.example.app explore

# 1. Hook加密函数 - 获取加密输入和输出
android hooking watch class_method "com.example.Crypto.encrypt" --dump-args --dump-return

# 2. Hook解密函数 - 获取解密输入和输出
android hooking watch class_method "com.example.Crypto.decrypt" --dump-args --dump-return

# 3. Hook密钥生成 - 分析密钥生成过程
android hooking watch class_method "com.example.Crypto.generateKey" --dump-args --dump-return

# 4. Hook哈希函数 - 分析哈希算法使用
android hooking watch class_method "java.security.MessageDigest.digest" --dump-args --dump-return

# 5. Hook随机数生成 - 分析随机数生成
android hooking watch class_method "java.security.SecureRandom.nextBytes" --dump-args --dump-return

# 6. Hook证书操作 - 分析证书使用
android hooking watch class_method "java.security.cert.Certificate.getPublicKey" --dump-args --dump-return

案例3:监控网络请求

这个案例演示如何使用Objection监控和分析应用的网络通信:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 启动Objection并连接目标APP
objection -g com.example.app explore

# 1. Hook HTTP请求构建 - 监控请求URL和参数
android hooking watch class_method "okhttp3.Request$Builder.build" --dump-args --dump-return

# 2. Hook HTTP响应处理 - 监控响应数据
android hooking watch class_method "okhttp3.Response.body" --dump-args --dump-return

# 3. Hook URL构建 - 监控URL构建过程
android hooking watch class_method "okhttp3.HttpUrl$Builder.build" --dump-args --dump-return

# 4. Hook请求头设置 - 监控请求头信息
android hooking watch class_method "okhttp3.Request$Builder.addHeader" --dump-args --dump-return

# 5. Hook请求体设置 - 监控请求体数据
android hooking watch class_method "okhttp3.Request$Builder.post" --dump-args --dump-return

# 6. Hook响应解析 - 监控响应解析过程
android hooking watch class_method "okhttp3.ResponseBody.string" --dump-args --dump-return

Objection插件系统

1. 插件安装

Objection支持多种插件安装方式:

内置插件

1
2
3
4
5
6
7
8
# 查看所有可用插件
plugin list

# 查看插件详细信息
plugin show <plugin_name>

# 加载插件
plugin load <plugin_name>

第三方插件安装

1
2
3
4
5
6
7
8
9
10
# 1. 通过pip安装第三方插件
pip install objection-plugin-name

# 2. 手动安装插件
# 下载插件文件到 ~/.objection/plugins/ 目录
mkdir -p ~/.objection/plugins/
cp plugin.py ~/.objection/plugins/

# 3. 重启Objection加载插件
objection -g com.example.app explore

2. 常用插件

Android Hook插件

1
2
3
4
5
6
7
8
9
10
11
# 加载Android Hook插件
plugin load android

# Hook Activity生命周期
android hooking watch class_method "android.app.Activity.onCreate" --dump-args --dump-return

# Hook Service生命周期
android hooking watch class_method "android.app.Service.onCreate" --dump-args --dump-return

# Hook BroadcastReceiver
android hooking watch class_method "android.content.BroadcastReceiver.onReceive" --dump-args --dump-return

内存分析插件

1
2
3
4
5
6
7
8
9
10
11
# 加载内存分析插件
plugin load memory

# 搜索内存中的字符串
memory search --string "password"

# 搜索内存中的模式
memory search --pattern "41 42 43 44"

# 读取内存数据
memory read <address> <size>

网络监控插件

1
2
3
4
5
6
7
8
9
10
11
# 加载网络监控插件
plugin load network

# 监控HTTP请求
network monitor

# 监控SSL连接
network ssl

# 监控DNS查询
network dns

3. 重要第三方插件

Wallbreaker插件

Wallbreaker是一个强大的内存分析插件,专门用于Android应用的内存dump和分析:

安装方法:

1
2
3
4
5
6
7
8
# 1. 下载Wallbreaker插件
git clone https://github.com/hluwa/Wallbreaker.git

# 2. 安装依赖
pip install objection

# 3. 将插件文件复制到Objection插件目录
cp Wallbreaker/objection_plugin.py ~/.objection/plugins/wallbreaker.py

主要功能:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 启动Objection并加载Wallbreaker
objection -g com.example.app explore
plugin load wallbreaker

# 1. 内存搜索功能
# 搜索字符串
memory search --string "password"

# 搜索类名
memory search --string "com.example.TargetClass"

# 搜索方法名
memory search --string "targetMethod"

# 2. 内存dump功能
# 导出所有类
memory export classes

# 导出特定类
memory export class com.example.TargetClass

# 导出方法
memory export method com.example.TargetClass.targetMethod

# 3. 内存修改功能
# 修改内存值
memory write <address> <value>

# 修改字符串
memory write_string <address> "new_string"

# 4. 内存监控功能
# 监控内存分配
memory monitor alloc

# 监控内存释放
memory monitor free

实战应用:

1
2
3
4
5
6
7
8
9
10
11
12
# 案例:分析加密算法
# 1. 搜索加密相关类
memory search --string "Cipher"

# 2. 导出加密类
memory export class javax.crypto.Cipher

# 3. 监控加密方法调用
memory monitor method javax.crypto.Cipher.doFinal

# 4. 修改加密参数
memory write <key_address> <new_key>

FRIDA-DEXDump插件

FRIDA-DEXDump是一个专门用于Android应用DEX文件dump的插件:

安装方法:

1
2
3
4
5
6
7
8
# 1. 下载FRIDA-DEXDump
git clone https://github.com/hluwa/FRIDA-DEXDump.git

# 2. 安装依赖
pip install frida

# 3. 将插件文件复制到Objection插件目录
cp FRIDA-DEXDump/objection_plugin.py ~/.objection/plugins/frida_dexdump.py

主要功能:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 启动Objection并加载FRIDA-DEXDump
objection -g com.example.app explore
plugin load frida_dexdump

# 1. DEX文件搜索
# 搜索内存中的DEX文件
dexdump search

# 搜索特定DEX文件
dexdump search --name "classes.dex"

# 2. DEX文件dump
# 导出所有DEX文件
dexdump export

# 导出特定DEX文件
dexdump export --name "classes.dex"

# 导出到指定目录
dexdump export --output /path/to/output/

# 3. DEX文件分析
# 分析DEX文件结构
dexdump analyze <dex_file>

# 分析类信息
dexdump analyze --class com.example.TargetClass

# 分析方法信息
dexdump analyze --method com.example.TargetClass.targetMethod

# 4. DEX文件修复
# 修复损坏的DEX文件
dexdump fix <dex_file>

# 修复并导出
dexdump fix --export <dex_file>

实战应用:

1
2
3
4
5
6
7
8
9
10
11
12
# 案例:逆向分析应用
# 1. 搜索DEX文件
dexdump search

# 2. 导出DEX文件
dexdump export --output ./dex_files/

# 3. 分析关键类
dexdump analyze --class com.example.Crypto

# 4. 分析方法实现
dexdump analyze --method com.example.Crypto.encrypt

4. 自定义插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 创建自定义插件
class CustomPlugin:
def __init__(self):
self.name = "custom_plugin"
self.description = "自定义插件"

def load(self):
# 插件加载逻辑
pass

def unload(self):
# 插件卸载逻辑
pass

# 注册插件
plugin_manager.register(CustomPlugin())

检测应对方法

1. 反调试检测

当遇到反调试检测时,可以使用以下方法:

1
2
3
4
5
6
7
8
9
10
11
# 1. Hook调试检测函数
android hooking watch class_method "android.os.Debug.isDebuggerConnected" --dump-args --dump-return

# 2. Hook调试器检测
android hooking watch class_method "java.lang.System.getProperty" --dump-args --dump-return

# 3. Hook进程检测
android hooking watch class_method "android.app.ActivityManager.getRunningAppProcesses" --dump-args --dump-return

# 4. Hook调试端口检测
android hooking watch class_method "java.net.Socket.connect" --dump-args --dump-return

2. 反Hook检测

当遇到反Hook检测时,可以使用以下方法:

1
2
3
4
5
6
7
8
9
10
11
# 1. Hook Hook检测函数
android hooking watch class_method "com.example.HookDetector.detectHook" --dump-args --dump-return

# 2. Hook方法替换检测
android hooking watch class_method "java.lang.reflect.Method.invoke" --dump-args --dump-return

# 3. Hook类加载检测
android hooking watch class_method "java.lang.ClassLoader.loadClass" --dump-args --dump-return

# 4. Hook异常检测
android hooking watch class_method "java.lang.Exception.printStackTrace" --dump-args --dump-return

3. 反Frida检测

当遇到反Frida检测时,可以使用以下方法:

1
2
3
4
5
6
7
8
9
10
11
# 1. Hook Frida检测函数
android hooking watch class_method "com.example.FridaDetector.detectFrida" --dump-args --dump-return

# 2. Hook端口检测
android hooking watch class_method "java.net.ServerSocket.bind" --dump-args --dump-return

# 3. Hook进程检测
android hooking watch class_method "java.lang.Runtime.exec" --dump-args --dump-return

# 4. Hook文件检测
android hooking watch class_method "java.io.File.exists" --dump-args --dump-return

4. 反Xposed检测

当遇到反Xposed检测时,可以使用以下方法:

1
2
3
4
5
6
7
8
9
10
11
# 1. Hook Xposed检测函数
android hooking watch class_method "com.example.XposedDetector.detectXposed" --dump-args --dump-return

# 2. Hook类加载检测
android hooking watch class_method "java.lang.ClassLoader.loadClass" --dump-args --dump-return

# 3. Hook方法替换检测
android hooking watch class_method "java.lang.reflect.Method.invoke" --dump-args --dump-return

# 4. Hook异常检测
android hooking watch class_method "java.lang.Exception.printStackTrace" --dump-args --dump-return

5. 反模拟器检测

当遇到反模拟器检测时,可以使用以下方法:

1
2
3
4
5
6
7
8
9
10
11
# 1. Hook模拟器检测函数
android hooking watch class_method "com.example.EmulatorDetector.detectEmulator" --dump-args --dump-return

# 2. Hook硬件检测
android hooking watch class_method "android.os.Build.HARDWARE" --dump-args --dump-return

# 3. Hook属性检测
android hooking watch class_method "android.os.SystemProperties.get" --dump-args --dump-return

# 4. Hook传感器检测
android hooking watch class_method "android.hardware.SensorManager.getSensorList" --dump-args --dump-return

常用脚本

1. 自动Hook脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 保存为hook_script.js
Java.perform(function() {
// Hook文件存在检查
var File = Java.use("java.io.File");
File.exists.implementation = function() {
var path = this.getAbsolutePath();
console.log("检查文件: " + path);

if (path.includes("su") || path.includes("magisk")) {
console.log("隐藏Root文件: " + path);
return false;
}

return this.exists();
};

// Hook系统属性
var SystemProperties = Java.use("android.os.SystemProperties");
SystemProperties.get.overload("java.lang.String", "java.lang.String").implementation = function(key, def) {
console.log("获取属性: " + key);

if (key === "ro.debuggable") {
return "0";
}
if (key === "ro.secure") {
return "1";
}

return this.get(key, def);
};
});

2. 使用脚本

1
2
3
4
5
# 使用自定义脚本
objection -g com.example.app -l hook_script.js explore

# 或者使用Frida命令
frida -U -f com.example.app -l hook_script.js --no-pause

高级技巧

1. 批量Hook

1
2
3
4
5
# 批量Hook多个方法
android hooking watch class_method "com.example.TargetClass.*" --dump-args --dump-return

# 批量Hook多个类
android hooking watch class_method "com.example.*.*" --dump-args --dump-return

2. 条件Hook

1
2
3
4
5
# 带条件的Hook
android hooking watch class_method "com.example.TargetClass.targetMethod" --dump-args --dump-return --dump-backtrace

# 过滤特定参数
android hooking watch class_method "com.example.TargetClass.targetMethod" --dump-args --dump-return --dump-return

3. 性能优化

1
2
3
4
5
# 减少日志输出
android hooking watch class_method "com.example.TargetClass.targetMethod" --dump-args

# 只Hook特定方法
android hooking watch class_method "com.example.TargetClass.specificMethod" --dump-args --dump-return

结语

Objection,这货现在在移动安全圈子里可以说是相当火的一个工具了。它基于Frida构建,但比直接写Frida脚本要简单得多,基本上就是”开箱即用”的感觉。

目前Objection在移动安全测试领域已经站稳了脚跟,很多安全研究员都在用它。它的优势很明显——门槛低,功能全,社区活跃。不过说实话,它也有一些局限性,比如对某些复杂的Hook场景支持还不够完善,性能上也有优化空间。比如说遇到一些特定的对frida的检测的时候,可能会需要自己添加一些特别的hook代码 —– 比如说去翻源码的agent.js的内容里加上自己的hook代码

总的来说,Objection在移动安全测试这个细分领域里算是比较实用的工具,虽然不是什么真正意义上的”神器”,但确实能解决很多实际问题。对于刚入门的朋友来说,是个不错的选择。

持续输出技术分享,您的支持将鼓励我继续创作!