iOS 应用砸壳和导出类信息

2019-01-22  本文已影响0人  绿叶竹林

下载的非越狱应用都是经过加密的,加密后可以保证一定的安全性,但是对于逆向开发的人来说,加密应用无法进行静态分析,也无法导出类信息等。加密对应着解密,也就是我们常说的应用砸壳。
应用砸壳分为两种:静态砸壳动态砸壳

一、iOS 应用运行原理

加密应用 --> 系统内核对加密应用进行解密 --> dyld 加载解密后的 Mach-O 文件 --> 内存中某个区域存在解密后的可执行文件数据


应用运行原理.png

二、砸壳方式

这里只讨论动态砸壳,原理都是从内存中读取解密后的数据,动态砸壳有以下四种砸壳工具:

1、利用 Clutch 砸壳

wifi 
scp Clutch root@<your.device.ip>:/usr/bin/Clutch
usb
iproxy 2222 22
scp -P 2222 Clutch root@localhost:/usr/bin/Clutch

2、利用 dumpdecrypted 砸壳

scp -P 2222 dumpdecrypted.dylib root@localhost:~/dumpdecrypted.dylib
DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib 应用路径
动态注入.png 当前目录下以 .decrypted 为后缀的就是我们解密后的可执行文件

3、利用 frida-ios-dump 砸壳

sudo easy_install pip
sudo pip install frida-tools

三、砸壳脚本

个人比较倾向使用 frida-ios-dump 砸壳,所以这里介绍的砸壳脚本就以 frida-ios-dump 为基础。

/Users/sun/SunShell/frida-ios-dump/dump.py $1
// 前面路径为 dump.py 绝对路径
export SUNSHELL=~/SunShell  #自定义脚本文件夹
export PATH=$PATH:$SUNSHELL

四、导出类信息

砸壳完了以后我们就可以导出应用中的类信息了。

Usage: class-dump [options] <mach-o-file>

  where options are:
        -a             show instance variable offsets
        -A             show implementation addresses
        --arch <arch>  choose a specific architecture from a universal binary (ppc, ppc64, i386, x86_64)
        -C <regex>     only display classes matching regular expression
        -f <str>       find string in method name
        -H             generate header files in current directory, or directory specified with -o
        -I             sort classes, categories, and protocols by inheritance (overrides -s)
        -o <dir>       output directory used for -H
        -r             recursively expand frameworks and fixed VM shared libraries
        -s             sort classes and categories by name
        -S             sort methods by name
        -t             suppress header in output, for testing
        --list-arches  list the arches in the file, then exit
        --sdk-ios      specify iOS SDK version (will look in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS<version>.sdk
        --sdk-mac      specify Mac OS X version (will look in /Developer/SDKs/MacOSX<version>.sdk
        --sdk-root     specify the full SDK root path (or use --sdk-ios/--sdk-mac for a shortcut)

打开命令行进入 class-dump 所在的目录下,执行 ./class-dump --arch arm64 TargetAppMach-O -H -o ./Headers 命令导出头文件到 Headers 文件夹下。
同样我也写了一个全局的导出类信息的脚本:

# 第一个参数是可执行文件名称
# 第二个参数是输出文件夹,可选
# 第三个参数是架构类型,可选,默认是arm64
outputName="./$1_Headers"
cpu_arch="arm64"

if [ $2 ]; then
    outputName=$2
fi

if [ $3 ]; then
    cpu_arch=$3
fi

/Users/sun/SunTool/class-dump --arch ${cpu_arch} $1 -H -o ${outputName}

脚本使用方式 class-dump.sh NewsLiteclass-dump.sh NewsLite Headersclass-dump.sh NewsLite arm64

上一篇 下一篇

猜你喜欢

热点阅读