Commit 14c8211b authored by robertdavidgraham's avatar robertdavidgraham
Browse files

--infinite

parent 42bea8f2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -847,6 +847,8 @@ masscan_set_parameter(struct Masscan *masscan,
        masscan->op = Operation_List_Adapters;
    } else if (EQUALS("includefile", name)) {
        ranges_from_file(&masscan->targets, value);
    } else if (EQUALS("infinite", name)) {
        masscan->is_infinite = 1;
    } else if (EQUALS("ip-options", name)) {
        fprintf(stderr, "nmap(%s): unsupported: maybe soon\n", name);
        exit(1);
@@ -1109,7 +1111,7 @@ is_singleton(const char *name)
        "send-eth", "send-ip", "iflist", "randomize-hosts",
        "nmap", "trace-packet", "pfring", "sendq",
        "banners", "banner", "offline", "ping", "ping-sweep",
		"arp", 
		"arp",  "infinite",
        0};
    size_t i;

+8 −2
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ main_listscan(struct Masscan *masscan)
    struct BlackRock blackrock;
    unsigned r = masscan->retries + 1;
    unsigned increment = masscan->shard.of;
    uint64_t seed = masscan->seed;

    count_ports = rangelist_count(&masscan->ports);
    if (count_ports == 0)
@@ -30,8 +31,8 @@ main_listscan(struct Masscan *masscan)

    range = count_ips * count_ports;

    
    blackrock_init(&blackrock, range, masscan->seed);
infinite:
    blackrock_init(&blackrock, range, seed);
    
    start = masscan->resume.index + (masscan->shard.one-1);
    end = range;
@@ -68,4 +69,9 @@ main_listscan(struct Masscan *masscan)
            r = masscan->retries + 1;
        }
    }

    if (masscan->is_infinite) {
        seed++;
        goto infinite;
    }
}
 No newline at end of file
+30 −9
Original line number Diff line number Diff line
@@ -258,6 +258,8 @@ transmit_thread(void *v) /*aka. scanning_thread() */
    unsigned src_ip_mask;
    unsigned src_port;
    unsigned src_port_mask;
    uint64_t seed = masscan->seed;
    uint64_t repeats = 0; /* --infinite repeats */

    get_sources(masscan, parms->nic_index, 
                &src_ip, &src_ip_mask, 
@@ -265,13 +267,18 @@ transmit_thread(void *v) /*aka. scanning_thread() */

    LOG(1, "xmit: starting transmit thread #%u\n", parms->nic_index);

    /* "THROTTLER" rate-limits how fast we transmit, set with the
     * --max-rate parameter */
    throttler_start(throttler, masscan->max_rate/masscan->nic_count);

infinite:

    /* Create the shuffler/randomizer. This creates the 'range' variable,
     * which is simply the number of IP addresses times the number of
     * ports */
    range = rangelist_count(&masscan->targets) 
            * rangelist_count(&masscan->ports);
    blackrock_init(&blackrock, range, masscan->seed);
    blackrock_init(&blackrock, range, seed);

    /* Calculate the 'start' and 'end' of a scan. One reason to do this is
     * to support --shard, so that multiple machines can co-operate on
@@ -286,11 +293,6 @@ transmit_thread(void *v) /*aka. scanning_thread() */
    end += retries * rate;



    /* "THROTTLER" rate-limits how fast we transmit, set with the
     * --max-rate parameter */
    throttler_start(throttler, masscan->max_rate/masscan->nic_count);

    /* -----------------
     * the main loop
     * -----------------*/
@@ -349,9 +351,18 @@ transmit_thread(void *v) /*aka. scanning_thread() */

            /*
             * SYN-COOKIE LOGIC
             *  Figure out the source IP/port, and the SYN cookie
             */
            ip_me = src_ip + (i & src_ip_mask);
            port_me = src_port + (xXx & src_port_mask);
            if (src_ip_mask > 1 || src_port_mask > 1) {
                uint64_t r = syn_cookie((unsigned)(i+repeats), 
                                        (unsigned)((i+repeats)>>32),
                                        (unsigned)xXx, (unsigned)(xXx>>32));
                port_me = src_port + (r & src_port_mask);
                ip_me = src_ip + ((r>>16) & src_ip_mask);
            } else {
                ip_me = src_ip;
                port_me = src_port;
            }
            cookie = syn_cookie(ip_them, port_them, ip_me, port_me);
            
            /*
@@ -401,6 +412,16 @@ transmit_thread(void *v) /*aka. scanning_thread() */
        parms->my_index = i;
    }

    /*
     * --infinite
     *  For load testing, go around and do this again
     */
    if (masscan->is_infinite && !control_c_pressed) {
        seed++;
        repeats++;
        goto infinite;
    }


    /*
     * We are done transmitting. However, response packets will take several
@@ -1107,7 +1128,7 @@ main_scan(struct Masscan *masscan)
            rate += parms->throttler->current_rate;
        }

        if (min_index >= range) {
        if (min_index >= range && !masscan->is_infinite) {
            control_c_pressed = 1;
        }

+7 −0
Original line number Diff line number Diff line
@@ -181,6 +181,13 @@ struct Masscan
        unsigned ip;
        unsigned port;
    } redis;

    /**
     * --infinite
     * Restarts the scan from the beginning, for load testing, but
     * by incrementing the seed
     */
    unsigned is_infinite:1;
};