从 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);