- download buildroot and unzip it to ~/
- For some reason, cttyhack is not enabled in busybox by default. we need to change config file to enable it. In the file
path/to/buildroot/package/busybox/busybox.configthere should be the line
# CONFIG_CTTYHACK is not set
change it to
CONFIG_CTTYHACK=y
Also, do this for SETUIDGID as well.
CONFIG_SETUIDGID=y
make menuconfig: do the following
1. Target Options -> Target Architecture -> x86_64
2. Kernel -> Linux Kernel [y] -> Kernel configuration -> Use the architecture default configuration
3. Filesystem images -> initial RAM filesystem linked into linux kernel [y]
-
makebuildroot. There are serveral dependencies which can fail the build, such as libssl and libelf. ThebzImageandrootfs.cpiofile will be located at/path/to/buildroot/output/images. -
compile the kernel module. For this, reference the
src/Makefilefile. Make sure you use the makefile in buildroot, not our own linux. -
Decompress the
rootfs.cpiofile. For this reference theimage/decompress.shfile. The opposite can be done withimage/compress.shscript. -
add the kernel module to initramfs and create an appropriate rcS file
#!/bin/sh
chown root:root flag
chmod 400 flag
insmod /lkm_example.ko
echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
setsid cttyhack setuidgid 1000 sh
umount /proc
umount /sys
poweroff -d 0 -f- Boot via qemu. Argument setting is complicated, so reference
image/boot.sh.