使用qemu启动iphone内核

准备工作

1 ipsw 这里选用的是 2 3 4 从该处下载http://www.newosxbook.com/tools/jtool.tar 将jtool的二进制文件 放置于/usr/lcoal/bin目录下 并 chmod +x 赋予执行权限

ipsw是iOS的固件其中的文件多以img3/img4格式加密的

需要对应的FW key做解密 目前只能处理img3格式 新版硬件只能通过OTA包中提取文件

0x01编译好用于启动xun的qemu

git clone https://github.com/alephsecurity/xnu-qemu-arm64.git
cd xnu-qemu-arm64
./configure --target-list=aarch64-softmmu --disable-capstone
make -j16

如果编译qemu时出现缺少pkg-config**

➜ xnu-qemu-arm64 git:(master) ✗ ./configure --target-list=aarch64-softmmu --disable-capstone

直接 brew install pkg-config即可

0x02 开始修改ipsw文件

从这里https://github.com/Co2333/iQemu-iPsw-iPreparer 下载或者编译iemu_prep_out

sudo /Users/tesi1a/Desktop/macos/iemu_prep_out  /Users/tesi1a/Desktop/macos/iPhone_5.5_12.1_16B92_Restore.ipsw   /Users/tesi1a/Desktop/macos/iemu_prep_test3

cd 到 iemu_prep_test3这个目录使用编译好的qemu(在~/Desktop/macos/xnu-qemu-arm64/aarch64-softmmu/qemu-system-aarch64目录) 开始启动xun内核的iphone

/Users/test/Desktop/macos/xnu-qemu-arm64/aarch64-softmmu/qemu-system-aarch64   -M iPhone6splus-n66-s8000,kernel-filename=kernel.fout,dtb-filename=device_tree.fout,secmon-filename=secure_monitor.fout,ramdisk-filename=boot_image.fout,tc-filename=static_tc.fout,kern-cmd-args="debug=0x8 kextlog=0xfff cpus=1 rd=md0 serial=2" -cpu max -m 6G -serial mon:stdio

最后成功起来了一个bash:

/iosbinpack64/usr/bin/uname -a

我们需要在里面执行动态库文件,比如把某个应用包装成dylb。然后直接调用里面的函数。

0x03 遇到的问题

问题一:新版mac上的clang编译缺少头文件 fatal error: ‘stdio.h’ file not found #import<stdio.h> ^ 在编译的过程中会提示 <stdio.h> not found。我是macOS 10.14.5 (18F132)

于是就去网上搜,得知 Mac 下 stdio.h 头文件应该位于 /usr/include。搞笑的是,include 文件夹消失了!去网上搜,发现很多人都遇到这个问题,估计是 Xcode 升级带来的 bug

Google了一波发现大家都会有这个问题:

同时也给了修补方案

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

安装完成后我们发现/usr/include里的头文件已经出现了:

疑惑: 这个xcode目录下也有会头文件,没有关闭rootless 我们无法拷贝文件和链接系统目录

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include /usr/include

而刚才那个pkg文件做到了移动文件到/usr目录,好奇是怎么做到的?

第二个问题:编译配置qemu时出现缺少pkg-config

➜  xnu-qemu-arm64 git:(master) ✗ ./configure --target-list=aarch64-softmmu --disable-capstone

直接 brew install pkg-config即可

第三个问题,在xun启动的最后一步出现了这个:

回头看ipsw的解包过程:发现缺少jtool 从该处下载http://www.newosxbook.com/tools/jtool.tar 将jtool 放置于/usr/lcoal/bin目录下 并 chmod +x 赋予执行权限即可

参考:

经验分享 程序员 微信小程序 职场和发展