使用qemu启动iphone内核

准备工作

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

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

需要对应的FW key做解密
https://www.theiphonewiki.com/wiki/Firmware_Keys
目前只能处理img3格式
新版硬件只能通过OTA包中提取文件
https://ipsw.me/ota
http://newosxbook.com/src.jl?tree=listings&file=ota.c

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。然后直接调用里面的函数。
http://blog.imjun.net/posts/convert-iOS-app-to-dynamic-library/

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了一波发现大家都会有这个问题:https://forums.developer.apple.com/thread/104296

同时也给了修补方案

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 赋予执行权限即可
在这里插入图片描述

参考:
http://iosre.com/t/qemu-xnu/14967
https://alephsecurity.com/2019/06/17/xnu-qemu-arm64-1/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值