1.1内存漫游
列出内存中所有的类
android hooking list classes
内存中搜索所有的类
android hooking search classes display
内存中搜索所有的方法
# android hooking search methods display
列出类的所有方法
# android hooking list class_methods com.android.settings.DisplaySettings
直接生成hook代码
# android hooking generate simple com.android.settings.DisplaySettings
1.2(hook)
hook类的所有方法
我们以手机连接蓝牙耳机播放音乐为例为例,看看手机蓝牙接口的动态信息。首先我们将手机连接上我的蓝牙耳机——,并可以正常播放音乐;然后我们按照上文的方法,搜索一下与蓝牙相关的类,搜到一个高度可疑的类:android.bluetooth.BluetoothDevice。运行以下命令,hook这个类:
# android hooking watch class android.bluetooth.BluetoothDevice
使用jobs list命令可以看到objection为我们创建的Hooks数为57,也就是将android.bluetooth.BluetoothDevice类下的所有方法都hook了。
这时候我们在设置→声音→媒体播放到上进行操作,在蓝牙耳机与“此设备”之间切换时,会命中这些hook之后,此时objection就会将方法打印出来,会将类似这样的信息“吐”出来:
com.android.settings on (google: 9) [usb] # (agent) [h0u5g7uclo] Called android.bluetooth.BluetoothDevice.getService()
(agent) [h0u5g7uclo] Called android.bluetooth.BluetoothDevice.isConnected()
(agent) [h0u5g7uclo] Called android.bluetooth.BluetoothDevice.getService()
(agent) [h0u5g7uclo] Called android.bluetooth.BluetoothDevice.getAliasName()
(agent) [h0u5g7uclo] Called android.bluetooth.BluetoothDevice.getAlias()
(agent) [h0u5g7uclo] Called android.bluetooth.BluetoothDevice.getName()
(agent) [h0u5g7uclo] Called android.bluetooth.BluetoothDevice.equals(java.lang.Object)
(agent) [h0u5g7uclo] Called android.bluetooth.BluetoothDevice.getService()
。。。。。
可以看到我们的切换操作,调用到了android.bluetooth.BluetoothDevice类中的多个方法。
hook方法的参数、返回值和调用栈
在这些方法中,我们对哪些方法感兴趣,就可以查看哪些个方法的参数、返回值和调用栈,比如想看getName()方法,则运行以下命令:
# android hooking watch class_method android.bluetooth.BluetoothDevice.getName --dump-args --dump-return --dump-backtrace
注意最后加上的三个选项–dump-args --dump-return --dump-backtrace,为我们成功打印出来了我们想要看的信息,其实返回值Return Value就是getName()方法的返回值,
hook方法的所有重载
objection的help中指出,在hook给出的单个方法的时候,会hook它的所有重载。
# help android hooking watch class_method
Command: android hooking watch class_method
Usage: android hooking watch class_method <fully qualified class method> <optional overload>
(optional: --dump-args) (optional: --dump-backtrace)
(optional: --dump-return)
Hooks a specified class method and reports on invocations, together with
the number of arguments that method was called with. This command will
also hook all of the methods available overloads unless a specific
overload is specified.
If the --include-backtrace flag is provided, a full stack trace that
lead to the methods invocation will also be dumped. This would aid in
discovering who called the original method.
Examples:
android hooking watch class_method com.example.test.login
android hooking watch class_method com.example.test.helper.executeQuery
android hooking watch class_method com.example.test.helper.executeQuery "java.lang.String,java.lang.String"
android hooking watch class_method com.example.test.helper.executeQuery --dump-backtrace
android hooking watch class_method com.example.test.login --dump-args --dump-return
那我们可以用File类的构造器来试一下效果。
# android hooking watch class_method java.io.File.$init --dump-args
Wallbreaker + objection
启动frida-server,使用 -P 参数带着插件启动 objection: objection -g com.app.name explore -P ~/.objection/plugins
或者
plugin load 插件目录
搜索类
plugin wallbreaker classsearch <pattern>
根据给的 pattern 对所有类名进行匹配,列出匹配到的所有类名。
搜索对象
plugin wallbreaker objectsearch <classname>
根据类名搜索内存中已经被创建的实例,列出 handle 和 toString() 的结果。
ClassDump
plugin wallbreaker classdump <classname> [--fullname]
输出类的结构, 若加了 --fullname 参数,打印的数据中类名会带着完整的包名。
ObjectDump
plugin wallbreaker objectdump <handle> [--fullname]
objection + Friday_dump
常用命令
plugin dexdump search
plugin dexdump dump