iOS逆向(四)-APP砸壳和class-dump工具的使用

https://www.jianshu.com/p/7ddba865ea21

逆向工具集的安装和使用

iOS 逆向工程的工具分类

  • 检查工具
    如:Reveal(界面分析工具)、tcpdump(抓包工具)等

  • 反编译工具(反汇编工具-分析二进制文件并得到一些信息)
    如:IDA、Hopper Disassembler、class-dumpyololib

  • 调试工具
    如:lldb、Cycript等

  • 开发工具
    如:Xcode、theos等

class-dump介绍

class-dump可以将Mach-O文件中的Objective-C运行时的声明信息导出,即编写OC代码时的.h文件。class-dump只能导出未加密的app头文件,class-dump是对"otool -ov"信息的翻译.以一种我们熟悉的易读的方式呈现。

  • otool工具简介
    otool(object file displaying tool):目标文件的展示工具。可以用来发现应用中使用到了那些系统库,调用了那些系统方法。使用了库中那些对象及属性,它是Xcode自带的常用工具。
    终端输入otool会得到如下使用命令:
```
-f print the fat headers
-a print the archive header
-h print the mach header
-l print the load commands
-L print shared libraries used
-D print shared library id name
-t print the text section (disassemble with -v)
-p <routine name>  start dissassemble from routine name
-s <segname> <sectname> print contents of section
-d print the data section
-o print the Objective-C segment
-r print the relocation entries
-S print the table of contents of a library
-T print the table of contents of a dynamic shared library
-M print the module table of a dynamic shared library
-R print the reference table of a dynamic shared library
-I print the indirect symbol table
-H print the two-level hints table
-G print the data in code table
-v print verbosely (symbolically) when possible
-V print disassembled operands symbolically
-c print argument strings of a core file
-X print no leading addresses or headers
-m don't use archive(member) syntax
-B force Thumb disassembly (ARM objects only)
-q use llvm's disassembler (the default)
-Q use otool(1)'s disassembler
-mcpu=arg use `arg' as the cpu for disassembly
-j print opcode bytes
-P print the info plist section as strings
-C print linker optimization hints
--version print the version of /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool
 ```
  • otool简单使用
    == 进入APP包文件目录/../xxoo.app
    $cd ../xx00.app

    == 依赖库的查询
    $otool -L 依赖库名称

    == 是否加壳
    $otool -l WeChat.app/WeChat | grep -B 2 crypt

    1代表加密了,0代表被解密了:
    
        cmd LC_ENCRYPTION_INFO
    cmdsize 20
    

cryptoff 16384
cryptsize 47841280
cryptid 1

    cmd LC_ENCRYPTION_INFO_64
cmdsize 24

cryptoff 16384
cryptsize 51200000
cryptid 1

classdump的使用

1、点击 class-dump下载dmg安装包
2、将class-dump执行文件拖入到/usr/local/bin目录下
3、终端输入class-dump查看版本号检查是否安装成功
4、class-dump的使用命令:
$class-dump -s -S -H /../xx00.app -o /.../heads
5、框架一样可以导出:
$class-dump -s -S -H /System/Library/Frameworks/AppKit.framework -o /.../heads
解释:
/../xx00.app 是app的路径
/../heads 是存放dump出来头文件的文件夹路径

dumpdecrypted砸壳工具

打开两个终端窗口:
打开两个终端窗口:
打开两个终端窗口:
== 一个ssh登录iPhone后,对iPhone进行操作
== 一个操作本地电脑

  • 下载dumpdecrypted最新源码
    终端命令:
    git clone https://github.com/stefanesser/dumpdecrypted.git

  • make命令编译生成dumpdecrypted.dylib动态库文件(砸壳的锤子)

    • cd 到下载的工程dumpdecrypted目录下
    • 输入终端命令即可:
      $make
  • 使用ssh登录越狱的iPhone设备拿到Data和Bundle两个文件路径

==bundle文件路径 (我们需要砸壳的app路径)

方式一:知道app名称情况
$ps -e | grep WeChat 
 1787 ??         0:05.98 /var/containers/Bundle/Application/D28A1C43-2F50-435D-AD0E-DDB14992D63B/WeChat.app/WeChat
 1794 ttys001    0:00.01 grep WeChat

方式二:不知道APP名称,只打开砸壳app
$ps -e 找到含bundle的路径,只会存在一个

/var/containers/Bundle/Application/D28A1C43-2F50-435D-AD0E-DDB14992D63B/WeChat.app/WeChat

==Data文件路径 (放锤子的地方)

$ cycript -p WeChat
cy# directory = NSHomeDirectory()
@"/var/mobile/Containers/Data/Application/E9232D81-80E3-4684-BB0E-FC3643703947"

/var/mobile/Containers/Data/Application/E9232D81-80E3-4684-BB0E-FC3643703947

退出:control+D

  • 拷贝dumpdecrypted.dylib到iPhone
    • 打开本地电脑窗口
    • 复制刚刚拿到的Data文件路径,我们要把电脑上生成的dumpdecrypted.dylib放在它的Documents文件目录下
    • 使用ssh传输文件
    $scp /.../dumpdecrypted/dumpdecrypted.dylib   root@192.168.1.2:/var/mobile/Containers/Data/Application/E9232D81-80E3-4684-BB0E-FC3643703947/Documents
    

为什么要把dumpdecrypted.dylib拷贝到Documents目录下操作?
StoreApp对沙盒以外的绝大多数目录是没有写权限。dumpdecrypted.dylib要写一个decrypted文件,但它是运行在StoreApp中的,与StoreApp的权限相同,那么它的写操作就必须发生在StoreApp拥有写权限的路径下才能成功。StoreApp一定是能写入其Documents目录的,因此我们在Documents目录下使用dumpdecrypted.dylib时,保证它能在当前目录下写一个decrypted文件,这就是把dumpdecrypted.dylib拷贝到Documents目录下操作的原因。

  • 砸壳

    • 打开ssh连接iPhone的终端窗口
    • cd到Data文件路径的Document目录下也就是我们放锤子的地方
    • 开砸
    DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib /var/containers/Bundle/Application/D28A1C43-2F50-435D-AD0E-DDB14992D63B/WeChat.app/WeChat
    

解释:
注入我们的动态库文件
DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib
APP包路径
/var/containers/Bundle/Application/D28A1C43-2F50-435D-AD0E-DDB14992D63B/WeChat.app/WeChat

  • 砸壳错误:

    dyld: could not load inserted library 'dumpdecrypted.dylib' because no suitable image found.  Did find:
      dumpdecrypted.dylib: required code signature missing for 'dumpdecrypted.dylib'
    Abort trap: 6
    
  • 重签名再次上传文件即可解决:

    列出可签名证书

    security find-identity -v -p codesigning

    为dumpecrypted.dylib签名

    codesign --force --verify --verbose --sign “iPhone Developer: xxx xxxx (xxxxxxxxxx)” dumpdecrypted.dylib

  • 微信砸壳后结果

    mach-o decryption dumper
    
  • DISCLAIMER: This tool is only meant for security research purposes, not for application crackers.

    [+] detected 64bit ARM binary in memory.
    [-] This mach-o file is not encrypted. Nothing was decrypted.

    尴尬了,没有破译文件,没有生成decrypted文件,可能微信做了处理,我们换成简书app再次操作一次,成功拿到破译文件

  • 简书砸壳成功


  • 拷贝生成的decryption文件到电脑,再使用class-dump导出头文件

    • 回到电脑终端窗口
    • 传输获取的破译文件Hugo.decrypted,去掉decrypted就是我们app的二进制文件
    拷贝命令:
    scp -r root@192.168.1.2:/var/mobile/Containers/Data/Application/E5A9CC73-1EF7-42F7-95BB-D154DA83E1BE/Documents/Hugo.decrypted /Users/Yohann/Desktop/Hugo
    
    • 使用class-dump导出头文件
    class-dump -S -s -H /Users/Yohann/Desktop/Hugo/Hugo.decrypted -o /Users/Yohann/Desktop/Header 
    
  • dump如果没有出现东西,可以确定下当前的处理器,加相应参数
    : class-dump arch armv7 -S -s -H WeChat.decrypted -o Headers

    其他型号使用相对应的 4(armv7),4s(armv7),5(armv7),5s(arm64),6(arm64),6s(arm64)

    • 又尴尬了导出头文件报错,再试一次换为自己公司APP成功
    Error: Cannot find offset for address 0x98000000010080d2 in stringAtAddress:
    

    网上搜索错误信息,得出结论:
    1、class-dump是利用Object-C语言的runtime特性,提取头文件,使用swift或其它语言混编无法提取头信息
    2、使用dumpdecrypted.dylib得不到decrypted破解文件,
    (1)可能是app未加壳,
    (2)无法破解,例如同样的操作对微信无效。
    (3)探索中。。。有见解望留言
    本次砸壳iOS10.0.2

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值