0x00 前言
Frida是一款基于python + javascript 的hook框架,通杀android\ios\linux\win\osx等各平台,由于是基于脚本的交互,因此相比xposed和substrace cydia更加便捷,本文重点介绍Frida在android下面的使用。
Frida的官网为:http://www.frida.re/
https://www.frida.re/docs/home/
0x01 安装和搭建Frida环境
首先要保证你的android手机已经root。
安装easy_install:
sudo apt-get install python-setuptools
再通过easy_install安装frida:
sudo easy_install frida
下载frida-server到android手机上并且运行:
curl -O https://build.frida.re/frida/android/arm/bin/frida-server
adb push frida-server /data/local/tmp/
adb shell
su
cd /data/local/tmp/
chmod 777 frida-server
./frida-server
转发android TCP端口到本地:
adb forward tcp:27042 tcp:27042
adb forward tcp:27043 tcp:27043
测试frida环境,如果出现android手机的进程列表说明搭建成功:
frida-ps -R
PID Name
----- --------------------------------------------
2700 acceleratord
2713 adbd
2798 agnsscontrol
2799 agnsslog
2195 akmd09911
8078 android.process.acore
31283 android.process.media
2185 atcmdserver
4939 chargelogcat
2796 chr_logd
22856 com.android.browser
7912 com.android.contacts
22417 com.android.gallery3d
....
0x02 得到android手机当前最前端Activity所在的进程
其中get_front_app.py的内容如下:
import frida
rdev = frida.get_remote_device()
front_app = rdev.get_frontmost_application()
print front_app
enum_process.py内容如下:
import frida
rdev = frida.get_remote_device()
processes = rdev.enumerate_processes()
for process in processes:
print process
0x04 枚举手机所有已安装的android APP应用
enum_app.py内容如下:
import frida
rdev = frida.get_remote_device()
apps = rdev.enumerate_applications()
for app in apps:
print app
0x05 枚举某个进程加载的所有模块以及模块中的导出函数
import frida
rdev = frida.get_remote_device()
session = rdev.attach("com.tencent.mm")
modules = session.enumerate_modules()
for module in modules:
print module
export_funcs = module.enumerate_exports()
print "\tfunc_name\tRVA"
for export_func in export_funcs:
print "\t%s\t%s"%(export_func.name,hex(export_func.relative_address))
如下代码为hook某个进程的libc.so中的导出函数open
import frida
import sys
rdev = frida.get_remote_device()
session = rdev.attach("com.tencent.mm")
scr = """
Interceptor.attach(Module.findExportByName("libc.so" , "open"), {
onEnter: function(args) {
send("open("+Memory.readCString(args[0])+","+args[1]+")");
},
onLeave:function(retval){
}
});
"""
script = session.create_script(scr)
def on_message(message ,data):
print message
script.on("message" , on_message)
script.load()
sys.stdin.read()
转自:http://www.voidcn.com/blog/autohacker/article/p-4979253.html