Setup
Overview
The kernel module used for these exercises is based off hxpCTF 2020
kernel-rop
. It didn't come with source, so I rewrote it and have it uploaded here. You can build the kernel yourself or use my prebuilt one here.
You will need qemu
,gcc
, and gdb
to follow along with these problems.
The launch.sh
script will rebuild the file system and launch qemu
The -s
flag will start qemu with gdb debugging enabled on localhost port 1234
. Most gdb extensions like gef
and pwndbg
have trouble debugging kernels and you can disable them with the command: gdb -nx ./bzImage
Kernel-Overflow module
The module we will be exploiting for most of this series is named kernel-overflow
and is located here [TODO github link]. The module creates a character device named kernel-overflow
which is accessible at /dev/kernel-overflow
. It supports read and write operations, which ultimately lead to a leak and overflow.
Leak
The leak happens when read
is called on the character device with a length greater than 256
bytes. Our stack buffer tmp
is only 256
bytes long and the length check below it is not sufficient to prevent an overread from happening. As long as our read is less than 0x1000
bytes, we can read past tmp
and leak out the stack cookie
and stack saved registers
Overflow
The overflow happens when write
is called on the character device with a length greater than 256
bytes. Our stack buffer tmp
is only 256
bytes long and just like the leak, the length check is not sufficient to prevent a stack overflow.
Last updated