参考链接
注意点:
虚拟机位置要放在固态硬盘里,最少要512B,因为后面还需要在虚拟机里套虚拟机。
内存也开到8G:
磁盘大小给到512G:
按照开源代码的README逐行运行下载
sudo apt install git
git clone https://github.com/vusec/dangzero.git
docker version
命令检查docker是否已下载cmh@cmh-virtual-machine:~/dangzero/kml-image$ docker version
找不到命令 “docker”,但可以通过以下软件包安装它:
sudo apt install podman-docker # version 3.4.4+ds1-1ubuntu1.22.04.2, or
sudo apt install docker.io # version 24.0.5-0ubuntu1~22.04.1
sudo apt install docker.io
命令下载docker镜像cmh@cmh-virtual-machine:~/dangzero/kml-image$ sudo apt install docker.io
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
。。。。。。
cmh@cmh-virtual-machine:~/dangzero/kml-image$ sudo groupadd docker
groupadd:“docker”组已存在
cmh@cmh-virtual-machine:~/dangzero/kml-image$
sudo gpasswd -a cmh docker
正在将用户“cmh”加入到“docker”组中
cmh@cmh-virtual-machine:~/dangzero/kml-image$ newgrp docker
cmh@cmh-virtual-machine:~/dangzero/kml-image$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Step 7/10 : RUN wget -O kernel.gz download.vusec.net/dataset/kml-kernel.tar.gz
的文件较大,且在虚拟机中下载速度很慢,我失败了2次,白天下载速度是20K/s,凌晨下载的速度会是1M/s,暂时不知道为什么,所以建议晚上下载,先去睡觉,第二天早上就下载完毕!cmh@cmh-virtual-machine:~/dangzero/kml-image$ bash build_kml.sh
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
Install the buildx component to build images with BuildKit:
https://docs.docker.com/go/buildx/
Sending build context to Docker daemon 3.584kB
Step 1/10 : FROM ubuntu:14.04
---> 13b66b487594
Step 2/10 : ARG DEBIAN_FRONTEND=noninteractive
---> Using cache
---> f208b78419c9
Step 3/10 : RUN apt update
---> Using cache
---> e6e9104e8d36
Step 4/10 : RUN apt install -y build-essential libncurses-dev bison flex libelf-dev libssl-dev bc wget
---> Using cache
---> 24bd00a774fc
Step 5/10 : RUN mkdir -p /home/kml
---> Using cache
---> 5a00886e6ed7
Step 6/10 : WORKDIR /home/kml
---> Using cache
---> d4f1c2b90429
Step 7/10 : RUN wget -O kernel.gz download.vusec.net/dataset/kml-kernel.tar.gz
---> Running in 6320086b7bfa
--2023-11-08 15:57:57-- http://download.vusec.net/dataset/kml-kernel.tar.gz
Resolving download.vusec.net (download.vusec.net)... 130.37.53.80
Connecting to download.vusec.net (download.vusec.net)|130.37.53.80|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://download.vusec.net/dataset/kml-kernel.tar.gz [following]
--2023-11-08 15:57:59-- https://download.vusec.net/dataset/kml-kernel.tar.gz
Connecting to download.vusec.net (download.vusec.net)|130.37.53.80|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4315393639 (4.0G) [application/x-gzip]
Saving to: 'kernel.gz'
0K .......... .......... .......... .......... .......... 0% 6.87K 7d2h
50K .......... .......... .......... .......... .......... 0% 16.7K 5d0h
readme执行!需要注意ubuntu的版本,readme中的是20.04.5,但是官网找不到这个版本,所以就用了20.04.6的,经过实验也是可行的。
cmh@cmh-virtual-machine:~/dangzero$ wget https://releases.ubuntu.com/20.04/ubuntu-20.04.6-desktop-amd64.iso
--2023-11-11 10:04:49-- https://releases.ubuntu.com/20.04/ubuntu-20.04.6-desktop-amd64.iso
正在解析主机 releases.ubuntu.com (releases.ubuntu.com)... 91.189.91.123, 185.125.190.37, 91.189.91.124, ...
正在连接 releases.ubuntu.com (releases.ubuntu.com)|91.189.91.123|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 4351463424 (4.1G) [application/x-iso9660-image]
正在保存至: ‘ubuntu-20.04.6-desktop-amd64.iso’
ubuntu-20.04.6-desktop-amd64.iso 21%[==============> ] 900.35M 922KB/s 剩余 ubuntu-ubuntu-20.04.6-desktop-amd64.iso 51%[====================================> ] 2.09G 888KB/s ubuntu-20.04.6ubuntu-20.04.6-desktop-amd64.iso 62%[============================================> ] 2.53G 100ubuntu-20.04.6-desktoubuntu-20.04.6-desktop-amd64.iso 83%[============================================================> ] 3.4ubuntu-20.04.6-desktop-amd64.iso 100%[===================================================================>] 4.05G 894KB/s 用时 78m 44s
2023-11-11 11:23:34 (900 KB/s) - 已保存 ‘ubuntu-20.04.6-desktop-amd64.iso’ [4351463424/4351463424])
sudo apt install qemu-utils
下载qemu工具cmh@cmh-virtual-machine:~/dangzero$ qemu-img create -f qcow2 ubuntu.img 60G
Formatting 'ubuntu.img', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=64424509440 lazy_refcounts=off refcount_bits=16
sudo apt install qemu-system-x86
下载qemu工具-m
指定内存数,-smp
指定核心数,readme中分别是16G和8,但是我的虚拟机都没这么大,因此我分别配置成4G和4-cdrom
参数的镜像也需要注意使用自己下载的版本cmh@cmh-virtual-machine:~/dangzero$ qemu-system-x86_64 -cdrom ubuntu-20.04.6-desktop-amd64.iso -drive "file=ubuntu.img,format=qcow2" -enable-kvm -m 4G -smp 4 -cpu host
注:从此节往后若不做说明,均不是在QEMU的虚拟机上操作。
在上一步Install Ubuntu
之后,不要关闭该终端,则QEMU上会出现一个新的Ubuntu界面,在QEMU中我擅自做了以下1、2步(可能没有必要,但总之我做了这个工作)
Install Ubuntu
产生的终端,以关闭QEMUInstall Ubuntu
的第三步注意点一致,在此不赘述。cmh@cmh-virtual-machine:~/dangzero$ qemu-system-x86_64 -drive "file=ubuntu.img,format=qcow2" -enable-kvm -m 4G -smp 4 -cpu host -net nic -net user,hostfwd=tcp::1810-:22
readme执行!在【qemu的虚拟机】终端上先安装openssh,以支持文件传输
apt-get install openssh-server
readme执行!将文件传输到QEMU的虚拟机上:
cmh@cmh-virtual-machine:~/dangzero$ scp -P 1810 kml-image/linux-*.deb cmh@localhost:~/
cmh@localhost's password:
linux-firmware-image-4.0.0-kml_4.0.0-kml-6_am 100% 944KB 37.6MB/s 00:00
linux-headers-4.0.0-kml_4.0.0-kml-6_amd64.deb 100% 6758KB 36.8MB/s 00:00
linux-image-4.0.0-kml_4.0.0-kml-6_amd64.deb 100% 38MB 39.2MB/s 00:00
linux-image-4.0.0-kml-dbg_4.0.0-kml-6_amd64.d 100% 366MB 54.5MB/s 00:06
linux-libc-dev_4.0.0-kml-6_amd64.deb 100% 772KB 27.9MB/s 00:00
cmh@cmh-virtual-machine:~/dangzero$
cd ~/
sudo dpkg -i linux-*.deb
2. 关闭QEMU
readme执行!编辑/etc/default/grub,以在启动QEMU时不出现GUI界面,命令行比较舒服!
GRUB_DEFAULT="1>4" # depends on menu entries of grub
#GRUB_TIMEOUT_STYLE=hidden # comment out
GRUB_TIMEOUT=2 # if you want to see menu entries with GUI
readme执行!编辑/etc/default/grub,以修改启动Linux的引导项(我也不懂,跟着配就行了)!
GRUB_CMDLINE_LINUX_DEFAULT="vga=normal"
# Add console=ttyS0 if you want to run without GUI
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0 vga=normal"
# Add make-linux-fast-again for performance:
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0 vga=normal noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off tsx=on tsx_async_abort=off mitigations=off"
readme执行!
qemu-system-x86_64 -drive "file=ubuntu.img,format=qcow2" -enable-kvm -m 4G -smp 4 -cpu host,-avx,-f16c,-avx512f,-pdpe1gb -nographic -serial mon:stdio -net nic -net user,hostfwd=tcp::1810-:22
KML开始启动
启动成功后,就可以愉快地使用命令行执行了!
readme执行!
注:此节均是在QEMU中执行!没有问题,不记录。
测试成功的结果是,在QEMU虚拟机的/trusted目录下为ring0,而在其他目录下为ring 3。
readme执行!没问题!
注:此节除了scp -P 1810 patchglibc.diff u16@localhost:/trusted/glibc/glibc-2.31/
,其他命令均在QEMU中执行!
readme执行!没问题!
在QEMU虚拟机中先使用sudo update-alternatives --config gcc
命令选择gcc-9,执行命令后出现以下界面,选择2
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/gcc-9 90 auto mode
* 1 /usr/bin/gcc-5 50 manual mode
2 /usr/bin/gcc-9 90 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
回到danzero目录,readme执行!bash test.sh
然后我们就成功了!完结撒花~~~~