CTF Linux Kernel PWN Setup

Introduction

Write a post to log the necessary steps for Linux Kernel pwn challenges in CTF.

Extracting Files

Usually a compressed file is given in challenges containing the following files:
bzImage: the bootable image of the linux kernel
rootfs.cpio: the file system used in the challenge
shart.sh: the shell script to run qemu on the image

Use the extract-vm script to extract vmlinux file. If the script does not exist, use sudo apt-get install linux-headers-$(uname -r) to down load the files.
20200314001

Next extract the file system. Since we need to decompress and compress the file system frequently during the exploitation, create an empty file for the extracted file.
20200314002
If we take a look at the init script in the extracted files as below, we can find that /dev/ptmx is mounted and the vulnerable kernel module memo.ko is loaded.
20200314003

Build and run exploit

After decompressing the file, the next step is to run the exploit code in qemu. Since busybox does not provide any compiler, the only option left is to compile the exploit in the host machine and compress the file system again. Modify the file system location in starting script and run the script. It is recommended to do stuff above in a shell.
20200314004

Taking Tips

The debugging process has been discussed in many previous posts. Here takes some useful notes in such challenges.
(1) Gain root privilege at first step so that we can gain some useful information for debugging.
20200314005

(2)After the above step, leak the base address of loaded module and function info for further debugging and exploitation.20200314006

Conclusion

Here I listed the necessary steps before starting the real kernel exploitation as note for myself.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.