
CPIOアーカイブからファイルを展開する
#!/bin/sh
mkdir fs
cd fs
cp ../initramfs.cpio.gz ./initramfs.cpio.gz
gunzip ./initramfs.cpio.gz
cpio -idm < ./initramfs.cpio
rm initramfs.cpio
cd ..
エクスプロイトをコンパイルし、fsに追加して実行する。
#!/bin/sh
gcc -w -o exploit -static exploit.c -pthread -lrt &&\
# musl-gcc -w -s -static -o3 exploit.c -o exploit -masm=intel &&\
mv exploit ./fs/ &&\
cd fs &&\
find . -print0 | cpio --owner root --null -ov --format=newc | gzip -9 > ../initramfs.cpio.gz &&\
cd .. &&\
# gunzip -f initramfs.cpio.gz &&\
./run.sh
ext4ファイルシステムアーカイブの場合
mount ./initramfs.cpio.gz ./fs/
0x20サイズの構造体で、copy_to_user呼び出しに対するチェックが存在しない
struct msg_msg {
struct list_head m_list;
long m_type;
size_t m_ts; /* message text size */
struct msg_msgseg *next;
void *security;
/* the actual message follows immediately */
};
ユーザーメッセージは msg_msg 構造体の直後に格納され、0x1000 - 0x30 まで続く。その後は struct msg_msgseg *next に保存されたチャンクの単方向リストとなり、各アロケーションのサイズは最大 0x1000 で、NULL 終端される仕様である。
任意読み取りの場合:
next と m_ts を上書きし、上書きされた next ポインタから読み取るようにする。
任意書き込みの場合:
msgsnd() // Userland
do_msgsnd() // Kernel land
load_msg()
alloc_msg() // Allocate all the necessary chunks
copy_from_user() // Race here to replace `struct msg_msgseg *next` before its used to copy userdata. Maybe use userfaultfd ;)
msg_msg do_msgsnd load_msg copy_msg
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
CPU_SET(0,&cpu_set);
ret=sched_setaffinity(0,sizeof(cpu_set),&cpu_set);