kernel_uaf

kernel uaf

分析

解包得到babydriver.ko文件,

这里其实有点奇怪,关于驱动文件我们要明白,他是常驻内核态的, 我们的程序打开这个文件描述符和读写关闭等操作会转入到这个驱动对应的函数内,我们编写用户态程序进行操作,其实是类似于我们直接去调用这些函数的。其中对应关系,

具体的关系一般要查看 data段的 file_operations, 这里说下一般遇到的常见命名方式。

  • open(“driver_name”, flag) => Xopen
  • Write => Xwrite
  • read => Xread
  • Ioctl => Xioctl
  • close(fd) => Xrelease

然后载入和卸载驱动会自动调用 init exit两个函数。

漏洞

简单分析几个函数, 发现这个驱动主要使用了一个babydevice_t结构体, 其中保存起点和长度,

image-20220213151649156

可以通过read和write进行读写,

通过ioctl可以实现重设大小,

image-20220213151737140

每次open都会设置下这个全局变量。

image-20220213151824489

close的时候将这个buf free掉, 但是没有清除全局变量,存在一个uaf

我们可以同时打开两次, 两次共享这个全局变量, 其中一个关闭的时候,通过另一个就可以实现uaf的操作

image-20220213151904695

利用

uaf的利用思路就是堆块再次使用,进行复写。

struct cred

这里介绍一个提权手段,linux下进程的权限管理是通过cred结构体实现的,定义如下:

// include/linux/cred.h
/*
 * The security context of a task
 *
 * The parts of the context break down into two categories:
 *
 *  (1) The objective context of a task.  These parts are used when some other
 *      task is attempting to affect this one.
 *
 *  (2) The subjective context.  These details are used when the task is acting
 *      upon another object, be that a file, a task, a key or whatever.
 *
 * Note that some members of this structure belong to both categories - the
 * LSM security pointer for instance.
 *
 * A task has two security pointers.  task->real_cred points to the objective
 * context that defines that task's actual details.  The objective part of this
 * context is used whenever that task is acted upon.
 *
 * task->cred points to the subjective context that defines the details of how
 * that task is going to act upon another object.  This may be overridden
 * temporarily to point to another security context, but normally points to the
 * same context as task->real_cred.
 */
struct cred {
   
        atomic_t        usage;
#ifdef CONFIG_DEBUG_CREDENTIALS
        atomic_t        subscribers;    /* number of processes subscribed */
        void            *put_addr;
        unsigned        magic;
#define CRED_MAGIC      0x43736564
#define<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值