吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4949|回复: 47
收起左侧

[Android 原创] 初探frida反调试

  [复制链接]
胡凯莉 发表于 2023-3-23 00:06
本帖最后由 胡凯莉 于 2023-3-23 08:32 编辑

[md]## 常见frida检测

  • 1、检测文件名(改名)、端口名27042(改端口)、双进程保护(spawn启动)

  • 2、检测D-Bus

    • D-Bus是一种进程间通信(IPC)和远程过程调用(RPC)机制,最初是为Linux开发的,目的是用一个统一的协议替代现有的和竞争的IPC解决方案。

    • 
      遍历连接手机所有端口发送D-bus消息,如果返回"REJECT"这个特征则认为存在frida-server。

    内存中存在frida rpc字符串,认为有frida-server
    /*

    • Mini-portscan to detect frida-server on any local port.
      /
      for(i = 0 ; i <= 65535 ; i++) {
      sock = socket(AF_INET , SOCK_STREAM , 0);
      sa.sin_port = htons(i);
      if (connect(sock , (struct sockaddr
      )&sa , sizeof sa) != -1) {
      __android_log_print(ANDROID_LOG_VERBOSE, APPNAME,  "FRIDA DETECTION [1]: Open Port: %d", i);
      memset(res, 0 , 7);
      // send a D-Bus AUTH message. Expected answer is “REJECT"
      send(sock, "\x00", 1, NULL);
      send(sock, "AUTH\r\n", 6, NULL);
      usleep(100);
      if (ret = recv(sock, res, 6, MSG_DONTWAIT) != -1) {
      if (strcmp(res, "REJECT") == 0) {
      / Frida server detected. Do something… /
      }
      }
      }
      close(sock);
      }
    • 检测D-Bus可以通过hook系统库函数,比如strstr、strcmp等等
  • 3、检测/proc/pid/maps映射文件

  • 4、检测/proc/pid/tast/tid/stat/或者/proc/pid/task/tip/status

    • 因为so载入的时候,底层最后open去打开的。 所以再用frida去hook应用中的open函数,看看读取了哪些so或者文件,可以看到最后断在了/proc/self/maps。  对于3、4有效
  • 5、直接调用openat的syscall的检测在text节表中搜索frida-gadget.so / frida-agent.so字符串,避免了hook libc来anti-anti的方法

    • 注入方式改为
    • 1、frida-inject
    • 2、ptrace注入 配置文件的形式注入
    • 3、编译rom注入
  • 6、从inlinehook角度检测frida

https://zhuanlan.zhihu.com/p/557713016

hook_open函数可以查看是哪里检测了so文件

function hook_open(){
    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;
        }
    })
}
setImmediate(hook_open)

替换一个正常的

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)

检测点是maps、status

  • 1、替换
  • 2、映射
    • image-20230304202127820
  • 使用方法把解压后的maps和status文件拷贝到sdcard目录下,并chmod给777权限 然后frida使用bypassFulao2.js脚本
  • 查看当前运行软件的包名和类名:
    • adb shell dumpsys window |grep mCurrentFocus
  • 去脱壳的dex文件夹中搜索
    • grep -ril "com.ilulutv.fulao2.main.MainActivity"
  • jadx查看
    • jadx-gui classes08.dex

image-20230304205839578

新版jadx修改checknum

image-20230304210155082

[/md]

免费评分

参与人数 12吾爱币 +10 热心值 +11 收起 理由
junjia215 + 1 + 1 谢谢@Thanks!
pwjcw + 1 热心回复!
wanjingbo + 1 我很赞同!
zhujue + 1 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
allspark + 1 + 1 用心讨论,共获提升!
moss0723 + 1 热心回复!
debug_cat + 1 + 1 谢谢@Thanks!
vaycore + 1 + 1 谢谢@Thanks!
yp17792351859 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
wangkaixuan0122 + 1 + 1 谢谢@Thanks!
为之奈何? + 1 + 1 我很赞同!
walykyy + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Glhdad 发表于 2024-4-18 10:41
[JavaScript] 纯文本查看 复制代码
function hook_open(){
    var pth = Module.findExportByName(null,"open");
    Interceptor.attach(ptr(pth),{
        onEnter:function(args){
            this.filename = args[0];
           
            if (this.filename.readCString().indexOf(".so") != -1){
                console.log("",this.filename.readCString())
            }
        },onLeave:function(retval){
            return retval;
        }
    })
}
setImmediate(hook_open)


这个这么写才有结果吧?
klop 发表于 2024-3-20 17:05
从inlinehook的思路比较通用,因为不管frida如何改变,它总要修改内存,这个方案相对通用一点
walykyy 发表于 2023-3-23 05:12
Simpleton 发表于 2023-3-23 06:54
路过看看
cbvtku 发表于 2023-3-23 07:22
非常感谢楼主的分享
q393810655 发表于 2023-3-23 07:43
学习学习。感谢楼主分享!
tb1215225 发表于 2023-3-23 07:53
好 但是看不懂
hanghaidongchen 发表于 2023-3-23 08:30
感谢分享
toimiao 发表于 2023-3-23 08:35
感谢的分享
scbzwv 发表于 2023-3-23 08:59
感谢楼主分享
puk88888 发表于 2023-3-23 09:01
感谢分享,学习一下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-3 01:48

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表