下载qemu
https://www.qemu.org/download/
本次下载的版本为8.2版本
下载Kali ARM系统镜像
本次下载的是Raspberry Pi 5系统,镜像文件kali-linux-2023.4-raspberry-pi5-arm64.img
下载QEMU_EFI.fd UEFI镜像
下载地址 https://releases.linaro.org/components/kernel/uefi-linaro/16.02/release/qemu64/
这个UEFI镜像不是本次仿真必须的文件
编译Linux内核,适配qemu环境
参考文章 https://gist.github.com/cGandom/23764ad5517c8ec1d7cd904b923ad863 (RaspberryPi4-qemu.md)进行编译内核
编译内核前,先安装以下软件:
sudo apt install flex bison libssl-dev
否则提示缺少相关依赖项。内核编译时间较长,耐心等待。
本次编译后内核镜像为.\Linux_kernel_v6.1.64_kvm_virt\Image
文件
编辑qemu启动脚本emulate_kali_raspberry_pi_5.bat,内容如下:
D:\qemu\qemu-system-aarch64.exe ^
-no-reboot ^
-M virt ^
-cpu cortex-a72 ^
-smp 4 -m 4G ^
-device VGA ^
-bios e:\QEMU_Kali_ARM64\QEMU_EFI.fd ^
-kernel E:\QEMU_Kali_ARM64\Linux_kernel_v6.1.64_kvm_virt\Image -append "root=/dev/vda2 rootfstype=ext4 rw panic=0 console=ttyAMA0" ^
-device virtio-blk,drive=hd0,bootindex=0 ^
-drive if=none,format=raw,file=E:\QEMU_Kali_ARM64\kali-linux-2023.4-raspberry-pi5-arm64.img,id=hd0,cache=writeback ^
-device virtio-net-pci,netdev=mynet ^
-netdev user,id=mynet,hostfwd=tcp::2222-:22
启动完成后,可直接通过ssh工具连接localhost:2222
登录
遇到的问题
启动系统时,停留在启动状态,提示rpi-resizerootfs.service、runonce.service等信息
- 使用qemu-img.exe重置镜像大小,命令:
qemu-img.exe resize xxx.img 30G
- 使用Arsenal以Write方式挂载xxx.img镜像(该镜像为raw格式),Vmware中添加挂载后的磁盘到Vmware的Kali系统中通过Kali自带的工具GParted,对ext4文件系统分区进行扩容
- 同时,在Vmware的kali系统中,删除ext4分区中
/etc/systemd/system/runonce.service
文件,命令
sudo rm -f ./etc/systemd/system/runonce.service
- 同时,在FAT32分区中,即Boot分区,创建ssh文件
touch ssh
,启用ssh服务 - 关闭Vmware中kali系统,然后Arsenal卸载xxx.img镜像,执行
emulate_kali_raspberry_pi_5.bat
脚本启动仿真系统