#include #include #include void help (); int main (int argc, char **argv) { u_long src_ip, dst_ip; u_char *packet; int socket, pktsize, confirm; char err_buff[LIBNET_ERRBUF_SIZE], c; if (argc == 1) { help (); exit (-1); } while ((c = getopt (argc, argv, "d:s:")) != EOF) { switch (c) { case 'd': if (!(dst_ip = libnet_name_resolve (optarg, LIBNET_RESOLVE))) { libnet_error (LIBNET_ERR_FATAL, "Bad destination IP Address: %s\n", optarg); } break; case 's': if (!(src_ip = libnet_name_resolve (optarg, LIBNET_RESOLVE))) { ibnet_error (LIBNET_ERR_FATAL, "Bad source IP Address: %s\n",optarg); } break; } } if (!src_ip || !dst_ip) { help (); exit (-1); } pktsize = LIBNET_IP_H + LIBNET_ICMP_ECHO_H; libnet_init_packet (pktsize, &packet); if (packet == NULL) { libnet_error (LIBNET_ERR_FATAL, "Cannot allocate memory for packet.\n"); exit (-1); } socket = libnet_open_raw_sock (IPPROTO_RAW); if (socket == -1) { libnet_error (LIBNET_ERR_FATAL, "Cannot open network.\n"); exit (-1); } libnet_build_ip (ICMP_ECHO_H, IPTOS_LOWDELAY | IPTOS_THROUGHPUT, 242, 0, 48, IPPROTO_ICMP, src_ip, dst_ip, NULL, 0, packet); libnet_build_icmp_echo (ICMP_ECHO, 0, 242, 5, NULL, 0, packet + LIBNET_IP_H); if (libnet_do_checksum (packet, IPPROTO_ICMP, LIBNET_ICMP_ECHO_H) == -1) { libnet_error (LIBNET_ERR_FATAL, "Cannot compute checksum.\n"); exit (-1); } confirm = libnet_write_ip (socket, packet, pktsize); if (confirm < pktsize) { libnet_error (LIBNET_ERR_FATAL, "libnet_write_ip wrote 0x%x bytes out of 0x%x expected.\n", confirm, pktsize); } else { printf ("Sent ICMP_ECHO, wrote 0x%x bytes.\n", pktsize); } libnet_destroy_packet (&packet); return 0; } void help (void) { printf ("ICMP_ECHO Spoofer, written by Javaman.\n"); printf ("Requires libnet.\n"); printf ("Options:\n"); printf ("\t-d\tDestination IP\n"); printf ("\t-s\tSource IP\n"); }