ios 逆向|frida hook 简单使用

ios 逆向 4 / 4

前言

这一篇来说一说 ios frida hook 的使用
样本还是熟悉的狗东版本 10.4.4
博主初学 ios 逆向,很多操作也没啥技巧,也不知道有啥方法工具,只能使用本方法了

ida 反编译

脱完壳后会生成一个 ipa 文件,可以直接拖进 ida,选择主程序打开即可
或者先解压,直接把主程序拖进 ida 也行

第一次打开需要很久,狗东的我是跑了一个晚上第二天才索引完成

等待索引完成就可以开始操作了,不然会卡到怀疑人生

ida 分析

打开字符串窗口搜索 sign 关键词,点进去按 x 查看交叉引用

最终是定位到这里,这里是对 encrypt 函数的执行结果进行 md5 加密,点进去分析一下

进来往下拉一点就能看到熟悉的 0 1 2 三个分支加密逻辑了,最后在进行 base64编码

下面来简单使用下 frida

frida hook

function hookFunction() {
    var JDSignCryptManager = eval('ObjC.classes.JDSignCryptManager["+ cryptWithPartion:cryptID:content:encrypt:"]');
    console.log('JDSignCryptManager: ', JDSignCryptManager);

    Interceptor.attach(JDSignCryptManager.implementation, {
        onEnter: function (args) {
            console.log('JDSignCryptManager args 2: ', args[2]);
            console.log('JDSignCryptManager args 3: ', args[3]);
            console.log('JDSignCryptManager args 4: ', ObjC.Object(args[4]));

        }, onLeave: function (ret) {
            console.log('JDSignCryptManager ret   : ', ObjC.Object(ret));
        }
    });

    var JDCPAHashManager = eval('ObjC.classes.JDCPAHashManager["+ md5:"]');
    console.log('JDCPAHashManager: ', JDCPAHashManager);

    Interceptor.attach(JDCPAHashManager.implementation, {
        onEnter: function (args) {
            console.log('JDCPAHashManager args 2: ', ObjC.Object(args[2]));

        }, onLeave: function (ret) {
            console.log('JDCPAHashManager res   : ', ObjC.Object(ret));
        }
    });
}

hookFunction();

hook 两个加密函数的输入输出

执行 frida -UF -l hook.js | tee hook.log 成功输出相关信息

上面这段代码是直接 hook 函数,当然还可以 inlinehook

function inlineHook() {
    var baseOffset = 0x100000000;
    var base = Module.findBaseAddress('JD4iPhone');
    console.log('base: ', base);

    var sub_105794200 = base.add(0x105794200 - baseOffset);
    console.log('sub_105794200: ', sub_105794200);

    Interceptor.attach(ptr(sub_105794200), {
        onEnter: function (args) {
            console.log(`sub_105794050 args 0: `, args[0]);
            console.log(`sub_105794050 args 1: `, args[1]);
            console.log(`sub_105794050 args 2: `, args[2]);
            console.log(`sub_105794050 args 3: \n`, hexdump(args[3], {length: args[4].toInt32(), header: false}));
            console.log(`sub_105794050 args 4: `, args[4]);

        }, onLeave: function (ret) {
            console.log(`sub_105794050 res   : ${ret}\n`);
        }
    });
}

inlineHook();

hook 012 的其中一个加密函数

同样执行 frida -UF -l hook.js | tee hook1.log 成功输出相关信息

暂无评论
本文作者:
本文链接: https://www.qinless.com/?p=1624
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 qinless 的博客!
100

发表评论

返回顶部