一例简单的frida反调试绕过

简介: 一例简单的frida反调试绕过

前言


最近在分析一款app时遇见了frida反调试,花了时间简单学习了一下,有不少收获,记录下学习的过程。


抛出问题


frida是一个很强大的hook框架,用的人多了,自然而然就出现了很多检测方案,这次碰到的app就检测了frida,可以正常打开,但是当你用frida -f启动或者attach进程,不久后就会闪退。  


常见frida检测


1.检测frida-server文件名  

2.检测27042默认端口  

3.检测D-Bus  

4.检测/proc/pid/maps映射文件  

5.检测/proc/pid/tast/tid/stat或/proc/pid/tast/tid/status    

6.双进程保护  


前两种可以通过修改frida-server文件名,改默认端口绕过。双进程可以通过-f spawn模式启动绕过。其他的需要去hook修改。  


定位


先针对简单的几个可能检测的方式,我修改了文件名,改了端口,也尝试了spawn启动,均会在启动后不久闪退。  

这时考虑到其他几种检测。  

首先用frida去看看载入了哪些so,看看是哪里检测了,看了个寂寞。  


  function fridaProcess(){
      Java.perform(function () {
        var enumMoudle = Process.enumerateModules();
        for (var i = 0; i < enumMoudle.length; i++){
          console.log("", enumMoudle[i].name)
        }
      });
    }
  setImmediate(fridaProcess,0)

739e14ae20913b7f5907903a0e5927a2_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


因为so载入的时候,底层最后open去打开的。  

所以再用frida去hook应用中的open函数,看看读取了哪些so或者文件,可以看到最后断在了/proc/self/maps。  


var pth = Module.findExportByName(null,"open");
    Interceptor.attach(ptr(pth),{
        onEnter:function(args){
            this.filename = args[0];
            console.log("",this.filename.readCString())
            if (this.filename.readCString().indexOf(".so") != -1){
                args[0] = ptr(0)
            }
        },onLeave:function(retval){
            return retval;
        }
    })

adace110ab28099147c25a23d61ac94f_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png



稍稍深入


这里当挂上frida后对应的maps文件中会出现re.frida.server之类的特征,这是在使用frida server的时候自动创建的,其中存放着frida的功能模块,可以在载入so的hook脚本输出中能看到最后也是断在frida-agent.so。  


ab53532a61dd6a613731405124d0caab_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


这里要绕过这个检测,我是通过备份一个正常启动时的maps文件(这里前面也讲到app不使用frida是能正常启动不闪退的)。


function main() {
  const openPtr = Module.getExportByName('libc.so', 'open');
  const open = new NativeFunction(openPtr, 'int', ['pointer', 'int']);
  var readPtr = Module.findExportByName("libc.so", "read");
  var read = new NativeFunction(readPtr, 'int', ['int', 'pointer', "int"]);
  var fakePath = "/data/data/com.app/maps";
  var file = new File(fakePath, "w");
  var buffer = Memory.alloc(512);
  Interceptor.replace(openPtr, new NativeCallback(function (pathnameptr, flag) {
      var pathname = Memory.readUtf8String(pathnameptr);
      var realFd = open(pathnameptr, flag);
      if (pathname.indexOf("maps") >= 0) {
          while (parseInt(read(realFd, buffer, 512)) !== 0) {
              var oneLine = Memory.readCString(buffer);
              if (oneLine.indexOf("tmp") === -1) {
                  file.write(oneLine);
              }
          }
          var filename = Memory.allocUtf8String(fakePath);
          return open(filename, flag);
      }
      var fd = open(pathnameptr, flag);
      return fd;
  }, 'int', ['pointer', 'int']));
}
setImmediate(main)

7c17bae9133355b9d9886cc616ced948_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


然后就可以继续调试了。


总结


这只是一个简单的例子,但是确实在这个bypass的过程中学到了东西,只要花时间是去分析,总能找到对应的突破口。  


相关文章
|
网络协议 Android开发 Python
Android 抓包工具r0capture使用
Android 抓包工具r0capture使用
1906 1
|
存储 移动开发 数据安全/隐私保护
高效反编译luac文件
高效反编译luac文件
|
7月前
|
Dart Linux iOS开发
JEB Pro v5.30 (macOS, Linux, Windows) - 逆向工程平台
JEB Pro v5.30 (macOS, Linux, Windows) - 逆向工程平台
687 0
JEB Pro v5.30 (macOS, Linux, Windows) - 逆向工程平台
|
编译器 Linux C语言
C/C++ 常见函数调用约定(__stdcall,__cdecl,__fastcall等):介绍常见函数调用约定的基本概念、用途和作用
C/C++ 常见函数调用约定(__stdcall,__cdecl,__fastcall等):介绍常见函数调用约定的基本概念、用途和作用
1261 0
|
Ubuntu JavaScript 开发工具
Ubuntu上编译多个版本的frida
【7月更文挑战第16天】在Ubuntu上编译多个版本的Frida(如15.1.28和16.1.4),首先确保系统为Ubuntu 20(WSL)或其他版本,并安装`build-essential`, `git`, `lib32stdc++-9-dev`, `libc6-dev-i386`等依赖。还需安装Node.js(例如20.15.1版)。通过`git clone`获取Frida源码,并根据所需版本进入对应分支。设置环境变量以指向正确的NDK和Node.js路径,可通过脚本如`env15.sh`来避免污染全局环境。
594 2
|
存储 Java API
Mac安装jadx并配置环境
Mac安装jadx并配置环境
2038 0
|
网络安全 iOS开发 开发者
frida环境配置、以及如何脱壳iOS包并安装到非越狱设备-制作iOS任意App分身
frida环境配置、以及如何脱壳iOS包并安装到非越狱设备-制作iOS任意App分身
3024 1
|
安全 Android开发 数据安全/隐私保护
安卓逆向 -- SO文件逆向分析
安卓逆向 -- SO文件逆向分析
325 0
|
安全 JavaScript Shell
Frida-Dexdump 脱壳工具下载使用以及相关技术介绍
Spider、App逆向,本案例使用的App是:引力播.apk,涉及到查壳、脱壳、反编译;
5603 0
Frida-Dexdump 脱壳工具下载使用以及相关技术介绍
|
存储 算法 Linux
[GUET-CTF2019]encrypt 题解
[GUET-CTF2019]encrypt 题解
378 0