首页 > 系统 > Android > 正文

android平台HOOK框架汇总之Frida

2019-11-06 08:39:39
字体:
来源:转载
供稿:网友

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 -R
PID  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 process

0x04 枚举手机所有已安装的android APP应用

enum_app.py内容如下:

import fridardev = frida.get_remote_device()apps = rdev.enumerate_applications()for app in apps:	print app

0x05 枚举某个进程加载的所有模块以及模块中的导出函数

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表