Skip to content

Commit

Permalink
Merge pull request #29 from sepehrdaddev/experimental
Browse files Browse the repository at this point in the history
Experimental
  • Loading branch information
sepehrdaddev authored Jun 3, 2018
2 parents f858db7 + 665a374 commit 0f19222
Show file tree
Hide file tree
Showing 34 changed files with 526 additions and 551 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBRARIES OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
add_executable(Xerxes main.cpp Headers/Configuration.hpp Sources/Engine.cpp Headers/Engine.hpp Sources/Validator.cpp Headers/Validator.hpp Sources/Parser.cpp Headers/Parser.hpp Sources/Logger.cpp Headers/Logger.hpp Sources/ICMP_Flood.cpp Headers/ICMP_Flood.hpp Headers/Attack_Vectors.hpp Headers/Randomizer.hpp Sources/Null_Flood.cpp Headers/Null_Flood.hpp Sources/Slowloris.cpp Headers/Slowloris.hpp Sources/Http_Flood.cpp Headers/Http_Flood.hpp Sources/Spoofed_Flood.cpp Headers/Spoofed_Flood.hpp Sources/Spoofed_TCP_Flood.cpp Headers/Spoofed_TCP_Flood.hpp Sources/Spoofed_UDP_Flood.cpp Headers/Spoofed_UDP_Flood.hpp Sources/Attack_Vector.cpp Headers/Attack_Vector.hpp Headers/Version.hpp Sources/Beast.cpp Headers/Beast.hpp)
add_executable(Xerxes main.cpp Headers/Configuration.hpp Sources/Engine.cpp Headers/Engine.hpp Sources/Validator.cpp Headers/Validator.hpp Sources/Parser.cpp Headers/Parser.hpp Sources/ICMP_Flood.cpp Headers/ICMP_Flood.hpp Headers/Attack_Vectors.hpp Headers/Randomizer.hpp Sources/Null_Flood.cpp Headers/Null_Flood.hpp Sources/Slowloris.cpp Headers/Slowloris.hpp Sources/Http_Flood.cpp Headers/Http_Flood.hpp Sources/Spoofed_Flood.cpp Headers/Spoofed_Flood.hpp Sources/Spoofed_TCP_Flood.cpp Headers/Spoofed_TCP_Flood.hpp Sources/Spoofed_UDP_Flood.cpp Headers/Spoofed_UDP_Flood.hpp Sources/Attack_Vector.cpp Headers/Attack_Vector.hpp Headers/Version.hpp Sources/Beast.cpp Headers/Beast.hpp Sources/httphdr.cpp Headers/httphdr.hpp Headers/Logging.hpp)
target_link_libraries(Xerxes ${OPENSSL_LIBRARIES})
target_link_libraries(Xerxes ${CMAKE_DL_LIBS})
add_custom_command(TARGET Xerxes POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/useragents ${CMAKE_CURRENT_BINARY_DIR}/useragents)
Expand Down
3 changes: 1 addition & 2 deletions Headers/Attack_Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define XERXES_ATTACK_VECTOR_H

#include "Configuration.hpp"
#include "Logger.hpp"

class Attack_Vector {
friend class Spoofed_Flood;
Expand All @@ -20,7 +19,7 @@ class Attack_Vector {
virtual void pause();

private:
virtual void attack(const int *id) = 0;
virtual void attack() = 0;
};


Expand Down
2 changes: 1 addition & 1 deletion Headers/Beast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Beast : public Attack_Vector {
void init();
void update_stat(struct timeval *tv);
uint64_t getusec(struct timeval *tv);
void attack(const int *id) override;
void attack() override;
};


Expand Down
33 changes: 29 additions & 4 deletions Headers/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <string>
#include <vector>
#include <memory>
#include <ctime>

#include "Version.hpp"
#include "Logger.hpp"

struct Config{
enum Vector{NullTCP, NullUDP, TCPFlood, UDPFlood, HTTP, Slowloris, ICMPFlood, SpoofedUDP,
Expand All @@ -27,9 +27,34 @@ struct Config{
bool RandomizeSource{false};
bool RandomizePort{false};
int delay{0};
const std::unique_ptr<Logger> logger = std::make_unique<Logger>(Logger::Warning);
const std::unique_ptr<std::vector<std::string>> useragents = std::make_unique<std::vector<std::string>>();

std::vector<std::string> *useragents = nullptr;
unsigned long long *voly = nullptr;
unsigned long long *req = nullptr;
struct Timer{
clock_t start_time;
clock_t end_time;
clock_t get(){
return end_time - start_time;
}
}timer{};
void show_stat(){
if((!website.empty()) && (*voly > 0) && (*req > 0)){
timer.end_time = clock();
fprintf(stdout, "--- %s Attack statistics ---\n%llu Volys sent, %llu Requests sent, Time %f s\n",
website.c_str(), *voly, *req,((float)timer.get())/CLOCKS_PER_SEC);
}
}
Config(){
useragents = new std::vector<std::string>();
useragents->emplace_back("Wget/1.16 (linux-gnu/Xerxes)");
voly = new unsigned long long(0);
req = new unsigned long long(0);
}
~Config(){
delete useragents;
delete voly;
delete req;
}
};

const char Version[] = {
Expand Down
3 changes: 2 additions & 1 deletion Headers/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#define XERXES_DOSER_H

#include "Configuration.hpp"
#include "Logger.hpp"

class Engine {
public:
explicit Engine(std::shared_ptr<Config> conf);
void run();
void show_info();

private:
std::shared_ptr<Config> conf;
void getUserAgents();

};

Expand Down
9 changes: 4 additions & 5 deletions Headers/Http_Flood.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <openssl/ssl.h>

#include "Configuration.hpp"
#include "Logger.hpp"
#include "Randomizer.hpp"
#include "Attack_Vector.hpp"
#include "httphdr.hpp"

class Http_Flood : public Attack_Vector {
friend class Slowloris;
Expand All @@ -17,8 +17,8 @@ class Http_Flood : public Attack_Vector {
void run() override;

private:
void attack(const int *id) override;
virtual void attack_ssl(const int *id);
void attack() override;
virtual void attack_ssl();
virtual int make_socket(const char *host, const char *port, int sock_type);
SSL_CTX* InitCTX();
SSL *Apply_SSL(int socket, SSL_CTX *ctx);
Expand All @@ -29,8 +29,7 @@ class Http_Flood : public Attack_Vector {
int write_socket(int socket, const char* string, int length);
int write_socket(SSL *ssl, const char* string, int length);
const SSL_METHOD *GetMethod();
virtual void init_header(std::string& header);
virtual void init_header(std::string& header, bool);
virtual void init_header(httphdr *header);
};


Expand Down
4 changes: 3 additions & 1 deletion Headers/ICMP_Flood.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#ifndef XERXES_ICMP_FLOOD_H
#define XERXES_ICMP_FLOOD_H

#include <netinet/ip_icmp.h>

#include "Spoofed_Flood.hpp"

class ICMP_Flood : public Spoofed_Flood {
public:
explicit ICMP_Flood(std::shared_ptr<Config> conf);

private:
void attack(const int *id) override;
void attack() override;
void init_headers(iphdr *ip, icmphdr *icmp, char *buf);
void override_headers(icmphdr *tcp, iphdr *ip);

Expand Down
19 changes: 0 additions & 19 deletions Headers/Logger.hpp

This file was deleted.

15 changes: 15 additions & 0 deletions Headers/Logging.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef XERXES_LOGGING_H
#define XERXES_LOGGING_H

#include <iostream>

#define RED "\x1B[31m" // Color Terminal Red
#define YEL "\x1B[33m" // Color Terminal Yellow
#define GRN "\x1B[32m" // Color Terminal Green
#define RESET "\x1B[0m" // Color Terminal Reset color

#define print_error(err) fprintf(stderr, "%s%s %s%s\n", RED, "[ERROR]:", (err), RESET);
#define print_info(inf) fprintf(stdout, "%s%s %s%s\n", GRN, "[INFO]:", (inf), RESET);
#define print_warning(warn) fprintf(stdout, "%s%s %s%s\n", YEL, "[WARNING]:", (warn), RESET);

#endif //XERXES_LOGGING_H
5 changes: 2 additions & 3 deletions Headers/Null_Flood.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
#define XERXES_NULL_FLOOD_H

#include "Configuration.hpp"
#include "Logger.hpp"
#include "Http_Flood.hpp"

class Null_Flood : public Http_Flood {
public:
explicit Null_Flood(std::shared_ptr<Config> conf);

private:
void attack(const int *id) override;
void attack_ssl(const int *id) override;
void attack() override;
void attack_ssl() override;

};

Expand Down
3 changes: 1 addition & 2 deletions Headers/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class Parser {
private:
std::shared_ptr<Config> conf;
void check_root();
void getUserAgents();
void init_arguments();
std::map<std::string, std::function<void(std::string&)>> arguments;
std::map<std::string, std::function<void(const char*)>> arguments;
};


Expand Down
64 changes: 34 additions & 30 deletions Headers/Randomizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,73 @@ namespace Randomizer{
return distribution(engine);
}

static const std::string randomIP(){
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;
static const void randomIP(std::string& src){
src = std::to_string(randomInt(1, 256))
+ "."
+ std::to_string(randomInt(1, 256))
+ "."
+ std::to_string(randomInt(1, 256))
+ "."
+ std::to_string(randomInt(1, 256));
}

static int randomPort(){
return randomInt(0, 65535);
static auto init_s_port = 0;
static int seq = 0;
seq++;
if(init_s_port == 0){
init_s_port = 1024 + (randomInt(0, 2000));
return init_s_port;
}
return (seq + init_s_port) % 65536;
}

static const std::string randomstr(){
static const void randomstr(std::string& src){
int string_length = randomInt(0, 20);
std::string string{};
for(int i = 0; i < string_length; i++){
string += (static_cast<char>('0' + randomInt(0, 72)));
src += (static_cast<char>('0' + randomInt(0, 72)));
}
return string;
}

static const std::string randomize_Vector(const std::vector<std::string> &vec){
return vec[randomInt(0, static_cast<int>(vec.size()) -1)];
static const void randomize_Vector(const std::vector<std::string> &vec, std::string& src){
src = vec[randomInt(0, static_cast<int>(vec.size()) -1)];
}

static const std::string random_referer(){
static const void random_referer(std::string& src){
static std::vector<std::string> referer{
"https://www.google.com/", "https://www.yahoo.com/", "https://www.bing.com/",
"https://twitter.com/", "https://www.facebook.com/", "https://www.msn.com/",
"https://www.youtube.com/", "https://yandex.com/", "https://www.amazon.com/"};
return randomize_Vector(referer);
randomize_Vector(referer, src);
}

static const std::string random_useragent(const std::vector<std::string> &useragents){
return randomize_Vector(useragents);
static const void random_useragent(const std::vector<std::string> &useragents, std::string& src){
randomize_Vector(useragents, src);
}

static const std::string random_encoding(){
static const void random_encoding(std::string& src){
static std::vector<std::string> encoding{"\'\'", "*", "identity", "gzip", "deflate"};
return randomize_Vector(encoding);
randomize_Vector(encoding, src);
}

static const std::string random_caching(){
static const void random_caching(std::string& src){
static std::vector<std::string> caching{"no-cache", "max-age=0"};
return randomize_Vector(caching);
randomize_Vector(caching, src);
}

static const std::string random_charset(){
static const void random_charset(std::string& src){
static std::vector<std::string> charset{"ISO-8859-1", "utf-8", "Windows-1251", "ISO-8859-2", "ISO-8859-15"};
return randomize_Vector(charset);
randomize_Vector(charset, src);
}

static const std::string random_contenttype(){
static const void random_contenttype(std::string& src){
static std::vector<std::string> contenttype{"multipart/form-data", "application/x-url-encoded"};
return randomize_Vector(contenttype);
randomize_Vector(contenttype, src);
}

static const std::string random_method(){
static const void random_method(std::string& src){
static std::vector<std::string> methods{"GET", "HEAD"};
return randomize_Vector(methods);
randomize_Vector(methods, src);
}
}

Expand Down
7 changes: 3 additions & 4 deletions Headers/Slowloris.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define XERXES_SLOWLORIS_H

#include "Configuration.hpp"
#include "Logger.hpp"
#include "Randomizer.hpp"
#include "Http_Flood.hpp"

Expand All @@ -11,9 +10,9 @@ class Slowloris : public Http_Flood {
explicit Slowloris(std::shared_ptr<Config> conf);

private:
void attack(const int *id) override;
void attack_ssl(const int *id) override;
void init_header(std::string& header, bool keep_alive) override;
void attack() override;
void attack_ssl() override;
void init_header(httphdr *header) override;
};


Expand Down
4 changes: 0 additions & 4 deletions Headers/Spoofed_Flood.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
#define XERXES_SPOOFED_FLOOD_H

#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>

#include "Configuration.hpp"
#include "Logger.hpp"
#include "Attack_Vector.hpp"

class Spoofed_Flood : public Attack_Vector {
Expand Down
4 changes: 3 additions & 1 deletion Headers/Spoofed_TCP_Flood.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#ifndef XERXES_SPOOFED_TCP_FLOOD_H
#define XERXES_SPOOFED_TCP_FLOOD_H

#include <netinet/tcp.h>

#include "Spoofed_Flood.hpp"

class Spoofed_TCP_Flood : public Spoofed_Flood {
public:
explicit Spoofed_TCP_Flood(std::shared_ptr<Config> conf);

private:
void attack(const int *id) override;
void attack() override;
void init_headers(iphdr *ip, tcphdr *tcp, char *buf);
void override_headers(tcphdr *tcp, iphdr *ip);
};
Expand Down
4 changes: 3 additions & 1 deletion Headers/Spoofed_UDP_Flood.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#ifndef XERXES_SPOOFED_UDP_FLOOD_H
#define XERXES_SPOOFED_UDP_FLOOD_H

#include <netinet/udp.h>

#include "Spoofed_Flood.hpp"

class Spoofed_UDP_Flood : public Spoofed_Flood {
public:
explicit Spoofed_UDP_Flood(std::shared_ptr<Config> conf);

private:
void attack(const int *id) override;
void attack() override;
void init_headers(iphdr *ip, udphdr *udp, char *buf);
void override_headers(udphdr *udp, iphdr *ip);
};
Expand Down
Loading

0 comments on commit 0f19222

Please sign in to comment.