使用Frida攻击安卓应用程序 - 嘶吼 RoarTalk – 网络安全行业综合服务平台,4hou.com

使用Frida攻击安卓应用程序

DarkEye 移动安全 2019-01-31 10:00:54
311648
收藏

导语:本文将为大家展示如何使用Frida工具来攻击安卓应用程序。

大家好,今天我想给大家展示的是如何使用Frida工具来攻击安卓应用程序。我可是花了好几个小时的时间才把这个Frida工具安装好的,最后发现,其实并不是很难,我只是没有找到一个对于像我这样的移动安全初学者的良好教程。所以我才决定做这个教程,给移动安全初学者提供一个参考,如果你知道Frida是什么,你可以直接跳到step0:开始安装Frida。

Frida是什么?

Frida官网上是这么说的:

它是针对本地APP的类似油猴插件的东西,用更专业的术语来说,它是一个动态代码检测toolkit。它可以让你注入JavaScript代码片段或者你自己的库到Windows中的APP中,也可以注入到macOS,GNU/Linux,iOS,Android和QNX的APP中。Frida还提供了一些构建在Frida之上的简单工具。这些工具你可以直接使用,也可以根据自己的需求来调整,或者是作为如何使用API的示例。

简而言之,Frida就是一个让你可以注入脚本到本地APP(此案例我们将注入到安卓APP中)中的工具,从而修改APP的行为(在这里例子中,我们可以绕过ssl pinning并执行中间人攻击,即使APP使用的是HTTPS/SSL连接),并且实时的进行动态测试。

声明:此方法不适用于使用HSTS协议的APP,比如Facebook,Instagram,Twitter,PayPal和银行APP,不过不用担心,现在绝大多数APP还没有使用这个HSTS协议。

step0—环境配置

电脑端

· Python2.7

· Python pip

· adb工具

· 本地代理(Burpsuite)

Android端

· root过的安卓手机(我的是一加手机 Android8.1)

· 安卓模拟器,Android4.4.4到8.1

step1—电脑安装Frida

# installing frida via terminal, sometimes you need to run this command as sudo
pip install frida-tools

step2—设备上安装frida-server

由于安卓设备有很多种不同的架构,所以我们需要搞清楚我们的设备是什么处理器,我们需要把手机跟电脑连接(要先激活USB调试选项),然后运行下列命令:

# getting the processor arquitecture in this case is ARM, there are also x86, x86_64, etc ...
adb shell getprop ro.product.cpu.abi
ouput: armeabi-v7a

OK,知道架构之后,我们就可以下载对应的Frida服务器版本了,下载的GitHub链接在这里https://github.com/frida/frida/releases,由于最新的版本不好用,这里我建议大家下载frida-server-12.0.5-android-arm.xz,下载好之后,我们需要解压这个frida server,然后将它复制到设备中。

# extracting frida-server binary from the xz file
# for linux distributions
tar -xJf frida-server-12.0.5-android-arm.xz
# for macOS or BSD based
unxz frida-server-12.0.5-android-arm.xz
 
# then we need to copy the frida-server binary to the device with adb
adb push ./frida-server-12.0.5-android-arm /data/local/tmp/

step3—frida中的hello进程

一旦我们在电脑端安装好了frida,在安卓端安装好了frida-server,我们就可以使用下面的命令与frida进行交互了:

# first we need to start frida-server with this adb command
# the last '&' is to run the command in background
# disable SELinux is very important I was looking about 4 hours trying to see what happened and SELinux was preventing the success frida-server execution, also frida-server must run as root
adb shell 'su -c setenforce 0'
adb shell 'su -c /data/local/tmp/frida-server-12.0.5-android-arm &'
 
# then if everything works you can see frida's hello world with
# frida-ps is for list the devices process and -U flag is for usb devices
frida-ps -U

1.png

step4—配置Burpsuite

在我们的设备之间建立连接的最快的方式就是将安卓设备和电脑连接到同一个WiFi中,所以我们需要在安卓设备中把WiFi连接修改为手动配置代理,然后设置Burpsuite代理为本机IP,具体配置如下图:

2.png 

当然,我们还需要安装Burpsuite证书。只要安卓设备的代理设置好了,我们就可以在浏览器中访问https://burp这个链接,然后点击CA证书按钮下载证书(注意:你需要将证书后缀der改成cer)如图:

3.png

最后一步—绕过SSL Pinning

现在,我们已经安装好了frida,Frida-server,Burpsuite也配置好了。下一步就是运行“通用安卓SSL Pinning Bypass No.2”脚本来开始嗅探应用程序的连接了,我们先要下载这个脚本并保存在本地。这里有一篇博文是讲解该脚本的(你可以从这个repo里添加多个脚本到frida里,也可以自定义脚本)

/*
   Universal Android SSL Pinning Bypass
   by Mattia Vinci and Maurizio Agazzini
 
   $ frida -U -f org.package.name -l universal-ssl-check-bypass.js --no-pause
 
    https://techblog.mediaservice.net/2018/11/universal-android-ssl-check-bypass-2/
*/
 
Java.perform(function() {
 
    var array_list = Java.use("java.util.ArrayList");
    var ApiClient = Java.use('com.android.org.conscrypt.TrustManagerImpl');
 
    ApiClient.checkTrustedRecursive.implementation = function(a1, a2, a3, a4, a5, a6) {
        // console.log('Bypassing SSL Pinning');
        var k = array_list.$new();
        return k;
    }
 
}, 0);

现在我们唯一要做的就是保存脚本,这里我们保存为“Frida-ssl-2.js”,然后运行下列命令:

# the -l flag is to run custom script, in this case ssl pinning 2 script
# the -f flag is for the apk package name, --no-paus option to not interrupt
# the app startup at all and still leave the spawning of the process to Frida.
 
frida -U -l frida-ssl-2.js --no-paus -f com.example.application

然后程序就开始运行了,我们可以在Burpsuite中看到结果,如图:

4.png

到这一步,我们可以看到已经使用frida成功绕过了ssl pinning,你可以对安卓应用程序进行抓包分析和实施进一步攻击了。

参考文献:

http://asvid.github.io/android-frida-hackinghttps://koz.io/using-frida-on-android-without-root/

https://www.codemetrix.net/hacking-android-apps-with-frida-1/

https://www.notsosecure.com/pentesting-android-apps-using-frida/

https://android.jlelse.eu/hacking-android-app-with-frida-a85516f4f8b7

https://www.securitynewspaper.com/2017/07/25/universal-android-ssl-pinning-bypass-frida/m

  • 分享至
取消

感谢您的支持,我会继续努力的!

扫码支持

打开微信扫一扫后点击右上角即可分享哟

发表评论

 
本站4hou.com,所使用的字体和图片文字等素材部分来源于原作者或互联网共享平台。如使用任何字体和图片文字有侵犯其版权所有方的,嘶吼将配合联系原作者核实,并做出删除处理。
©2024 北京嘶吼文化传媒有限公司 京ICP备16063439号-1 本站由 提供云计算服务