lldb动态调试(一)

准备环境:

Xcode 11.4.1

iOS 12.4.5 越狱设备

基本上参考了以下文章:

1. iOS设备的CPU架构

2. IOS逆向--debugserver 

3. iOS逆向学习笔记之--LLDB动态调试目标程序

4. iOS12 下配置debugserver + lldb调试环境的小技巧和问题处理

5. 一步一步用debugserver + lldb代替gdb进行动态调试 

//http://www.360doc.com/content/17/0510/11/12278201_652654333.shtml 补充5的图

配置过程

debugserver是根据iOS版本走的,最近升级到了12.4.5,以前的debugserver就作废了,要重新配置一下。

一、debugserver准备

主要工作是对debugserver进行精简+赋权。

1. 获取debugserver。将手机连接电脑,打开Xcode,选择Window->Devices and Simulators,然后就能在iOS系统的Developer/usr/bin目录中看到debugserver。

这步也可以直接在电脑上找xcode对应版本的debugserver,路径:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/

2. 执行scp命令将debugserver下载到电脑上。

$ iproxy 2222 22

$ scp -P 2222 [email protected]:/Developer/usr/bin/debugserver ./


3. 精简debugserver。先参考文章1,得知目标iOS设备cpu架构为arm64。执行:

$ lipo -thin arm64 ~/desktop/debugserver -output ~/debugserver

//这里两个debugserver似乎不能在同一个文件夹,因此我把新输出的文件放到~目录下了。


4. 给debugServer添加task_for_pid权限。

首先下载配置文件(http://iosre.com/ent.plist,自己写一个也可以),执行:

$ codesign -s - --entitlements ent.plist -f debugserver

//备用方案 ldid -S ent.plist debugserver

验证:

$ ldid -e  debugserver

显示ent.plist的内容说明成功。

5. 将处理好的debugserver拷贝回越狱iOS设备

$ iproxy 2222 22

$ scp -P 2222 debugserver [email protected]:/usr/bin/debugserver

scp -P 2222 debugserver [email protected]:/usr/bin/debugserver拷贝到"/usr/bin/"目录下具有全局使用权限,原有目录下/Developer/usr/bin/debugserver保留。


二、lldb连接debugserver

调试时,需要在移动端启用debugserver,在mac使用lldb连接debugserver。

1. 在iOS上启动debugserver

上一步已经将新的debugserver拷到/usr/bin/目录下,这里可以直接在iOS端的终端里使用了:

$ frida-ps -U       //获取进程名,ps -ef也行

# debugserver *:9999 -a Cydia       //9999为监听的端口号

2. macOS上启动lldb

情况1 

你的macOS和已经越狱的iOS在同一个网段,客户端(debugserver)和服务端(lldb)能够直接连通:

$ lldb

 (lldb) process connect connect://(iOS的IP):9999

报错处理

其中出现了lldb报错信息:error:failed to get reply to handshake packet

这个使用usb连接解决:

# debugserver 127.0.0.1:1234 -a XXXX       //这个名称我是用filza在container里翻出来的,取XXXX.app的文件名。

$ iproxy 1234 1234

(lldb) process connect connect://127.0.0.1:1234

成功的图参考《iOS应用逆向与安全》P130(还是要好好看书啊)。

使用lldb为下一步脱壳做准备。

另外可以参考文章4提到的一键脚本配置debugserver。

你可能感兴趣的:(lldb动态调试(一))