所有的IOS应用上传到APP STORE上线前都会被自动加"壳",可以理解为蜗牛的外壳,主要作用就是用于保护"脆弱"的源代码,这个"壳"的真实身份是 FairPlayDRM(Digital Rights Management,数字版权保护),想详细了解的可以自行搜索查询一下。
一、检测是否加壳
1.使用 otool 检测
在终端运行mac自带工具otool查看文件,cryptid=1表示已加壳,cryptid=0表示未加壳。
$ otool -l WhatsApp | grep crypt
cryptoff 16384
cryptsize 57311232
cryptid 0
2. 使用 MachOView 检测
将文件拖到MachOView,点击 Load Commands显示子节点,选择 LC_ENCRYPTION_INFO_64, 在右边的窗口中查看Crypt ID的 Value是0还是1

二、脱壳
我使用的iPhone 6系统是12.5.6,尝试了Clutch、dumpdecryptedb、bfinject都无法正常脱壳,只有CrackerXI和Frida-ios-dump可以正常脱壳
1.使用 CrackerXI 脱壳
使用起来比较简单方便,Cydia添加源(Ant 蚂蚁源 | 最简洁的Cydia中文源)后搜索 CrackerXI App脱壳工具(当前版本1.1.16),安装完成之后打开 CrackerXI+,按照下面图片操作,先设置几个选项,再选择要脱壳的应用,在弹出的窗口中选择"YES,Full IPA",等待一会后就会弹出包含脱壳后IPA路径的提示框。


如果安装了CrackerXI后又从APPStore下载了应用,再打开会发现CrackerXI卡住了没有反应,出现这个问题就只需要在Cydia中重新安装一遍 CrackerXI就可以了。
2.使用 Frida-ios-dump 脱壳
使用起来相比 CrackerXI复杂一些,需要配置Mac和iPhone的环境
IOS配置
在Cydia中搜索Frida安装,当前版本16.0.10(Mac版本也要是这个版本)
安装完成后进入/usr/sbin目录启动Frida
$ ./frida-server &
Mac配置
$ pip3 install frida -i Simple Index
$ pip3 install frida-tools -i Simple Index
检查iphone和mac版本是否一致
frida --version
下载frida-ios-dump(GitHub - AloneMonkey/frida-ios-dump: pull decrypted ipa from jailbreak device)
使用git克隆或者下载代码压缩包到mac
$ git clone GitHub - AloneMonkey/frida-ios-dump: pull decrypted ipa from jailbreak device
解压后进入frida-ios-dump目录安装需求文件
$ python -m pip install --upgrade pip
$ pip3 install -r requirements.txt
安装中如果遇到错误处理方法:
ModuleNotFoundError: No module named 'paramiko'
$ sudo pip3 install paramiko
Failed to build bcrypt
$ sudo pip3 install bcrypt
If you are seeing a compilation error please try the following steps to successfully install bcrypt:
1) Upgrade to the latest pip and try again. This will fix errors for most users. See: This page has moved - pip documentation v24.2
2) Ensure you have a recent Rust toolchain installed. bcrypt requires rustc >= 1.56.0.
安装rust
rustup.rs - The Rust toolchain installer
Failed to build bcrypt
Could not build wheels for bcrypt which use PEP 517 and cannot be installed directly
$ python -m pip install --no-use-pep517 bcrypt
都安装好了之后,usb连接mac和iphone,开个终端将22端口映射到指定端口
$ iproxy 2222 22
修改frida-ios-dump目录下dump.py里面ssh账号\密码\端口
User = 'root'
Password = '123456'
Host = 'localhost'
Port = 2222
再开个终端连接本地2222端口(连接后输入iphone密码,默认是alpine)
$ ssh -p 2222 root@127.0.0.1
查看iphone上安装的应用
$ python3 ./dump.py -l
脱壳(先运行要脱壳的程序)
$ python3 ./dump.py MytalkingTom2
程序运行完成后会自动在frida-ios-dump目录生成脱壳后的IPA
如果执行上面的命令出现下面的错误是因为iphone没有启动frida
frida.NotSupportedError: unable to attach to the specified process
安装脱壳后的IPA会闪退解决方法
把FixMachO文件放到dump.py所在的frida-ios-dump目录,再修改dump.py调用FixMachO
def generate_ipa(path, display_name):
ipa_filename = display_name + '.ipa'
print('Generating "{}"'.format(ipa_filename))
try:
app_name = file_dict['app']
for key, value in file_dict.items():
from_dir = os.path.join(path, key)
to_dir = os.path.join(path, app_name, value)
if key != 'app':
#########################################################
# update here
exec_args = ('./FixMachO', from_dir)
try:
subprocess.check_call(exec_args)
except subprocess.CalledProcessError as err:
print(err)
#########################################################
shutil.move(from_dir, to_dir)
target_dir = './' + PAYLOAD_DIR
zip_args = ('zip', '-qr', os.path.join(os.getcwd(), ipa_filename), target_dir)
subprocess.check_call(zip_args, cwd=TEMP_DIR)
shutil.rmtree(PAYLOAD_PATH)
except Exception as e:
print(e)
finished.set()
3. 使用 LLDB 手动脱壳
待补充
参考:
https://www.shuzhiduo.com/A/lk5aXKKaJ1/
https://www.cnblogs.com/rab3it/p/15187642.html
[分享]windows上ios App一键砸壳教程(不需要ssh)-iOS安全-看雪-安全社区|安全招聘|kanxue.com