朋友在執行的時候說有的會出現提權不成功,內核crash掉的現象。因為cred結構體的偏移量可能因為內核版本不同、內核編譯選項不同而出現差異,作者給的exp偏移量是寫死的,所以exp里面對應的偏移地址也要改一下。以下方法可以算出不同內核版本默認編譯選項下的cred偏移地址:
1.Makefile
obj-m += getCredOffset.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
2.getCredOffset.c
#include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/kthread.h> #include <linux/errno.h> #include <linux/types.h> int init_module() { printk("[!]current cred offset:%x\n",(unsigned long)&(current->cred)-(unsigned long)current); return 0; } void cleanup_module() { printk("module cleanup\n"); }
把上面倆文件扔到一目錄里,make一下,生成getCredOffset.ko,執行insmod getCredOffset.ko,然后新開一個命令行執行dmesg | grep "cred offset",OK了,把得到的offset替換到exp里面。
前面說了,這個適合默認的內核編譯選項,這樣才能在本地環境中的root權限下insmod,至於其他情況,只能通過其他方法來確定cred偏移量了。
這個漏洞是個任意地址讀寫漏洞,所以也可以在確定task_struct地址之后,以當前用戶的uid為特征去搜索內存,畢竟cred離task_struct不遠。