Loading src/main-conf.c +12 −7 Original line number Diff line number Diff line Loading @@ -109,14 +109,14 @@ masscan_echo_nic(struct Masscan *masscan, FILE *fp, unsigned i) (masscan->nic[i].adapter_ip>> 8)&0xFF, (masscan->nic[i].adapter_ip>> 0)&0xFF ); fprintf(fp, "adapter-mac = %02x:%02x:%02x:%02x:%02x:%02x\n", zzz, fprintf(fp, "adapter-mac%s = %02x:%02x:%02x:%02x:%02x:%02x\n", zzz, masscan->nic[i].adapter_mac[0], masscan->nic[i].adapter_mac[1], masscan->nic[i].adapter_mac[2], masscan->nic[i].adapter_mac[3], masscan->nic[i].adapter_mac[4], masscan->nic[i].adapter_mac[5]); fprintf(fp, "router-mac = %02x:%02x:%02x:%02x:%02x:%02x\n", zzz, 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], masscan->nic[i].router_mac[2], Loading Loading @@ -617,6 +617,7 @@ masscan_set_parameter(struct Masscan *masscan, } else if (EQUALS("ports", name) || EQUALS("port", name)) { rangelist_parse_ports(&masscan->ports, value); if (masscan->op == 0) masscan->op = Operation_Scan; } else if (EQUALS("exclude-ports", name) || EQUALS("exclude-port", name)) { Loading Loading @@ -650,6 +651,7 @@ masscan_set_parameter(struct Masscan *masscan, else offset++; /* skip comma */ } if (masscan->op == 0) masscan->op = Operation_Scan; } else if ( Loading Loading @@ -679,6 +681,7 @@ masscan_set_parameter(struct Masscan *masscan, else offset++; /* skip comma */ } if (masscan->op == 0) masscan->op = Operation_Scan; } else if (EQUALS("append-output", name) || EQUALS("output-append", name)) { if (EQUALS("overwrite", name)) Loading Loading @@ -821,6 +824,8 @@ masscan_set_parameter(struct Masscan *masscan, masscan->resume.seed = parseInt(value); } else if (EQUALS("resume-index", name)) { masscan->resume.index = parseInt(value); } else if (EQUALS("resume-count", name)) { masscan->resume.count = parseInt(value); } else if (EQUALS("retries", name) || EQUALS("retry", name)) { unsigned x = strtoul(value, 0, 0); if (x >= 1000) { Loading Loading @@ -1230,8 +1235,8 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) fprintf(stderr, "nmap(%s): Zombie scans will never be supported\n", argv[i]); exit(1); case 'L': /* List Scan - simply list targets to scan */ fprintf(stderr, "nmap(%s): list scan unsupported\n", argv[i]); exit(1); masscan->op = Operation_ListScan; break; case 'M': fprintf(stderr, "nmap(%s): Maimon scan not yet supported\n", argv[i]); exit(1); Loading src/main-listscan.c 0 → 100644 +71 −0 Original line number Diff line number Diff line #include "masscan.h" #include "logger.h" #include "rand-blackrock.h" void main_listscan(struct Masscan *masscan) { uint64_t count_ips; uint64_t count_ports; uint64_t i; uint64_t range; uint64_t start; uint64_t end; struct BlackRock blackrock; unsigned r = masscan->retries + 1; unsigned increment = masscan->shard.of; count_ports = rangelist_count(&masscan->ports); if (count_ports == 0) rangelist_add_range(&masscan->ports, 80, 80); count_ports = rangelist_count(&masscan->ports); count_ips = rangelist_count(&masscan->targets); if (count_ips == 0) { LOG(0, "FAIL: target IP address list empty\n"); LOG(0, " [hint] try something like \"--range 10.0.0.0/8\"\n"); LOG(0, " [hint] try something like \"--range 192.168.0.100-192.168.0.200\"\n"); return; } range = count_ips * count_ports; blackrock_init(&blackrock, range, masscan->seed); start = masscan->resume.index + (masscan->shard.one-1); end = range; if (masscan->resume.count && end > start + masscan->resume.count) end = start + masscan->resume.count; end += masscan->retries * masscan->max_rate; for (i=start; i<end; ) { uint64_t xXx; unsigned ip; unsigned port; xXx = (i + (r--) * masscan->max_rate); while (xXx >= range) xXx -= range; xXx = blackrock_shuffle(&blackrock, xXx); ip = rangelist_pick(&masscan->targets, xXx % count_ips); port = rangelist_pick(&masscan->ports, xXx / count_ips); if (count_ports == 1) printf("%u.%u.%u.%u\n", (ip>>24)&0xFF, (ip>>16)&0xFF, (ip>>8)&0xFF, (ip>>0)&0xFF ); else printf("%u.%u.%u.%u:%u\n", (ip>>24)&0xFF, (ip>>16)&0xFF, (ip>>8)&0xFF, (ip>>0)&0xFF, port ); if (r == 0) { i += increment; /* <------ increment by 1 normally, more with shards/nics */ r = masscan->retries + 1; } } } No newline at end of file src/main.c +12 −4 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ unsigned control_c_pressed = 0; static unsigned control_c_pressed_again = 0; time_t global_now; static unsigned wait = 10; static unsigned global_wait = 10; uint64_t foo_timestamp = 0; uint64_t foo_count = 0; Loading Loading @@ -238,6 +238,8 @@ transmit_thread(void *v) /*aka. scanning_thread() */ * is essentially the same logic as shards. */ start = masscan->resume.index + (masscan->shard.one-1) + parms->nic_index; end = range; if (masscan->resume.count && end > start + masscan->resume.count) end = start + masscan->resume.count; end += retries * rate; Loading Loading @@ -702,7 +704,9 @@ static void control_c_handler(int x) { if (control_c_pressed == 0) { fprintf(stderr, "waiting %u seconds to exit... \n", wait); "waiting %u seconds to exit..." " \n", global_wait); fflush(stderr); control_c_pressed = 1+x; } else Loading Loading @@ -907,7 +911,6 @@ main_scan(struct Masscan *masscan) unsigned i; double rate = 0; min_index = UINT64_MAX; /* Find the minimum index of all the threads */ min_index = UINT64_MAX; Loading Loading @@ -1082,6 +1085,11 @@ int main(int argc, char *argv[]) */ return main_scan(masscan); case Operation_ListScan: /* Create a randomized list of IP addresses */ main_listscan(masscan); return 0; case Operation_List_Adapters: /* List the network adapters we might want to use for scanning */ rawsock_list_adapters(); Loading src/masscan.h +2 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,7 @@ struct Masscan struct { uint64_t seed; uint64_t index; uint64_t count; } resume; struct { Loading Loading @@ -172,6 +173,7 @@ void masscan_read_config_file(struct Masscan *masscan, const char *filename); void masscan_command_line(struct Masscan *masscan, int argc, char *argv[]); void masscan_usage(); void masscan_save_state(struct Masscan *masscan); void main_listscan(struct Masscan *masscan); int masscan_initialize_adapter( Loading src/output.c +1 −1 Original line number Diff line number Diff line Loading @@ -530,7 +530,7 @@ output_report_banner(struct Output *out, unsigned ip, unsigned port, length, px ); if (count < 80) fprintf(stdout, "%.*s\n", (size_t)(79-count), fprintf(stdout, "%.*s\n", (int)(79-count), " "); else fprintf(stdout, "\n"); Loading Loading
src/main-conf.c +12 −7 Original line number Diff line number Diff line Loading @@ -109,14 +109,14 @@ masscan_echo_nic(struct Masscan *masscan, FILE *fp, unsigned i) (masscan->nic[i].adapter_ip>> 8)&0xFF, (masscan->nic[i].adapter_ip>> 0)&0xFF ); fprintf(fp, "adapter-mac = %02x:%02x:%02x:%02x:%02x:%02x\n", zzz, fprintf(fp, "adapter-mac%s = %02x:%02x:%02x:%02x:%02x:%02x\n", zzz, masscan->nic[i].adapter_mac[0], masscan->nic[i].adapter_mac[1], masscan->nic[i].adapter_mac[2], masscan->nic[i].adapter_mac[3], masscan->nic[i].adapter_mac[4], masscan->nic[i].adapter_mac[5]); fprintf(fp, "router-mac = %02x:%02x:%02x:%02x:%02x:%02x\n", zzz, 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], masscan->nic[i].router_mac[2], Loading Loading @@ -617,6 +617,7 @@ masscan_set_parameter(struct Masscan *masscan, } else if (EQUALS("ports", name) || EQUALS("port", name)) { rangelist_parse_ports(&masscan->ports, value); if (masscan->op == 0) masscan->op = Operation_Scan; } else if (EQUALS("exclude-ports", name) || EQUALS("exclude-port", name)) { Loading Loading @@ -650,6 +651,7 @@ masscan_set_parameter(struct Masscan *masscan, else offset++; /* skip comma */ } if (masscan->op == 0) masscan->op = Operation_Scan; } else if ( Loading Loading @@ -679,6 +681,7 @@ masscan_set_parameter(struct Masscan *masscan, else offset++; /* skip comma */ } if (masscan->op == 0) masscan->op = Operation_Scan; } else if (EQUALS("append-output", name) || EQUALS("output-append", name)) { if (EQUALS("overwrite", name)) Loading Loading @@ -821,6 +824,8 @@ masscan_set_parameter(struct Masscan *masscan, masscan->resume.seed = parseInt(value); } else if (EQUALS("resume-index", name)) { masscan->resume.index = parseInt(value); } else if (EQUALS("resume-count", name)) { masscan->resume.count = parseInt(value); } else if (EQUALS("retries", name) || EQUALS("retry", name)) { unsigned x = strtoul(value, 0, 0); if (x >= 1000) { Loading Loading @@ -1230,8 +1235,8 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) fprintf(stderr, "nmap(%s): Zombie scans will never be supported\n", argv[i]); exit(1); case 'L': /* List Scan - simply list targets to scan */ fprintf(stderr, "nmap(%s): list scan unsupported\n", argv[i]); exit(1); masscan->op = Operation_ListScan; break; case 'M': fprintf(stderr, "nmap(%s): Maimon scan not yet supported\n", argv[i]); exit(1); Loading
src/main-listscan.c 0 → 100644 +71 −0 Original line number Diff line number Diff line #include "masscan.h" #include "logger.h" #include "rand-blackrock.h" void main_listscan(struct Masscan *masscan) { uint64_t count_ips; uint64_t count_ports; uint64_t i; uint64_t range; uint64_t start; uint64_t end; struct BlackRock blackrock; unsigned r = masscan->retries + 1; unsigned increment = masscan->shard.of; count_ports = rangelist_count(&masscan->ports); if (count_ports == 0) rangelist_add_range(&masscan->ports, 80, 80); count_ports = rangelist_count(&masscan->ports); count_ips = rangelist_count(&masscan->targets); if (count_ips == 0) { LOG(0, "FAIL: target IP address list empty\n"); LOG(0, " [hint] try something like \"--range 10.0.0.0/8\"\n"); LOG(0, " [hint] try something like \"--range 192.168.0.100-192.168.0.200\"\n"); return; } range = count_ips * count_ports; blackrock_init(&blackrock, range, masscan->seed); start = masscan->resume.index + (masscan->shard.one-1); end = range; if (masscan->resume.count && end > start + masscan->resume.count) end = start + masscan->resume.count; end += masscan->retries * masscan->max_rate; for (i=start; i<end; ) { uint64_t xXx; unsigned ip; unsigned port; xXx = (i + (r--) * masscan->max_rate); while (xXx >= range) xXx -= range; xXx = blackrock_shuffle(&blackrock, xXx); ip = rangelist_pick(&masscan->targets, xXx % count_ips); port = rangelist_pick(&masscan->ports, xXx / count_ips); if (count_ports == 1) printf("%u.%u.%u.%u\n", (ip>>24)&0xFF, (ip>>16)&0xFF, (ip>>8)&0xFF, (ip>>0)&0xFF ); else printf("%u.%u.%u.%u:%u\n", (ip>>24)&0xFF, (ip>>16)&0xFF, (ip>>8)&0xFF, (ip>>0)&0xFF, port ); if (r == 0) { i += increment; /* <------ increment by 1 normally, more with shards/nics */ r = masscan->retries + 1; } } } No newline at end of file
src/main.c +12 −4 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ unsigned control_c_pressed = 0; static unsigned control_c_pressed_again = 0; time_t global_now; static unsigned wait = 10; static unsigned global_wait = 10; uint64_t foo_timestamp = 0; uint64_t foo_count = 0; Loading Loading @@ -238,6 +238,8 @@ transmit_thread(void *v) /*aka. scanning_thread() */ * is essentially the same logic as shards. */ start = masscan->resume.index + (masscan->shard.one-1) + parms->nic_index; end = range; if (masscan->resume.count && end > start + masscan->resume.count) end = start + masscan->resume.count; end += retries * rate; Loading Loading @@ -702,7 +704,9 @@ static void control_c_handler(int x) { if (control_c_pressed == 0) { fprintf(stderr, "waiting %u seconds to exit... \n", wait); "waiting %u seconds to exit..." " \n", global_wait); fflush(stderr); control_c_pressed = 1+x; } else Loading Loading @@ -907,7 +911,6 @@ main_scan(struct Masscan *masscan) unsigned i; double rate = 0; min_index = UINT64_MAX; /* Find the minimum index of all the threads */ min_index = UINT64_MAX; Loading Loading @@ -1082,6 +1085,11 @@ int main(int argc, char *argv[]) */ return main_scan(masscan); case Operation_ListScan: /* Create a randomized list of IP addresses */ main_listscan(masscan); return 0; case Operation_List_Adapters: /* List the network adapters we might want to use for scanning */ rawsock_list_adapters(); Loading
src/masscan.h +2 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,7 @@ struct Masscan struct { uint64_t seed; uint64_t index; uint64_t count; } resume; struct { Loading Loading @@ -172,6 +173,7 @@ void masscan_read_config_file(struct Masscan *masscan, const char *filename); void masscan_command_line(struct Masscan *masscan, int argc, char *argv[]); void masscan_usage(); void masscan_save_state(struct Masscan *masscan); void main_listscan(struct Masscan *masscan); int masscan_initialize_adapter( Loading
src/output.c +1 −1 Original line number Diff line number Diff line Loading @@ -530,7 +530,7 @@ output_report_banner(struct Output *out, unsigned ip, unsigned port, length, px ); if (count < 80) fprintf(stdout, "%.*s\n", (size_t)(79-count), fprintf(stdout, "%.*s\n", (int)(79-count), " "); else fprintf(stdout, "\n"); Loading