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-serveradb push frida-server /data/local/tmp/adb shellsucd /data/local/tmp/chmod 777 frida-server./frida-server转发android TCP端口到本地:
adb forward tcp:27042 tcp:27042adb forward tcp:27043 tcp:27043测试frida环境,如果出现android手机的进程列表说明搭建成功:
frida-ps -RPID Name----- -------------------------------------------- 2700 acceleratord 2713 adbd 2798 agnsscontrol 2799 agnsslog 2195 akmd09911 8078 android.PRocess.acore31283 android.process.media 2185 atcmdserver 4939 chargelogcat 2796 chr_logd22856 com.android.browser 7912 com.android.contacts22417 com.android.gallery3d....0x02 得到android手机当前最前端Activity所在的进程
其中get_front_app.py的内容如下:
import fridardev = frida.get_remote_device()front_app = rdev.get_frontmost_application()print front_app0x03 枚举android手机所有的进程
enum_process.py内容如下:
import fridardev = frida.get_remote_device()processes = rdev.enumerate_processes()for process in processes: print process0x04 枚举手机所有已安装的android APP应用
enum_app.py内容如下:
import fridardev = frida.get_remote_device()apps = rdev.enumerate_applications()for app in apps: print app0x05 枚举某个进程加载的所有模块以及模块中的导出函数
import fridardev = 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))0x06 hook android的native函数如下代码为hook某个进程的libc.so中的导出函数open
import fridaimport sysrdev = 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 messagescript.on("message" , on_message)script.load()sys.stdin.read()0x06 hook android的java层函数转自:http://www.voidcn.com/blog/autohacker/article/p-4979253.html
新闻热点
疑难解答