越狱调试
从内存中dump出IPA包
- 砸壳工具:Clutch
- 砸壳工具:dumpdecrypted
- 砸壳工具:frida-iOS-dump
- theos
- Reveal
- debugserver
- 手动砸壳
1. 砸壳工具:Clutch
- 将Clutch-2.0.4拷贝到iPhone
scp Clutch-2.0.4 root@192.168.2.141:/usr/bin
-
Clutch-2.0.4 -i
查看可以砸壳的APP

-
Clutch-2.0.4 -d 4
哔哩哔哩APP砸壳


- 砸壳OK,将IPA包拷贝到Mac,
scp
命令在Mac目录下执行
//拷贝失败的话,可以修改IPA名字先(iFunBox工具)
scp -P 12345 root@localhost:/private/var/mobile/Documents/Dumped/tv.danmaku.bilianime-iOS9.0-(Clutch-2.0.4).ipa ./

- 查看MachO签名

- 砸壳的MachO可以dump出头文件
class-dump -H bili-universal -o biliheaders
2. 砸壳工具:dumpdecrypted
AloneMonkey的改进版dumpdecrypted
make编译生成dumpdecrypted.dylib文件,copy到iPhone

- 查看APP renren的进程信息,iPhone终端执行
ps -A | grep renren

- 通过
DYLD_INSERT_LIBRARIES
环境变量插入动态库进行砸壳,生成PUClient.decrypted
文件,去掉后缀是MachO
文件
5s:~ root# DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib /var/mobile/Containers/Bundle/Application/C373317E-85C5-409F-88A5-3DECDE96BDA8/renren.app/PUClient

- 将砸壳写成sh脚本,+x权限
dump5s.sh:DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib $1
5s:~ root# sh dump5s.sh /var/mobile/Containers/Bundle/Application/09567720-35AC-4540-AB78-C906FE131C08/PUClient.app/PUClient
3. 砸壳工具:frida-iOS-dump
非完美越狱可以使用openSSH
、frida
砸壳
下载文件放置目录/Users/zz/ZZShell

- 安装 frida
sudo -H pip install frida-tools
sudo pip install six --upgrade --ignore-installed six
- 下载 frida-ios-dump
放置目录/Users/zz/ZZShell
sudo pip install -r /Users/zz/ZZShell/frida-ios-dump/requirements.txt --upgrade
遇到错误❌
File "/Users/zz/ZZShell/frida-iOS-dump/dump.py", line 19, in <module>
import paramiko
ImportError: No module named paramiko
安装paramiko
pip install paramiko
- 允许终端
输入中文
需要在iPhone家目录新建.inputrc
文件,添加下面4行代码
set convert-meta off
set output-meta on
set meta-flag on
set input-meta on
- 用dump.py砸壳生成IPA包
先执行
sh usbConnect.sh
,映射端口
dump.py 哔哩哔哩
- 可以将砸壳写成脚本
dumpIPA.sh
/Users/zz/ZZShell/frida-iOS-dump/dump.py $1

- 脚本砸壳
先执行sh usbConnect.sh
,映射端口
sh dumpIPA.sh 哔哩哔哩


4. theos
存放至/opt/theos

- 配置环境变量
.zshrc
文件
export THEOS=/opt/theos
export PATH=$THEOS/bin:$PATH
#Theos连接手机环境变量
export THEOS_DEVICE_IP=localhost
export THEOS_DEVICE_PORT=12345
- 使用
theos

案例. 分析界面,点击登录时拿到手机号、验证码
哔哩的登录页面

- cycript附加进程,找到
验证登录
按钮
5s:~ root# cycript -p 1073
cy# @import mjcript
{}
cy# MJFrontVc()
#"<BBPhoneNumLoginVC: 0x137353200>"
cy# #0x137353200.view.recursiveDescription() .toString ()

- 列出登录按钮的响应事件
cy# #0x1396e2730.allTargets()
[NSSet setWithArray:@[#"<BBPhoneNumLoginVC: 0x137353200>"]]]
cy# #0x1396e2730.allControlEvents()
64
cy# [#0x1396e2730 actionsForTarget: #0x137353200 forControlEvent: 64]
@["loginClick:"]
登录的方法是类BBPhoneNumLoginVC
的loginClick:
- 使用
Clutch-2.0.4
砸壳拿到MachO
文件,class-dump
出头文件

- 找到手机号、验证码的控件

- 编写插件
终端执行nic.pl
,生成文件目录


- 使用
logos
语法hookBBPhoneNumLoginVC
的loginClick:
方法

-
make
编译 ->make package
打包生成deb插件->make install
安装插件,手机kill
掉哔哩进程


-
make
编译出错,将Tweak.x后缀修改为xm


- iPhone打开
cydia
可以看到安装了bilidemo这个插件了

- 打开哔哩验证登录,在控制台可以看到输出了手机号、验证码

5. Reveal
- iPhone新建文件夹
/var/root/Library/RHRevealLoader
- 将
Reveal
的RevealServer.framework/RevealServer
重命名libReveal.dylib
,拷贝到iPhone的RHRevealLoader
scp -P 12345 -r RevealServer.framework root@localhost:/var/root/Library/RHRevealLoader/libReveal.dylib


6. debugserver
由于使用的5s是9.1系统,需要在xcode
包里找到对应的debugserver
版本。打开/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/9.1/DeveloperDiskImage.dmg
,将usr/bin
下的debugserver
拷贝到iPhone端/usr/bin
目录
- 修改脚本,添加
12346
端口映射

- 5s开启
debugserver
附加到进程,提供端口12346
debugserver *:12346 -a PUClient

- 启动
lldb
(lldb) lldb
(lldb) process connect connect://localhost:12346

- 断住程序,执行
lldb
s命令
(lldb) process interrupt
(lldb) pviews
(lldb) c

7. 手动砸壳进行class-dump
可以使用
scp
命令将iPhone的MachO
拷贝出来,otool
查看cryptid
的值
1
表示未脱壳的,用class-dump
导出头文件会失败
0
表示已经砸壳了由于iPhone运行的时候
MachO
是解密了的,这里可以从内存中读取解密的数据覆盖原来的MachO
对应位置的数据,再修改cryptid
为0
,完成手动砸壳,即可class-dump
-
scp
拷贝MachO
列出5s当前运行的进程
ps -e
7483 ?? 0:06.62 /var/mobile/Containers/Bundle/Application/DB89222B-666A-4D8E-BE7E-441F5BB181CD/PUClient.app/PUClient
拷贝到mac
scp -P 12345 root@localhost:/var/mobile/Containers/Bundle/Application/DB89222B-666A-4D8E-BE7E-441F5BB181CD/PUClient.app/PUClient ./
查看cryptid
otool -l PUClient| grep cr
//
zz ~/Desktop/demo/Theos/人人Payload otool -l PUClient| grep cr
locreloff 0
nlocrel 0
cryptoff 16384:加密的数据偏移量
cryptsize 27099136 :加密的数据大小
cryptid 1

- 从内存读解密的数据
5s开启debugserver
5s:~ root# debugserver *:12346 -a PUClient

Mac端进入lldb
,process
附加到PUClient
进程
zz ~ lldb
(lldb) process connect connect://localhost:12346

image list
读取MachO的内存地址0x000000010008c000

memory
读取解密数据,需要用process interrupt'
断住进程,否则报错:error: Process is running. Use 'process interrupt' to pause execution.
(lldb) process interrupt
(lldb) memory read --force --outfile decrypted.bin --binary --count 27099136 0x000000010008c000+16384

- 将读取的数据覆盖到
MachO
的对应位置
// seek:偏移
// bs:每次1个byte
// conv:文件没有替换的部分不要截断
// if/of:输入输出文件
dd seek=16384 bs=1 conv=notrunc if=decrypted.bin of=PUClient

- 用
MachOView
修改cryptid
为0

-
class-dump
导出头文件
class-dump -H PUClient -o PUClientHeaders