如何高效找到越狱检测函数?

需求: 绕过一款app的越狱检测.

现状: 打开app以后,页面空白,然后跳到safari页面,上面写了越狱设备不支持使用,重回app界面又会打开此页面. 我的思路有俩个但是行不通:

  1. 找出带有jailbreak字眼的函数进行hook. 但是没有进入我hook的函数
  2. 打开页面用的应该是 open函数, 用fishhook 进行hook,然后打印调用栈. 但是我不知道入口函数是哪个, 现在注入的这个也是没有生效的.

代码如下

// See http://iphonedevwiki.net/index.php/Logos

#import <UIKit/UIKit.h>

#include "fishhook.h"
#import <dlfcn.h>

%hook AppsFlyerUtils

- (bool) isJailBreakon
{
    %log;
    NSLog(@"Hey, appsflyer jailbreak ");
    return NO;
}

%end

%hook SmartBeatUtil

- (bool) isJailbroken
{
    %log;
    NSLog(@"Hey, smartbeatutil jailbreak ");
    return NO;
}

%end

static int (*orig_close)(int);
static int (*orig_open)(const char *, int, ...);

int my_close(int fd) {
    NSLog(@"Calling real close(%d)\n", fd);
    return orig_close(fd);
}

int my_open(const char *path, int oflag, ...) {
    va_list ap = {0};
    mode_t mode = 0;
    
    if ((oflag & O_CREAT) != 0) {
        // mode only applies to O_CREAT
        va_start(ap, oflag);
        mode = va_arg(ap, int);
        va_end(ap);
        NSLog(@"Calling real open('%s', %d, %d)\n", path, oflag, mode);
        return orig_open(path, oflag, mode);
    } else {
        NSLog(@"Calling real open('%s', %d)\n", path, oflag);
        return orig_open(path, oflag, mode);
    }
}

%hook UIApplicationDelegate
- (_Bool)application:(UIApplication *)arg1 willFinishLaunchingWithOptions:(NSDictionary *)arg2 {
    NSLog(@" inHook now");
    // fishfook use
    struct rebinding binds[2];
    // orig_close是一个函数指针,(void *)&orig_close 是一个返回参数,所以用取地址,(void *)&orig_open也是类似的
    struct rebinding bind1 = {"close", (void *)my_close, (void **)&orig_close};
    binds[0] = bind1;
    binds[1] = (struct rebinding){"open", (void *)my_open, (void **)&orig_open};

    // rebind_symbols((struct rebinding[2]){{"close", my_close, (void *)&orig_close}, {"open", my_open, (void *)&orig_open}}, 2);
    // 转换为:
    rebind_symbols(binds, 2);

    return %orig;
}

%end


大佬们帮我看下我的思路有没有问题,以及入口函数怎么找(来自萌新的提问)


2019-12-30-19:30 更新
印象里的open应该是swift调用的 UIApplication.shared.open(link) …犯傻了.但是用 openURL也没生效

%hook UIApplication
+(void)load {
    NSLog(@" inHook now");
    return %orig;
}
-(BOOL)openURL:(NSURL *)url{
NSLog(@"openURL-url0:%@",url);
return %orig;
}
%end

既然越狱后会跳转到Safari,正常的思路不就应该找到跳转代码的上下文吗

是啊,所以跳转不是用的 open函数吗:joy:? (不是ios开发不清楚这个)

那就先去了解,ios是怎么跳转到safari的.

试下这个吧//绕过使用NSFileManager判断特定文件是否存在的越狱检测,此时直接返回NO势必会影响程序中对这个方法的正常使用,因此可以先打印一下path,然后判断如果path是用来判断是否越狱则返回NO,否则按照正常逻辑返回
%hook NSFileManager

  • (BOOL)fileExistsAtPath:(NSString *)path{
    if(TARGET_IPHONE_SIMULATOR)return NO;
    for (int i = 0;i < sizeof(JailbrokenPathArr) / sizeof(char *);i++) {
    NSString *jPath = [NSString stringWithUTF8String:JailbrokenPathArr[i]];
    if([path isEqualToString:jPath]){
    return NO;
    }
    }
    return %orig;
    }
    %end
    转自https://github.com/SmileZXLee/ZXHookDetection

openURL也试过了.
现在的问题是 没进入到注入函数里面,也就是 UIApplicationDelegate .application 没有执行到.
如何确定入口函数是哪个呢?

谢了. 试了下不行
现在主要也是想自己实践下逆向的过程. 所以还是自己想找出关键函数~

跳转Safari指的是跳转到手机的Safari浏览器吗?
还是说打开了WebView
或者Safari ViewController。

跳转到手机的Safari浏览器了

https://github.com/SmileZXLee/ZXHookDetection你看这里面,还有其他方法。

2 个赞

感谢分享。