Skip to content

Commit

Permalink
code cleanup and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehrdaddev committed Apr 11, 2019
1 parent e3aa29f commit 6ed786f
Show file tree
Hide file tree
Showing 79 changed files with 1,218 additions and 1,322 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
/cmake-build-*
.idea
PKGBUILD
.vscode
28 changes: 24 additions & 4 deletions CMakeLists.txt
Expand Up @@ -15,24 +15,44 @@ if(NOT CMAKE_BUILD_TYPE)
endif()

if(STATIC)
option(BUILD_SHARED OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBRARIES OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++ -Wl,--whole-archive -Wl,--no-whole-archive")
endif()

option(BUILD_TESTING OFF)

# LibreSSL Options
option(LIBRESSL_APPS OFF)
option(LIBRESSL_TESTS OFF)
option(BUILD_SHARED_LIBS OFF)
option(BUILD_NC OFF)
option(LIBRESSL_SKIP_INSTALL ON)

set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -s")

include_directories(include)
include_directories(lib/catch/single_include/catch2)
include_directories(lib/args)
include_directories(lib/spdlog/include)
include_directories(lib/libressl/include)

include(CTest)
add_subdirectory(lib)
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(lib/libressl)
add_subdirectory(lib/spdlog)

if(BUILD_TESTING)
include(CTest)
add_subdirectory(test)
endif()

file(GLOB SRCS src/*.cpp)
set(LIBS tls ssl crypto pthread dl)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(Xerxes ${SRCS})
target_link_libraries(Xerxes ${LIBS})

file(COPY bash-completion DESTINATION ${CMAKE_BINARY_DIR}/bin)
file(COPY man DESTINATION ${CMAKE_BINARY_DIR}/bin)
Expand Down
18 changes: 18 additions & 0 deletions include/Vector.h
@@ -0,0 +1,18 @@
#ifndef XERXES_VECTOR_H
#define XERXES_VECTOR_H

#include <memory>

#include "config.h"

class Vector {
public:
explicit Vector(std::shared_ptr<Config> config);
virtual ~Vector() = default;
virtual void run() = 0;

protected:
std::shared_ptr<Config> config;
};

#endif // XERXES_VECTOR_H
16 changes: 16 additions & 0 deletions include/ack_flood.h
@@ -0,0 +1,16 @@
#ifndef XERXES_ACK_FLOOD_H
#define XERXES_ACK_FLOOD_H

#include "spoofed_tcp_flood.h"

class ack_flood : public spoofed_tcp_flood {

public:
explicit ack_flood(std::shared_ptr<Config> config);
~ack_flood() override = default;

protected:
void finalize_hdr(tcphdr *tcp, iphdr *ip) override;
};

#endif // XERXES_ACK_FLOOD_H
21 changes: 21 additions & 0 deletions include/base_flood.h
@@ -0,0 +1,21 @@
#ifndef XERXES_BASE_FLOOD_H
#define XERXES_BASE_FLOOD_H

#include "Vector.h"
#include "socket.h"
#include <vector>

class base_flood : public Vector {

public:
base_flood(std::shared_ptr<Config> config, int sock_type);
~base_flood() override = default;
void run() override;

protected:
virtual int gen_hdr(std::string &string);
virtual void init_sockets(std::vector<std::unique_ptr<Socket>> &sockets);
int sock_type{};
};

#endif // XERXES_BASE_FLOOD_H
20 changes: 20 additions & 0 deletions include/base_spoofed_flood.h
@@ -0,0 +1,20 @@
#ifndef XERXES_BASE_SPOOFED_FLOOD_H
#define XERXES_BASE_SPOOFED_FLOOD_H

#include "Vector.h"
#include "rsocket.h"

class base_spoofed_flood : public Vector {
public:
base_spoofed_flood(std::shared_ptr<Config> config, int protocol);
~base_spoofed_flood() override = default;
void run() override;

protected:
virtual char *gen_hdr(sockaddr_in *dst, int len) = 0;
virtual void init_sockets(std::vector<std::unique_ptr<Rsocket>> &sockets);
int proto{};
int hdr_len{};
};

#endif // XERXES_BASE_SPOOFED_FLOOD_H
16 changes: 16 additions & 0 deletions include/blacknurse.h
@@ -0,0 +1,16 @@
#ifndef XERXES_BLACKNURSE_H
#define XERXES_BLACKNURSE_H

#include "icmp_flood.h"

class blacknurse : public icmp_flood {

public:
explicit blacknurse(std::shared_ptr<Config> config);
~blacknurse() override = default;

protected:
void finalize_hdr(icmphdr *icmp, iphdr *ip) override;
};

#endif // XERXES_BLACKNURSE_H
36 changes: 36 additions & 0 deletions include/config.h
@@ -0,0 +1,36 @@
#ifndef XERXES_CONFIG_H
#define XERXES_CONFIG_H

#include <string>

enum __Vector__ {
NULL_TCP = 0,
NULL_UDP,
TCP_FLOOD,
UDP_FLOOD,
HTTP_FLOOD,
ICMP_FLOOD,
SYN_FLOOD,
ACK_FLOOD,
FIN_FLOOD,
SPOOFED_UDP_FLOOD,
TEARDROP,
BLACKNURSE,
LAND,
SMURF
};

struct Config {
std::string rhost;
std::string rport;
std::string bcast;
int vec;
int trds;
int conn;
bool tls;
bool rand_lhost;
bool rand_lport;
timespec time;
};

#endif // XERXES_CONFIG_H
7 changes: 3 additions & 4 deletions src/engine.h → include/engine.h
Expand Up @@ -8,9 +8,8 @@
class engine {

public:
explicit engine(std::shared_ptr<Config> config);
virtual ~engine() = default;
explicit engine(std::shared_ptr<Config> config);
virtual ~engine() = default;
};


#endif //XERXES_ENGINE_H
#endif // XERXES_ENGINE_H
16 changes: 16 additions & 0 deletions include/fin_flood.h
@@ -0,0 +1,16 @@
#ifndef XERXES_FIN_FLOOD_H
#define XERXES_FIN_FLOOD_H

#include "spoofed_tcp_flood.h"

class fin_flood : public spoofed_tcp_flood {

public:
explicit fin_flood(std::shared_ptr<Config> config);
~fin_flood() override = default;

protected:
void finalize_hdr(tcphdr *tcp, iphdr *ip) override;
};

#endif // XERXES_FIN_FLOOD_H
46 changes: 46 additions & 0 deletions include/http.h
@@ -0,0 +1,46 @@
#ifndef XERXES_HTTP_H
#define XERXES_HTTP_H

#include "utils.h"
#include <string>
#include <vector>

struct httphdr {
std::string method{};
std::string path{};
std::string useragent{};
std::string cache_control{};
std::string encoding{};
std::string charset[2]{};
std::string referer{};
std::string content_type{};
std::string cookie[2]{};
std::string connection_type{"Keep-Alive"};
std::string accept{"*/*"};
};

namespace http {

namespace randomizer {

void random_referer(std::string &src);

void random_useragent(std::string &src);

void random_encoding(std::string &src);

void random_caching(std::string &src);

void random_charset(std::string &src);

void random_contenttype(std::string &src);

void random_method(std::string &src);
} // namespace randomizer

void hdr_gen(httphdr &hdr, std::string &str);

void load_usr(std::vector<std::string> &useragents);
} // namespace http

#endif // XERXES_HTTP_H
15 changes: 15 additions & 0 deletions include/http_flood.h
@@ -0,0 +1,15 @@
#ifndef XERXES_HTTP_FLOOD_H
#define XERXES_HTTP_FLOOD_H

#include "tcp_flood.h"

class http_flood : public tcp_flood {
public:
explicit http_flood(std::shared_ptr<Config> config);
~http_flood() override = default;

protected:
int gen_hdr(std::string &string) override;
};

#endif // XERXES_HTTP_FLOOD_H
21 changes: 21 additions & 0 deletions include/icmp_flood.h
@@ -0,0 +1,21 @@
#ifndef XERXES_ICMP_FLOOD_H
#define XERXES_ICMP_FLOOD_H

#include "base_spoofed_flood.h"

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

class icmp_flood : public base_spoofed_flood {

public:
explicit icmp_flood(std::shared_ptr<Config> config);
~icmp_flood() override = default;

protected:
char *gen_hdr(sockaddr_in *dst, int len) override;
virtual void init_hdr(icmphdr *icmp, iphdr *ip);
virtual void finalize_hdr(icmphdr *icmp, iphdr *ip);
};

#endif // XERXES_ICMP_FLOOD_H
16 changes: 16 additions & 0 deletions include/land.h
@@ -0,0 +1,16 @@
#ifndef XERXES_LAND_H
#define XERXES_LAND_H

#include "spoofed_tcp_flood.h"

class land : public spoofed_tcp_flood {

public:
explicit land(std::shared_ptr<Config> config);
~land() override = default;

protected:
void finalize_hdr(tcphdr *tcp, iphdr *ip) override;
};

#endif // XERXES_LAND_H
16 changes: 16 additions & 0 deletions include/null_tcp.h
@@ -0,0 +1,16 @@
#ifndef XERXES_NULL_TCP_H
#define XERXES_NULL_TCP_H

#include "tcp_flood.h"

class null_tcp : public tcp_flood {
public:
explicit null_tcp(std::shared_ptr<Config> config);

~null_tcp() override = default;

protected:
int gen_hdr(std::string &string) override;
};

#endif // XERXES_NULL_TCP_H
16 changes: 16 additions & 0 deletions include/null_udp.h
@@ -0,0 +1,16 @@
#ifndef XERXES_NULL_UDP_H
#define XERXES_NULL_UDP_H

#include "udp_flood.h"

class null_udp : public udp_flood {
public:
explicit null_udp(std::shared_ptr<Config> config);

~null_udp() override = default;

protected:
int gen_hdr(std::string &string) override;
};

#endif // XERXES_NULL_UDP_H
29 changes: 29 additions & 0 deletions include/rsocket.h
@@ -0,0 +1,29 @@
#ifndef XERXES_RSOCKET_H
#define XERXES_RSOCKET_H

#include <netdb.h>
#include <string>
#include <vector>

class Rsocket {

public:
Rsocket(std::string host, std::string port, int proto);
virtual ~Rsocket() = default;
virtual ssize_t Write(const char *str, size_t len);
virtual bool Open();
virtual bool Close();
virtual bool Alive();
sockaddr_in *GetDst();

protected:
bool open();
bool close();
std::string rhost;
std::string rport;
int proto;
int fd{};
sockaddr_in dst;
};

#endif // XERXES_RSOCKET_H
16 changes: 16 additions & 0 deletions include/smurf.h
@@ -0,0 +1,16 @@
#ifndef XERXES_SMURF_H
#define XERXES_SMURF_H

#include "icmp_flood.h"

class smurf : public icmp_flood {

public:
explicit smurf(std::shared_ptr<Config> config);
~smurf() override = default;

protected:
void finalize_hdr(icmphdr *icmp, iphdr *ip) override;
};

#endif // XERXES_SMURF_H

0 comments on commit 6ed786f

Please sign in to comment.