ios逆向入门-app登录协议逆向分析破解

某app登录协议分析破解

加群互相学习ios安全相关
file

设备

  • iphone 5s
  • Mac Os
  • app:神奇的字符串57qm5Y2V
    本文主要通过frida-trace、fridaHook、lldb动态调试完成破解相应的登录算法,从达到登录成功,并根据该步骤完成ios逆向分析,文中所有涉及的脚本都已经放在github上面。

    抓包分析

    之前文章已经进行了详细的抓包教程。
    iOS系统抓包入门实践之短链
    file
    file
    从上图中可以看到ydtoken、请求响应以及该接口涉及到的mobile为要破解的内容。

    请求参数分析

    这里涉及到的frida相关环境安装配置可以参考
    ios逆向-frida&环境&破解appSign算法

    ydtoken

    通过砸壳以及ida分析
    file
    加密是通过yd_md5:方法进行加密,继续追踪。
    file
    调用CC_MD5进行加密。
    通过trace命令:frida-trace -UF -i "CC_MD5",可以很快速的破解该app的ydtoken算法。frida默认trace是不能打印入参的,更改之后如下:

{
  onEnter(log, args, state) {
    log('CC_MD5()--arg[0]='+args[0].readUtf8String());
  },
  onLeave(log, retval, state) {
    log('CC_MD5()--return--=');
    var md5_digest = hexdump(retval,{length:16});
    var hexified = " ";
    var raw_array = md5_digest.split("\n");
    for (var a=0; a<raw_array.length; a++)
    {
      var line_array = raw_array[a].split(" ");
      for (var b=1; b<line_array.length-1; b++) 
      {
        if (line_array[b].length === 2)
        {
          hexified += line_array[b];
          hexified = hexified.trim();
        }
      }
    }
    log(hexified+"\n");
  }
}

参数显示出来了
file

Mobile

在ida分析之后,发现该算法是属于des加密。
file
使用默认的CCCrypt继续trace:frida-trace -FU -i CCCrypt
file
更改之后的trace脚本代码较长,放在了github。
https://github.com/zhaoboy9692/dailyanalysis

响应分析

这里主要是针对响应内容无法正常看到信息,目前通过Mac的日志控制台定位发现,这里其实定位了好久,直到最后才通过日志找到算法位置。
file
接口返回信息失败这块的日志定位到该响应解密的位置parseStringByRule:
file
这里其实是对后台的数据做了一个映射。
sohoFilteredInfo是把映射key和value做成字典。
file
这里的数字对应ASCII的值,那要解密响应内容,只需要获取该key、value的映射关系即可。这里使用fridaHook、lldb进行获取该映射关系。

fridaHook

确定到算法位置之后,使用frida进行hook。

var className = "ADAuthenticationRule";
var methodName = "- parseStringByRule:";
var hooking = ObjC.classes[className][methodName];
Interceptor.attach(hooking.implementation, {
    onEnter: function (args) {
        var obj  = ObjC.Object(args[0]);
        console.log('sohoFilteredInfo',obj.sohoFilteredInfo()) #调用映射方法。
    },
    onLeave: function (returnValues) {

    }
});

file

lldb

debugserver处理

  • 将未经处理的debugserver从iOS拷贝到macOS中的,scp root@iOSIP:/Developer/usr/bin/debugserver ~/debugserver
  • 瘦身 lipo -thin arm64 ~/debugserver -output ~/debugserver iphone5s是arm64
  • 给debugserver添加task_for_pid权限/opt/theos/bin/ldid -Sent.xml debugserver 或者 MARKDOWN_HASH67f1cb59a8759f2cbbdcbfe53e2f45d2MARKDOWNHASH
    [entitlements.plist](https://zhaoxincheng.com/wp-content/uploads/2021/11/entitlements.plist.zip "entitlements.plist")
  • 将经过处理的debugserver拷回iOS scp ~/debugserver root@iOSIP:/usr/bin/debugserver
  • 在iOS上用debugserver来attach进程 :
    ssh连接手机之后,使用debugserver localhost:1234 -a pid
    file

    lldb调试

    在mac终端执行lldb。
    使用iproxy 端口转发 iproxy 1234 1234
    在lldb中执行
    process connect connect://localhost:1234 链接手机debugserver
    file
    动态调试需要知道基地址+偏移。
    查看macho基地址:
    image list -f -o,红色框就是基地址
    file
    计算需要下断点的地址:
    file
    下断地址=0x0000000000638000+0x0000000100104EF0=0x10073CEF0
    此处地址是映射方法返回的值,也就是解密需要的映射表。
    b 0x10073CEF0 下断点
    运行app
    file
    停到了断点位置,读取x0的值,映射函数返回值给了x0寄存器。
    po $x0
    file
    c app继续运行。
    更多命令可以 help 查看。

    效果

    file

    小结

    该app用来练手最好不过,没有特别复杂的算法,又需要一定的耐心跟踪。在后边的映射中,要是更懂oc的语法,可能会更加上手。
    文中涉及脚本github地址(喜欢可以点小星星):https://github.com/zhaoboy9692/dailyanalysis

    参考文章

    https://iosre.com/t/debugserver-lldb-gdb/65
    https://www.jianshu.com/p/6e6bb0d0ee78

本文系作者 @ 原创发布在 我的编程学习之路。未经许可,禁止转载。

喜欢()
热门搜索
30 文章
0 评论
541 喜欢
Top