美文网首页
ptrace&sysctl 双重反反调试

ptrace&sysctl 双重反反调试

作者: yxc木易星辰 | 来源:发表于2019-05-16 15:40 被阅读0次

    1、创建一个动态库Inject,引入fishhook及sysctl、MyPtraceHeader头文件

    2、创建一个继承自NSObject的类 如 XCInject

    3、编码

    #import "XCAntDebug.h"

    #import "XCPtrance.h"

    #import <sys/sysctl.h>

    @implementation XCAntDebug

    static dispatch_source_t timer;

    //检测是否被调试

    BOOLisDebugger() {

        //控制码

        int name[4];//里面放字节码,查询信息

        name[0] =CTL_KERN;//内核查看

        name[1] =KERN_PROC;//查询进程

        name[2] = KERN_PROC_PID;//传递的参数是进程的ID(PID)

        name[3] =getpid();//PID的值

        struct kinfo_proc info; //接受进程查询结果的结构体

        size_tinfo_size =sizeof(info);//结构体的大小

        interror =sysctl(name,sizeof(name)/sizeof(*name), &info, &info_size,0,0);

        assert(error == 0);//0就是没有错误,其他就是错误码

        return((info.kp_proc.p_flag&P_TRACED) !=0);

    }

    voiddebugCheck(){

        timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));

        dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC, 0.0 * NSEC_PER_SEC);

        dispatch_source_set_event_handler(timer, ^{

            if(isDebugger()) {

                //        exit(0);

                NSLog(@"有debugServer");

            }else{

                NSLog(@"无debugServer");

            }

        });

        dispatch_resume(timer);

    }

    + (void)load {

        NSLog(@"XCAntDebug *************");

        debugCheck();

        ptrace(PT_DENY_ATTACH, 0, 0, 0);

    }

    @end

    相关文章

      网友评论

          本文标题:ptrace&sysctl 双重反反调试

          本文链接:https://www.haomeiwen.com/subject/figbvftx.html