Frida操作手册-Android环境准备
本帖最后由 Hoimk 于 2018-12-10 10:27 编辑大扎好,我诈尸了(没人认识,滚出去)
好久没发过文章啥的了,看了一下我的上一个帖子,emmm..2018年1月...(其实我只是不知道该写点啥)
正好前几天@roysue对frida特别感兴趣,于是就拉上我开了一个写Frida教程的Gayhub,刚写完半篇就被我搬到各个社区刷存在感了..
教程尽量小白化,希望大家都看得懂~
Github: https://github.com/hookmaster/frida-all-in-one
建议:先把小星星点上,然后把小眼睛也点上,然后就等着收更新邮件吧
- (#13-androidios)
- (#131-android-root)
- (#1311-%E7%A1%AC%E4%BB%B6%E5%87%86%E5%A4%87)
- (#1312-%E5%88%B7%E5%85%A5%E5%AE%98%E6%96%B9android-81)
- (#1313-%E5%88%B7%E5%85%A5twrp-recovery)
- (#1314-%E5%88%B7%E5%85%A5magisk)
- (#1315-%E8%8E%B7%E5%8F%96root%E6%9D%83%E9%99%90)
- (#132-android-frida-server-%E5%AE%89%E8%A3%85)
### 1.3 Android/iOS
#### 1.3.1 Android root
##### 1.3.1.1 硬件准备
在手机硬件的考虑上,首先优选谷歌的“亲儿子”:`Nexus`和`Pixel`系列,鉴于官网上测试案例在`Nexus 5X`手机,系统为`Android 8.1.0`版本上进行测试,我们也会选用这款手机、和这个系统版本来进行实验。
官网也指出不可能在所有手机和所有ROM上完全进行测试,肯定是具体情况具体分析。
>Also note that most of our recent testing has been taking place on a Nexus 5X running Android 8.1.0. Older and newer ROMs may work, but if you’re running into basic issues like Frida crashing the system when launching an app, this is due to ROM-specific quirks. We cannot test on all possible devices, so we count on your help to improve on this. However if you’re just starting out with Frida it is strongly recommended to go with a Nexus device with factory software, or an official 8.x emulator image for arm or arm64. (x86 may work too but has gone through significantly less testing.)
官网上依旧指出,选择`Android 8.x`系统的模拟器也是没问题的,架构必须选择`arm`或者`arm64`,`x86`可能会有`crash`的情况发生。
`Nexus 5X`这款手机的硬件参数为:
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.1a.png)
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.1b.png)
##### 1.3.1.2 刷入官方`Android 8.1`
frida官网指出的`factory software`就是谷歌的[官方工厂镜像网站](https://developers.google.com/android/images),打开这个网站可能需要科学上网。网站中间有一些操作指南,右边就是手机型号一览表,在这里我们选择`Nexus 5X`的型号`bullhead`。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.2a.png)
可以看到从安卓6到安卓8均支持,而且最新支持到`8.1.0`。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.2b.png)
...
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.2c.png)
我们使用`wget`命令来下载最新的`8.1.0 (OPM7.181205.001, Dec 2018)`版本,这样速度最快。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.2d.png)
下载完成后记得校验`SHA-256 Checksum`,必须得于官网一致,否则下载文件已经损坏,无法使用,必须重新下载。
```
$ openssl dgst -sha256 bullhead-opm7.181205.001-factory-5f189d84.zip
SHA256(bullhead-opm7.181205.001-factory-5f189d84.zip)= 5f189d84781a26b49aca0de84a941a32ae0150da0aab89f1d7709d56c31b3c0a
```
可见`SHA-256 Checksum`与官网相同,接下来就是刷入该系统。
首先将手机进入`fastboot`状态,操作流程如下:
1. 将`USB`线断开,并确保手机有`80%`左右的电量;
2. 将手机完全关机;
3. 同时按住音量向下键和开机键;
4. 手机将进入`fastboot`状态;
状态如下:
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.2e.jpeg)
>PS:如果手机并没有解锁,也就是`DEVICE STATE - `显示`locked`,那手机需要先解锁,得是`unlocked`,也就是图上的状态,才可以后续刷入`recovery`等操作。`Nexus 5X`手机解锁是比较简单的,这里不做演示了。
手机用USB线连上电脑,运行脚本,将系统刷进手机。
```
$ unzip bullhead-opm7.181205.001-factory-5f189d84.zip
Archive:bullhead-opm7.181205.001-factory-5f189d84.zip
creating: bullhead-opm7.181205.001/
inflating: bullhead-opm7.181205.001/radio-bullhead-m8994f-2.6.42.5.03.img
inflating: bullhead-opm7.181205.001/bootloader-bullhead-bhz32c.img
inflating: bullhead-opm7.181205.001/flash-all.bat
inflating: bullhead-opm7.181205.001/flash-all.sh
extracting: bullhead-opm7.181205.001/image-bullhead-opm7.181205.001.zip
inflating: bullhead-opm7.181205.001/flash-base.sh
$ cd bullhead-opm7.181205.001
$ ./flash-all.sh
target reported max download size of 536870912 bytes
sending 'bootloader' (4610 KB)...
OKAY
writing 'bootloader'...
OKAY
finished. total time: 0.371s
rebooting into bootloader...
OKAY
finished. total time: 0.020s
target reported max download size of 536870912 bytes
sending 'radio' (56630 KB)...
OKAY
writing 'radio'...
OKAY
finished. total time: 2.546s
rebooting into bootloader...
OKAY
finished. total time: 0.020s
extracting android-info.txt (0 MB) to RAM...
extracting boot.img (11 MB) to disk... took 0.125s
target reported max download size of 536870912 bytes
archive does not contain 'boot.sig'
archive does not contain 'dtbo.img'
archive does not contain 'dt.img'
extracting recovery.img (17 MB) to disk... took 0.093s
archive does not contain 'recovery.sig'
extracting system.img (1909 MB) to disk... took 17.733s
archive does not contain 'system.sig'
archive does not contain 'vbmeta.img'
extracting vendor.img (185 MB) to disk... took 1.895s
archive does not contain 'vendor.sig'
wiping userdata...
mke2fs 1.43.3 (04-Sep-2016)
Creating filesystem with 2874363 4k blocks and 719488 inodes
Filesystem UUID: 79218aab-c322-4823-a83f-5a26ad3fd27e
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
wiping cache...
mke2fs 1.43.3 (04-Sep-2016)
Creating filesystem with 24576 4k blocks and 24576 inodes
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
--------------------------------------------
Bootloader Version...: BHZ32c
Baseband Version.....: M8994F-2.6.42.5.03
Serial Number........: 00f4d2e97de8bd23
--------------------------------------------
checking product...
OKAY
checking version-bootloader...
OKAY
checking version-baseband...
OKAY
sending 'boot' (11781 KB)...
OKAY
writing 'boot'...
OKAY
sending 'recovery' (17425 KB)...
OKAY
writing 'recovery'...
OKAY
erasing 'system'...
OKAY
sending sparse 'system' 1/4 (508768 KB)...
OKAY [ 14.932s]
writing 'system' 1/4...
OKAY
sending sparse 'system' 2/4 (524238 KB)...
OKAY [ 15.055s]
writing 'system' 2/4...
OKAY
sending sparse 'system' 3/4 (501061 KB)...
OKAY [ 15.391s]
writing 'system' 3/4...
OKAY
sending sparse 'system' 4/4 (421469 KB)...
OKAY [ 12.113s]
writing 'system' 4/4...
OKAY
erasing 'vendor'...
OKAY
sending 'vendor' (190332 KB)...
OKAY
writing 'vendor'...
OKAY
erasing 'userdata'...
OKAY
sending 'userdata' (4284 KB)...
OKAY
writing 'userdata'...
OKAY
erasing 'cache'...
OKAY
sending 'cache' (92 KB)...
OKAY
writing 'cache'...
OKAY
rebooting...
finished. total time: 105.131s
```
刷机完成后,手机会自动重启,重启完成后即可自动进入系统。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.2f.png)
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.2g.png)
##### 1.3.1.3 刷入`twrp recovery`
`recovery`相当于`Windows PE`微型系统,在`recovery`里我们也可以挂载磁盘,修改系统分区,使用`adb`命令,等一系列功能。详细的功能列表可以百度或者谷歌。
我们这里只需要下载`twrp`针对`bullhead`机型的镜像,刷进去即可。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.3a.png)
我们下载最新的`twrp-3.2.3-0-bullhead.img`镜像文件。
然后将手机设置到`fastboot`模式,使用`fastboot`命令将镜像刷进去。
```
$ fastboot flash recovery twrp-3.2.3-0-bullhead.img
target reported max download size of 536870912 bytes
sending 'recovery' (16289 KB)...
OKAY
writing 'recovery'...
OKAY
finished. total time: 0.774s
```
刷完之后,在手机上按两次音量向下键,选择`Recovery mode`,按电源键进入。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.3b.jpeg)
稍等片刻之后,就会进入`twrp 3.2.3-0`系统。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.3c.jpeg)
直接滑开即可。意味着允许修改系统。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.3d.jpeg)
可以看到功能非常丰富。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.3e.jpeg)
##### 1.3.1.4 刷入`Magisk`
自从`SuperSU`卖给中国人,并且不再更新之后,大家已经不怎么使用这款`root`软件了,取而代之的是`Magisk`。
`Magisk`是由中国台湾省小伙儿`topjohnwu`开发的一款完全开源的`root`软件,其`github`项目托管主页在[这里](https://github.com/topjohnwu/Magisk)。
有关`Magisk`的详细中文介绍,大家可以看[这篇文章](https://xposed.appkg.com/2536.html),我们只是用`Magisk`来获取`root`权限。
在`github`项目主页的`release`页面,下载最新的卡刷包:`Magisk-v17.3.zip`
然后使用`adb`命令将卡刷包上传到手机中去。
```
$ adb push Magisk-v17.3.zip /sdcard/
* daemon not running; starting now at tcp:5037
* daemon started successfully
Magisk-v17.3.zip: 1 file pushed. 6.5 MB/s (4178628 bytes in 0.610s)
```
然后使用`twrp`将这个卡刷包安装进手机里。首先点选上一节最后一张图中的`Install`。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.4a.png)
然后选择我们刚刚传输进去的`Magisk-v17.3.zip`卡刷包。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.4b.png)
滑动确认安装。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.4c.png)
安装完成后直接重启即可,`Reboot System`
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.4d.png)
滑动重启。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.4e.png)
重启后发现`Magisk Manager`已经安装好了,并且是作为系统App,卸载不了的。卸载只有安装官网`release`页面里的`Magisk-uninstaller-20181022.zip`卡刷包。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.4f.png)
打开`App`可以看到安装成功。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.4g.png)
##### 1.3.1.5 获取`root`权限
接下来就是使用`adb`命令进入安卓手机的`shell`,并且获取`root`权限,为下一节做好准备。
在手机上找到`设置→系统→关于手机→版本号`,点击`版本号`五下,打开`开发者选项`,然后进入`设置→系统→开发者选项`,打开`USB调试选项`。然后USB连接到电脑,使用`adb`命令连上去。手机上会出现授权,点击接受该指纹的电脑连接。
```
$ adb shell
bullhead:/ $
bullhead:/ $
bullhead:/ $ whoami
shell
bullhead:/ $
```
此时是`shell`权限,权限非常小。我们来切换到`root`用户:
```
bullhead:/ $ su -
```
此时手机上会出现`Magisk`的超级用户请求,点击允许,`com.android.shell`即可获取`root`权限。
![](https://github.com/hookmaster/frida-all-in-one/raw/master/01.%E5%A4%9A%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/pic/1.3.1.5a.png)
点击允许之后,`su -`这个命令才会返回,然后运行`who{防屏蔽}ami`命令,可以看到已经是`root`了。
```
bullhead:/ #
bullhead:/ # whoami
root
bullhead:/ #
bullhead:/ #
```
这时候就可以用`root`的权限来做一些事情了。
#### 1.3.2 Android frida-server 安装
上一节中刷机,获取`root`其实倒是蛮复杂的,这一节安装`frida-server`其实倒是简单很多,我们从官方github页面的`release`标签里,找到最新版的`frida-server`,注意要匹配系统和架构,比如`arm`和`arm64`就不能搞错,比如我们这里选择的就是`frida-server-12.2.26-android-arm64.xz`的版本。
下载完成后进行解压,获得`linux`原生的可执行文件,我们将它重命名为`frida-server`。
```
$ file frida-server
frida-server-arm64: ELF 64-bit LSB shared object ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, stripped
```
使用`adb`命令将其推送到手机上去。
```
$ adb push frida-server /data/local/tmp/
```
然后使用`adb shell`命令进入到手机中去,执行以下命令:
```
$ adb shell
bullhead:/ $ su -
bullhead:/ # whoami
root
bullhead:/ # cd /data/local/tmp/
bullhead:/data/local/tmp # chmod 755 /data/local/tmp/frida-server
bullhead:/data/local/tmp # ./frida-server &
9849
bullhead:/data/local/tmp #
```
`frida-server`即可运行成功。
此时在电脑上新开一个`shell`,运行`frida-ps -U`命令,即可显示手机中正在运行的进程。
```
$ frida-ps -U
PIDName
-------------------------------------------------------
9628-
5389.esfm
591ATFWD-daemon
2953adbd
596android.hardware.biometrics.fingerprint@2.1-service
398android.hardware.cas@1.0-service
399android.hardware.configstore@1.0-service
400android.hardware.dumpstate@1.0-service.bullhead
401android.hardware.graphics.allocator@2.0-service
402android.hardware.usb@1.0-service
403android.hardware.wifi@1.0-service
397android.hidl.allocator@1.0-service
7456android.process.acore
3098android.process.media
567audioserver
568cameraserver
592cnd
588cnss-daemon
977com.android.bluetooth
8829com.android.connectivity.metrics
8275com.android.keychain
3026com.android.nfc
1175com.android.phone
5184com.android.settings
1020com.android.systemui
7414com.android.vending
3417com.estrongs.android.pop
8247com.estrongs.android.pop:local
5916com.google.android.apps.gcs
8711com.google.android.apps.messaging
8747com.google.android.apps.messaging:rcs
7721com.google.android.apps.photos
```
到这里我们在64位手机`Nexus 5X`的安卓原生`8.1`系统上安装`frida-server`就成功了。
frida是一款基于python + javascript 的hook框架,可运行在androidioslinuxwinosx等各平台,主要使用动态二进制插桩技术。 问楼主一个问题,我这边最后打frida-ps -U的时候显示sush:frida-ps not found该怎么解决。百度说是环境配置没有弄好,没搞懂怎么去办这个 留个标记 动态插桩,加watch等更新
好教程,谢谢楼主 不错,学习了一下
不错,学习了一下 期待使用方法教程 完全看不懂 注册时间:情节中字 :eee 好复杂啊