iOS逆向工程示例

作者: NI_Leo | 来源:发表于2017-02-07 15:35 被阅读0次

    1、准备工作:手机越狱

    • 使用PP助手在windows环境下进行越狱

    • 给越狱的手机安装openSSH,在cydia商店首页里有一个<OpenSSH教程>,点击里面的下载链接进行下载和安装

    • 测试是否可以用Mac控制iPhone:

      mac同iPhone接到同一个wifi上,查看iPhone的IP地址,如 10.0.1.200
      打开terminal输入ssh root@10.0.1.200。此时会要求输入密码,使用默认密码’alpine’。
      成功连接手机后会进入手机的根目录 root#

    2、对微信ipa包进行砸壳

    • 下载砸壳工具 dumpdecrypted, 下载地址: https://github.com/stefanesser/dumpdecrypted/archive/master.zip

    • 确认iOS设备版本:本机为 iOS8.4

    • 打开dumpdecrypted文件目录,查看Makefile文件

    • 确保Makefile配置与真机环境一致

      在Mac中打开terminal,输入以下命令查看SDK版本。
      <pre><code>xcrun --sdk iphoneos --show-sdk-path</code></pre>

      如果与Makefile文件里的不一致,(如:当前Mac的xcode iOS SDK版本为IPhoneOS10.sdk)需要去苹果官网(https://developer.apple.com/download/more/)下载老版本xcode ,提取出SDK,放入当前版本SDK的相同目录下,位置为:
      /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk

      修改Makefile文件里的SDK路径为以下路径:
      SDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk

    • 运行dumpdecrypted脚本

      在terminal上,cd进入dumpdecrypted脚本文件所在的目录,然后输入’make’并回车运行脚本。会在同级目录下生成dumpdecrypted.dylib文件

    • 查找wechat目录

      • 在cydia中搜索并安装cycript脚本工具及adv-cmds命令行工具

      • 在Mac的terminal中连接上手机然后获取当前使用的线程
        <pre>
        <code>ssh root@10.0.1.200</code>
        <code>ps -e</code>
        </pre>
        从返回结果中可找到当前打开的微信的线程标识号及路径
        <pre> 1478 ?? 0:05.56 /var/mobile/Containers/Bundle/Application/7C271A0B-C7A6-4E87-AFBF-FF88887F7E7C/WeChat.app/WeChat</pre>
        并记录下线程标识号: 1478 然后继续输入
        <pre>cycript -p 1478</pre>
        进入Objective-C代码输入状态: cy# 再次输入
        <pre> cy# [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0]</pre>
        得到微信的数据存放地址如下:
        <pre>file:///var/mobile/Containers/Data/Application/EA7A1E9B-DD1D-4DE0-92EA-50A66E63727A/Documents/</pre>
        将dumpdecripted.dylib文件拷贝到当前目录下
        <pre>
        scp dumpdecrypted.dylib root@10.0.1.200:/var/mobile/Containers/Data/Application/EA7A1E9B-DD1D-4DE0-92EA-50A66E63727A/Documents
        </pre>

    • 开始砸壳

      进入/var/mobile/Containers/Data/Application/EA7A1E9B-DD1D-4DE0-92EA-50A66E63727A/Documents
      路径下,运行如下命令
      <pre>
      DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib
      /var/mobile/Containers/Bundle/Application/7C271A0B-C7A6-4E87-AFBF-FF88887F7E7C/WeChat.app/WeChat
      </pre>
      看到如下信息表示已经完成砸壳
      <pre>
      <code>[+] detected 32bit ARM binary in memory.</code>
      <code>[+] offset to cryptid found: @0x59a4c(from 0x59000) = a4c</code>
      <code>[+] Found encrypted data at address 00004000 of length 49446912 bytes - type 1.</code>
      <code>[+] Opening /private/var/mobile/Containers/Bundle/Application/7C271A0B-C7A6-4E87-AFBF-FF88887F7E7C/WeChat.app/WeChat for reading.</code>
      <code>[+] Reading header</code>
      <code>[+] Detecting header type</code>
      <code>[+] Executable is a FAT image - searching for right architecture</code>
      <code>[+] Correct arch is at offset 16384 in the file</code>
      <code>[+] Opening WeChat.decrypted for writing.</code>
      <code>[+] Copying the not encrypted start of the file</code>
      <code>[+] Dumping the decrypted data into the file</code>
      <code>[+] Copying the not encrypted remainder of the file</code>
      <code>[+] Setting the LC_ENCRYPTION_INFO->cryptid to 0 at offset 4a4c</code>
      <code>[+] Closing original file</code>
      <code>[+] Closing dump file</code>
      </pre>
      在同级目录下就已经生成了一个wechat.decrypted文件,这就是砸壳之后的文件。

    • 导出头文件

      将刚刚生成的decrypted文件导出到Mac上:
      <pre>
      scp root@10.0.1.200:/var/mobile/Containers/Data/Application/EA7A1E9B-DD1D-4DE0-92EA-50A66E63727A/Documents/WeChat.decrypted /Users/Leo/Desktop/WeChat.decrypted
      </pre>
      使用之前的class-dump工具运行以下命令可反编译出头文件
      <pre>
      class-dump --arch armv7 -H WeChat.decrypted -o /Users/Leo/Desktop/wechatRes/WeChatHeaders/
      </pre>

    • 查看中间码
      使用hopper disassembler工具打开 decrypted文件可以查看中间码,具体使用方法请自行查阅

    相关文章

      网友评论

        本文标题:iOS逆向工程示例

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