Loading src/main-conf.c +32 −1 Original line number Diff line number Diff line Loading @@ -149,6 +149,14 @@ masscan_echo_nic(struct Masscan *masscan, FILE *fp, unsigned i) masscan->nic[i].adapter_mac[3], masscan->nic[i].adapter_mac[4], masscan->nic[i].adapter_mac[5]); if (masscan->nic[i].router_ip) { fprintf(fp, "router-ip%s = %u.%u.%u.%u\n", zzz, (masscan->nic[i].router_ip>>24)&0xFF, (masscan->nic[i].router_ip>>16)&0xFF, (masscan->nic[i].router_ip>> 8)&0xFF, (masscan->nic[i].router_ip>> 0)&0xFF ); } else fprintf(fp, "router-mac%s = %02x:%02x:%02x:%02x:%02x:%02x\n", zzz, masscan->nic[i].router_mac[0], masscan->nic[i].router_mac[1], Loading Loading @@ -195,6 +203,7 @@ masscan_echo(struct Masscan *masscan, FILE *fp) case Output_XML: fprintf(fp, "output-format = xml\n"); break; case Output_Binary: fprintf(fp, "output-format = binary\n"); break; case Output_JSON: fprintf(fp, "output-format = json\n"); break; case Output_None: fprintf(fp, "output-format = none\n"); break; case Output_Redis: fprintf(fp, "output-format = redis\n"); fprintf(fp, "redis = %u.%u.%u.%u:%u\n", Loading Loading @@ -669,6 +678,22 @@ masscan_set_parameter(struct Masscan *masscan, memcpy(masscan->nic[index].router_mac, mac, 6); } else if (EQUALS("router-ip", name)) { /* Send packets FROM this IP address */ struct Range range; range = range_parse_ipv4(value, 0, 0); /* Check for bad format */ if (range.begin != range.end) { LOG(0, "FAIL: bad source IPv4 address: %s=%s\n", name, value); LOG(0, "hint addresses look like \"19.168.1.23\"\n"); exit(1); } masscan->nic[index].router_ip = range.begin; } else if (EQUALS("rate", name) || EQUALS("max-rate", name) ) { double rate = 0.0; double point = 10.0; Loading Loading @@ -849,6 +874,8 @@ masscan_set_parameter(struct Masscan *masscan, ranges_from_file(&masscan->targets, value); } else if (EQUALS("infinite", name)) { masscan->is_infinite = 1; } else if (EQUALS("interactive", name)) { masscan->is_interactive = 1; } else if (EQUALS("ip-options", name)) { fprintf(stderr, "nmap(%s): unsupported: maybe soon\n", name); exit(1); Loading Loading @@ -910,11 +937,13 @@ masscan_set_parameter(struct Masscan *masscan, fprintf(stderr, "nmap(%s): OS scanning unsupported\n", name); exit(1); } else if (EQUALS("output-format", name)) { masscan->is_interactive = 0; if (EQUALS("list", value)) masscan->nmap.format = Output_List; else if (EQUALS("interactive", value)) masscan->nmap.format = Output_Interactive; else if (EQUALS("xml", value)) masscan->nmap.format = Output_XML; else if (EQUALS("binary", value)) masscan->nmap.format = Output_Binary; else if (EQUALS("json", value)) masscan->nmap.format = Output_JSON; else if (EQUALS("none", value)) masscan->nmap.format = Output_None; else if (EQUALS("redis", value)) masscan->nmap.format = Output_Redis; else { fprintf(stderr, "error: %s=%s\n", name, value); Loading @@ -922,6 +951,7 @@ masscan_set_parameter(struct Masscan *masscan, } else if (EQUALS("output-filename", name) || EQUALS("output-file", name)) { if (masscan->nmap.format == 0) masscan->nmap.format = Output_XML; masscan->is_interactive = 0; strcpy_s(masscan->nmap.filename, sizeof(masscan->nmap.filename), value); } else if (EQUALS("pcap", name)) { strcpy_s(masscan->pcap_filename, sizeof(masscan->pcap_filename), value); Loading Loading @@ -1111,7 +1141,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", "infinite", "arp", "infinite", "interactive", 0}; size_t i; Loading Loading @@ -1301,6 +1331,7 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) /* Do nothing: this code never does DNS lookups anyway */ break; case 'o': /* nmap output format */ masscan->is_interactive = 0; switch (argv[i][2]) { case 'A': masscan->nmap.format = Output_All; Loading src/main-dedup.c +26 −15 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ struct DedupEntry { unsigned ip; unsigned port; unsigned ip_them; unsigned port_them; unsigned ip_me; unsigned port_me; }; struct DedupTable { Loading Loading @@ -51,7 +53,7 @@ dedup_destroy(struct DedupTable *table) /*************************************************************************** ***************************************************************************/ unsigned dedup_is_duplicate(struct DedupTable *dedup, unsigned ip, unsigned port) dedup_is_duplicate(struct DedupTable *dedup, unsigned ip_them, unsigned port_them, unsigned ip_me, unsigned port_me) { unsigned hash; struct DedupEntry *bucket; Loading @@ -59,24 +61,31 @@ dedup_is_duplicate(struct DedupTable *dedup, unsigned ip, unsigned port) /* THREAT: probably need to secure this hash, though the syn-cookies * provides some protection */ hash = (ip + port) ^ ((ip>>8) + (ip>>16)) ^ (ip>>24); hash = (ip_them + port_them) ^ ((ip_me) + (ip_them>>16)) ^ (ip_them>>24) ^ port_me; hash &= DEDUP_ENTRIES-1; /* Search in this bucket */ bucket = dedup->entries[hash]; for (i = 0; i < 4; i++) { if (bucket[i].ip == ip && bucket[i].port == port) { if (bucket[i].ip_them == ip_them && bucket[i].port_them == port_them && bucket[i].ip_me == ip_me && bucket[i].port_me == port_me) { /* move to end of list so constant repeats get ignored */ if (i > 0) { bucket[i].ip ^= bucket[0].ip; bucket[i].port ^= bucket[0].port; bucket[0].ip ^= bucket[i].ip; bucket[0].port ^= bucket[i].port; bucket[i].ip ^= bucket[0].ip; bucket[i].port ^= bucket[0].port; bucket[i].ip_them ^= bucket[0].ip_them; bucket[i].port_them ^= bucket[0].port_them; bucket[i].ip_me ^= bucket[0].ip_me; bucket[i].port_me ^= bucket[0].port_me; bucket[0].ip_them ^= bucket[i].ip_them; bucket[0].port_them ^= bucket[i].port_them; bucket[0].ip_me ^= bucket[i].ip_me; bucket[0].port_me ^= bucket[i].port_me; bucket[i].ip_them ^= bucket[0].ip_them; bucket[i].port_them ^= bucket[0].port_them; bucket[i].ip_me ^= bucket[0].ip_me; bucket[i].port_me ^= bucket[0].port_me; } return 1; } Loading @@ -85,8 +94,10 @@ dedup_is_duplicate(struct DedupTable *dedup, unsigned ip, unsigned port) /* We didn't find it, so add it to our list. This will push * older entries at this bucket off the list */ memmove(bucket, bucket+1, 3*sizeof(*bucket)); bucket[0].ip = ip; bucket[0].port = port; bucket[0].ip_them = ip_them; bucket[0].port_them = port_them; bucket[0].ip_me = ip_me; bucket[0].port_me = port_me; return 0; } src/main-initadapter.c +4 −3 Original line number Diff line number Diff line Loading @@ -141,11 +141,12 @@ masscan_initialize_adapter( if (masscan->is_offline) { memcpy(router_mac, "\x66\x55\x44\x33\x22\x11", 6); } else if (memcmp(router_mac, "\0\0\0\0\0\0", 6) == 0) { unsigned router_ipv4; int err; unsigned router_ipv4 = masscan->nic[index].router_ip; int err = 0; LOG(1, "rawsock: looking for default gateway\n"); if (router_ipv4 == 0) err = rawsock_get_default_gateway(ifname, &router_ipv4); if (err == 0) { LOG(2, "auto-detected: router-ip=%u.%u.%u.%u\n", Loading src/main-status.c +52 −12 Original line number Diff line number Diff line Loading @@ -27,13 +27,23 @@ status_print( struct Status *status, uint64_t count, uint64_t max_count, double x) double x, uint64_t total_tcbs, uint64_t total_synacks, uint64_t total_syns) { double elapsed_time; double rate; double now; double percent_done; double time_remaining; uint64_t current_tcbs = 0; uint64_t current_synacks = 0; uint64_t current_syns = 0; double tcb_rate = 0.0; double synack_rate = 0.0; double syn_rate = 0.0; /* * #### FUGGLY TIME HACK #### Loading Loading @@ -79,8 +89,8 @@ status_print( + status->last_rates[7] ; rate /= 8; if (rate == 0) return; /*if (rate == 0) return;*/ /* * Calculate "percent-done", which is just the total number of Loading @@ -94,20 +104,50 @@ status_print( */ time_remaining = (1.0 - percent_done/100.0) * (max_count / rate); /* * some other stats */ if (total_tcbs) { current_tcbs = total_tcbs - status->total_tcbs; status->total_tcbs = total_tcbs; tcb_rate = (1.0*current_tcbs)/elapsed_time; } if (total_synacks) { current_synacks = total_synacks - status->total_synacks; status->total_synacks = total_synacks; synack_rate = (1.0*current_synacks)/elapsed_time; } if (total_syns) { current_syns = total_syns - status->total_syns; status->total_syns = total_syns; syn_rate = (1.0*current_syns)/elapsed_time; } /* * Print the message to <stderr> so that <stdout> can be redirected * to a file (<stdout> reports what systems were found). */ fprintf(stderr, "rate:%6.2f-kpps, %5.2f%% done,%4u:%02u:%02u remaining, %llu-tcbs, \r", if (status->is_infinite) { fprintf(stderr, "rate:%6.2f-kpps, syn/s=%.0f ack/s=%.0f tcb-rate=%.0f, %llu-tcbs, \r", x/1000.0, syn_rate, synack_rate, tcb_rate, global_tcb_count ); } else { fprintf(stderr, "rate:%6.2f-kpps, %5.2f%% done,%4u:%02u:%02u remaining, %llu-tcbs, rr=%.0f \r", x/1000.0, percent_done, (unsigned)(time_remaining/60/60), (unsigned)(time_remaining/60)%60, (unsigned)(time_remaining)%60, global_tcb_count //(unsigned)rate global_tcb_count, synack_rate ); } fflush(stderr); /* Loading src/main-status.h +7 −1 Original line number Diff line number Diff line Loading @@ -15,10 +15,16 @@ struct Status double last_rates[8]; unsigned last_count; unsigned is_infinite:1; uint64_t total_tcbs; uint64_t total_synacks; uint64_t total_syns; }; void status_print(struct Status *status, uint64_t count, uint64_t max_count, double x); void status_print(struct Status *status, uint64_t count, uint64_t max_count, double x, uint64_t total_tcbs, uint64_t total_synacks, uint64_t total_syns); void status_finish(struct Status *status); void status_start(struct Status *status); Loading Loading
src/main-conf.c +32 −1 Original line number Diff line number Diff line Loading @@ -149,6 +149,14 @@ masscan_echo_nic(struct Masscan *masscan, FILE *fp, unsigned i) masscan->nic[i].adapter_mac[3], masscan->nic[i].adapter_mac[4], masscan->nic[i].adapter_mac[5]); if (masscan->nic[i].router_ip) { fprintf(fp, "router-ip%s = %u.%u.%u.%u\n", zzz, (masscan->nic[i].router_ip>>24)&0xFF, (masscan->nic[i].router_ip>>16)&0xFF, (masscan->nic[i].router_ip>> 8)&0xFF, (masscan->nic[i].router_ip>> 0)&0xFF ); } else fprintf(fp, "router-mac%s = %02x:%02x:%02x:%02x:%02x:%02x\n", zzz, masscan->nic[i].router_mac[0], masscan->nic[i].router_mac[1], Loading Loading @@ -195,6 +203,7 @@ masscan_echo(struct Masscan *masscan, FILE *fp) case Output_XML: fprintf(fp, "output-format = xml\n"); break; case Output_Binary: fprintf(fp, "output-format = binary\n"); break; case Output_JSON: fprintf(fp, "output-format = json\n"); break; case Output_None: fprintf(fp, "output-format = none\n"); break; case Output_Redis: fprintf(fp, "output-format = redis\n"); fprintf(fp, "redis = %u.%u.%u.%u:%u\n", Loading Loading @@ -669,6 +678,22 @@ masscan_set_parameter(struct Masscan *masscan, memcpy(masscan->nic[index].router_mac, mac, 6); } else if (EQUALS("router-ip", name)) { /* Send packets FROM this IP address */ struct Range range; range = range_parse_ipv4(value, 0, 0); /* Check for bad format */ if (range.begin != range.end) { LOG(0, "FAIL: bad source IPv4 address: %s=%s\n", name, value); LOG(0, "hint addresses look like \"19.168.1.23\"\n"); exit(1); } masscan->nic[index].router_ip = range.begin; } else if (EQUALS("rate", name) || EQUALS("max-rate", name) ) { double rate = 0.0; double point = 10.0; Loading Loading @@ -849,6 +874,8 @@ masscan_set_parameter(struct Masscan *masscan, ranges_from_file(&masscan->targets, value); } else if (EQUALS("infinite", name)) { masscan->is_infinite = 1; } else if (EQUALS("interactive", name)) { masscan->is_interactive = 1; } else if (EQUALS("ip-options", name)) { fprintf(stderr, "nmap(%s): unsupported: maybe soon\n", name); exit(1); Loading Loading @@ -910,11 +937,13 @@ masscan_set_parameter(struct Masscan *masscan, fprintf(stderr, "nmap(%s): OS scanning unsupported\n", name); exit(1); } else if (EQUALS("output-format", name)) { masscan->is_interactive = 0; if (EQUALS("list", value)) masscan->nmap.format = Output_List; else if (EQUALS("interactive", value)) masscan->nmap.format = Output_Interactive; else if (EQUALS("xml", value)) masscan->nmap.format = Output_XML; else if (EQUALS("binary", value)) masscan->nmap.format = Output_Binary; else if (EQUALS("json", value)) masscan->nmap.format = Output_JSON; else if (EQUALS("none", value)) masscan->nmap.format = Output_None; else if (EQUALS("redis", value)) masscan->nmap.format = Output_Redis; else { fprintf(stderr, "error: %s=%s\n", name, value); Loading @@ -922,6 +951,7 @@ masscan_set_parameter(struct Masscan *masscan, } else if (EQUALS("output-filename", name) || EQUALS("output-file", name)) { if (masscan->nmap.format == 0) masscan->nmap.format = Output_XML; masscan->is_interactive = 0; strcpy_s(masscan->nmap.filename, sizeof(masscan->nmap.filename), value); } else if (EQUALS("pcap", name)) { strcpy_s(masscan->pcap_filename, sizeof(masscan->pcap_filename), value); Loading Loading @@ -1111,7 +1141,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", "infinite", "arp", "infinite", "interactive", 0}; size_t i; Loading Loading @@ -1301,6 +1331,7 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) /* Do nothing: this code never does DNS lookups anyway */ break; case 'o': /* nmap output format */ masscan->is_interactive = 0; switch (argv[i][2]) { case 'A': masscan->nmap.format = Output_All; Loading
src/main-dedup.c +26 −15 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ struct DedupEntry { unsigned ip; unsigned port; unsigned ip_them; unsigned port_them; unsigned ip_me; unsigned port_me; }; struct DedupTable { Loading Loading @@ -51,7 +53,7 @@ dedup_destroy(struct DedupTable *table) /*************************************************************************** ***************************************************************************/ unsigned dedup_is_duplicate(struct DedupTable *dedup, unsigned ip, unsigned port) dedup_is_duplicate(struct DedupTable *dedup, unsigned ip_them, unsigned port_them, unsigned ip_me, unsigned port_me) { unsigned hash; struct DedupEntry *bucket; Loading @@ -59,24 +61,31 @@ dedup_is_duplicate(struct DedupTable *dedup, unsigned ip, unsigned port) /* THREAT: probably need to secure this hash, though the syn-cookies * provides some protection */ hash = (ip + port) ^ ((ip>>8) + (ip>>16)) ^ (ip>>24); hash = (ip_them + port_them) ^ ((ip_me) + (ip_them>>16)) ^ (ip_them>>24) ^ port_me; hash &= DEDUP_ENTRIES-1; /* Search in this bucket */ bucket = dedup->entries[hash]; for (i = 0; i < 4; i++) { if (bucket[i].ip == ip && bucket[i].port == port) { if (bucket[i].ip_them == ip_them && bucket[i].port_them == port_them && bucket[i].ip_me == ip_me && bucket[i].port_me == port_me) { /* move to end of list so constant repeats get ignored */ if (i > 0) { bucket[i].ip ^= bucket[0].ip; bucket[i].port ^= bucket[0].port; bucket[0].ip ^= bucket[i].ip; bucket[0].port ^= bucket[i].port; bucket[i].ip ^= bucket[0].ip; bucket[i].port ^= bucket[0].port; bucket[i].ip_them ^= bucket[0].ip_them; bucket[i].port_them ^= bucket[0].port_them; bucket[i].ip_me ^= bucket[0].ip_me; bucket[i].port_me ^= bucket[0].port_me; bucket[0].ip_them ^= bucket[i].ip_them; bucket[0].port_them ^= bucket[i].port_them; bucket[0].ip_me ^= bucket[i].ip_me; bucket[0].port_me ^= bucket[i].port_me; bucket[i].ip_them ^= bucket[0].ip_them; bucket[i].port_them ^= bucket[0].port_them; bucket[i].ip_me ^= bucket[0].ip_me; bucket[i].port_me ^= bucket[0].port_me; } return 1; } Loading @@ -85,8 +94,10 @@ dedup_is_duplicate(struct DedupTable *dedup, unsigned ip, unsigned port) /* We didn't find it, so add it to our list. This will push * older entries at this bucket off the list */ memmove(bucket, bucket+1, 3*sizeof(*bucket)); bucket[0].ip = ip; bucket[0].port = port; bucket[0].ip_them = ip_them; bucket[0].port_them = port_them; bucket[0].ip_me = ip_me; bucket[0].port_me = port_me; return 0; }
src/main-initadapter.c +4 −3 Original line number Diff line number Diff line Loading @@ -141,11 +141,12 @@ masscan_initialize_adapter( if (masscan->is_offline) { memcpy(router_mac, "\x66\x55\x44\x33\x22\x11", 6); } else if (memcmp(router_mac, "\0\0\0\0\0\0", 6) == 0) { unsigned router_ipv4; int err; unsigned router_ipv4 = masscan->nic[index].router_ip; int err = 0; LOG(1, "rawsock: looking for default gateway\n"); if (router_ipv4 == 0) err = rawsock_get_default_gateway(ifname, &router_ipv4); if (err == 0) { LOG(2, "auto-detected: router-ip=%u.%u.%u.%u\n", Loading
src/main-status.c +52 −12 Original line number Diff line number Diff line Loading @@ -27,13 +27,23 @@ status_print( struct Status *status, uint64_t count, uint64_t max_count, double x) double x, uint64_t total_tcbs, uint64_t total_synacks, uint64_t total_syns) { double elapsed_time; double rate; double now; double percent_done; double time_remaining; uint64_t current_tcbs = 0; uint64_t current_synacks = 0; uint64_t current_syns = 0; double tcb_rate = 0.0; double synack_rate = 0.0; double syn_rate = 0.0; /* * #### FUGGLY TIME HACK #### Loading Loading @@ -79,8 +89,8 @@ status_print( + status->last_rates[7] ; rate /= 8; if (rate == 0) return; /*if (rate == 0) return;*/ /* * Calculate "percent-done", which is just the total number of Loading @@ -94,20 +104,50 @@ status_print( */ time_remaining = (1.0 - percent_done/100.0) * (max_count / rate); /* * some other stats */ if (total_tcbs) { current_tcbs = total_tcbs - status->total_tcbs; status->total_tcbs = total_tcbs; tcb_rate = (1.0*current_tcbs)/elapsed_time; } if (total_synacks) { current_synacks = total_synacks - status->total_synacks; status->total_synacks = total_synacks; synack_rate = (1.0*current_synacks)/elapsed_time; } if (total_syns) { current_syns = total_syns - status->total_syns; status->total_syns = total_syns; syn_rate = (1.0*current_syns)/elapsed_time; } /* * Print the message to <stderr> so that <stdout> can be redirected * to a file (<stdout> reports what systems were found). */ fprintf(stderr, "rate:%6.2f-kpps, %5.2f%% done,%4u:%02u:%02u remaining, %llu-tcbs, \r", if (status->is_infinite) { fprintf(stderr, "rate:%6.2f-kpps, syn/s=%.0f ack/s=%.0f tcb-rate=%.0f, %llu-tcbs, \r", x/1000.0, syn_rate, synack_rate, tcb_rate, global_tcb_count ); } else { fprintf(stderr, "rate:%6.2f-kpps, %5.2f%% done,%4u:%02u:%02u remaining, %llu-tcbs, rr=%.0f \r", x/1000.0, percent_done, (unsigned)(time_remaining/60/60), (unsigned)(time_remaining/60)%60, (unsigned)(time_remaining)%60, global_tcb_count //(unsigned)rate global_tcb_count, synack_rate ); } fflush(stderr); /* Loading
src/main-status.h +7 −1 Original line number Diff line number Diff line Loading @@ -15,10 +15,16 @@ struct Status double last_rates[8]; unsigned last_count; unsigned is_infinite:1; uint64_t total_tcbs; uint64_t total_synacks; uint64_t total_syns; }; void status_print(struct Status *status, uint64_t count, uint64_t max_count, double x); void status_print(struct Status *status, uint64_t count, uint64_t max_count, double x, uint64_t total_tcbs, uint64_t total_synacks, uint64_t total_syns); void status_finish(struct Status *status); void status_start(struct Status *status); Loading