Loading src/main-conf.c +8 −3 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ masscan_echo(struct Masscan *masscan, FILE *fp) fprintf(fp, "rate = %10.2f\n", masscan->max_rate); fprintf(fp, "randomize-hosts = true\n"); fprintf(fp, "seed = %llu\n", masscan->seed); fprintf(fp, "# ADAPTER SETTINGS\n"); Loading Loading @@ -145,7 +146,7 @@ masscan_echo(struct Masscan *masscan, FILE *fp) fprintf(fp, "rotate = %u\n", masscan->rotate_output); fprintf(fp, "rotate-dir = %s\n", masscan->rotate_directory); fprintf(fp, "rotate-offset = %u\n", masscan->rotate_offset); fprintf(fp, "pcap = %s\n", masscan->pcap_filename); /* * Targets Loading Loading @@ -628,6 +629,8 @@ masscan_set_parameter(struct Masscan *masscan, const char *name, const char *val } } else if (EQUALS("output-filename", name)) { 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); } else if (EQUALS("packet-trace", name) || EQUALS("trace-packet", name)) { masscan->nmap.packet_trace = 1; } else if (EQUALS("privileged", name) || EQUALS("unprivileged", name)) { Loading @@ -635,8 +638,6 @@ masscan_set_parameter(struct Masscan *masscan, const char *name, const char *val exit(1); } else if (EQUALS("pfring", name)) { masscan->is_pfring = 1; } else if (EQUALS("sendq", name)) { masscan->is_sendq = 1; } else if (EQUALS("port-ratio", name)) { fprintf(stderr, "nmap(%s): unsupported\n", name); exit(1); Loading Loading @@ -758,6 +759,10 @@ masscan_set_parameter(struct Masscan *masscan, const char *name, const char *val } else if (EQUALS("scanflags", name)) { fprintf(stderr, "nmap(%s): TCP scan flags not yet supported\n", name); exit(1); } else if (EQUALS("seed", name)) { masscan->seed = parseInt(value); } else if (EQUALS("sendq", name)) { masscan->is_sendq = 1; } else if (EQUALS("send-eth", name)) { fprintf(stderr, "nmap(%s): unnecessary, we always do --send-eth\n", name); } else if (EQUALS("send-ip", name)) { Loading src/main.c +30 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include "output.h" /* for outputing results */ //#include "xring.h" /* producer/consumer ring buffer */ #include "rte-ring.h" /* producer/consumer ring buffer */ #include "rawsock-pcapfile.h" /* for saving pcap files w/ raw packets */ #include "pixie-timer.h" /* portable time functions */ #include "pixie-threads.h" /* portable threads */ Loading Loading @@ -177,7 +178,7 @@ transmit_thread(void *v) /*aka. scanning_thread() */ for (j=0; j<masscan->wait && !control_c_pressed; j++) { unsigned k; status_print(&status, i++, m); for (k=0; k<100; k++) { for (k=0; k<1000; k++) { for (;;) { unsigned char *p; int err; Loading Loading @@ -209,6 +210,16 @@ receive_thread(struct Masscan *masscan, { struct Output *out; struct DedupTable *dedup; struct PcapFile *pcapfile = NULL; /* * If configured, open a pcap file for saving raw packets. This is * so that we can debug scans, but also so that we can look at the * strange things people send us. Note that we don't record transmitted * packets, just the packets we've received. */ if (masscan->pcap_filename) pcapfile = pcapfile_openwrite(masscan->pcap_filename, 1); /* * Open output. This is where results are reported. Loading @@ -216,7 +227,8 @@ receive_thread(struct Masscan *masscan, out = output_create(masscan); /* * Create deduplication table * Create deduplication table. This is so when somebody sends us * multiple responses, we only record the first one. */ dedup = dedup_create(); Loading Loading @@ -269,6 +281,18 @@ receive_thread(struct Masscan *masscan, if (adapter_ip != dst) continue; /* Save raw packet (if configured to do so) */ if (pcapfile) { pcapfile_writeframe( pcapfile, px, length, length, secs, usecs); } /* OOPS: handle arp instead */ if (parsed.found == FOUND_ARP) { LOG(2, "found arp 0x%08x\n", parsed.ip_dst); Loading Loading @@ -321,6 +345,7 @@ receive_thread(struct Masscan *masscan, ); } LOG(1, "end receive thread\n"); /* Loading @@ -328,6 +353,8 @@ receive_thread(struct Masscan *masscan, */ dedup_destroy(dedup); output_destroy(out); if (pcapfile) pcapfile_close(pcapfile); } /*************************************************************************** Loading Loading @@ -529,7 +556,7 @@ int main(int argc, char *argv[]) rawsock_init(); /* Set randomization seed for SYN-cookies */ syn_set_entropy(); syn_set_entropy(masscan->seed); /* * Apply excludes. People ask us not to scan them, so we maintain a list Loading src/masscan.h +7 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,12 @@ struct Masscan */ unsigned rotate_output; /** * A random seed for randomization if zero, otherwise we'll use * the configured seed for repeatable tests. */ uint64_t seed; /** * When doing "--rotate daily", the rotation is done at GMT. In order * to fix this, add an offset. Loading @@ -146,6 +152,7 @@ struct Masscan } nmap; char rotate_directory[256]; char pcap_filename[256]; struct rte_ring *packet_buffers; struct rte_ring *pending_packets; Loading src/output.c +17 −13 Original line number Diff line number Diff line Loading @@ -253,19 +253,6 @@ output_create(struct Masscan *masscan) return out; } /*************************************************************************** ***************************************************************************/ void output_destroy(struct Output *out) { if (out == NULL) return; if (out->fp) close_rotate(out, out->fp); free(out); } /*************************************************************************** ***************************************************************************/ static const char * Loading Loading @@ -506,3 +493,20 @@ output_report(struct Output *out, int status, unsigned ip, unsigned port, unsign } /*************************************************************************** ***************************************************************************/ void output_destroy(struct Output *out) { if (out == NULL) return; if (out->period) output_do_rotate(out); /*TODO: this leaves an empty file behind */ if (out->fp) close_rotate(out, out->fp); free(out); } src/output.h +1 −0 Original line number Diff line number Diff line Loading @@ -8,4 +8,5 @@ void output_destroy(struct Output *output); void output_report(struct Output *output, int status, unsigned ip, unsigned port, unsigned reason, unsigned ttl); #endif Loading
src/main-conf.c +8 −3 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ masscan_echo(struct Masscan *masscan, FILE *fp) fprintf(fp, "rate = %10.2f\n", masscan->max_rate); fprintf(fp, "randomize-hosts = true\n"); fprintf(fp, "seed = %llu\n", masscan->seed); fprintf(fp, "# ADAPTER SETTINGS\n"); Loading Loading @@ -145,7 +146,7 @@ masscan_echo(struct Masscan *masscan, FILE *fp) fprintf(fp, "rotate = %u\n", masscan->rotate_output); fprintf(fp, "rotate-dir = %s\n", masscan->rotate_directory); fprintf(fp, "rotate-offset = %u\n", masscan->rotate_offset); fprintf(fp, "pcap = %s\n", masscan->pcap_filename); /* * Targets Loading Loading @@ -628,6 +629,8 @@ masscan_set_parameter(struct Masscan *masscan, const char *name, const char *val } } else if (EQUALS("output-filename", name)) { 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); } else if (EQUALS("packet-trace", name) || EQUALS("trace-packet", name)) { masscan->nmap.packet_trace = 1; } else if (EQUALS("privileged", name) || EQUALS("unprivileged", name)) { Loading @@ -635,8 +638,6 @@ masscan_set_parameter(struct Masscan *masscan, const char *name, const char *val exit(1); } else if (EQUALS("pfring", name)) { masscan->is_pfring = 1; } else if (EQUALS("sendq", name)) { masscan->is_sendq = 1; } else if (EQUALS("port-ratio", name)) { fprintf(stderr, "nmap(%s): unsupported\n", name); exit(1); Loading Loading @@ -758,6 +759,10 @@ masscan_set_parameter(struct Masscan *masscan, const char *name, const char *val } else if (EQUALS("scanflags", name)) { fprintf(stderr, "nmap(%s): TCP scan flags not yet supported\n", name); exit(1); } else if (EQUALS("seed", name)) { masscan->seed = parseInt(value); } else if (EQUALS("sendq", name)) { masscan->is_sendq = 1; } else if (EQUALS("send-eth", name)) { fprintf(stderr, "nmap(%s): unnecessary, we always do --send-eth\n", name); } else if (EQUALS("send-ip", name)) { Loading
src/main.c +30 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include "output.h" /* for outputing results */ //#include "xring.h" /* producer/consumer ring buffer */ #include "rte-ring.h" /* producer/consumer ring buffer */ #include "rawsock-pcapfile.h" /* for saving pcap files w/ raw packets */ #include "pixie-timer.h" /* portable time functions */ #include "pixie-threads.h" /* portable threads */ Loading Loading @@ -177,7 +178,7 @@ transmit_thread(void *v) /*aka. scanning_thread() */ for (j=0; j<masscan->wait && !control_c_pressed; j++) { unsigned k; status_print(&status, i++, m); for (k=0; k<100; k++) { for (k=0; k<1000; k++) { for (;;) { unsigned char *p; int err; Loading Loading @@ -209,6 +210,16 @@ receive_thread(struct Masscan *masscan, { struct Output *out; struct DedupTable *dedup; struct PcapFile *pcapfile = NULL; /* * If configured, open a pcap file for saving raw packets. This is * so that we can debug scans, but also so that we can look at the * strange things people send us. Note that we don't record transmitted * packets, just the packets we've received. */ if (masscan->pcap_filename) pcapfile = pcapfile_openwrite(masscan->pcap_filename, 1); /* * Open output. This is where results are reported. Loading @@ -216,7 +227,8 @@ receive_thread(struct Masscan *masscan, out = output_create(masscan); /* * Create deduplication table * Create deduplication table. This is so when somebody sends us * multiple responses, we only record the first one. */ dedup = dedup_create(); Loading Loading @@ -269,6 +281,18 @@ receive_thread(struct Masscan *masscan, if (adapter_ip != dst) continue; /* Save raw packet (if configured to do so) */ if (pcapfile) { pcapfile_writeframe( pcapfile, px, length, length, secs, usecs); } /* OOPS: handle arp instead */ if (parsed.found == FOUND_ARP) { LOG(2, "found arp 0x%08x\n", parsed.ip_dst); Loading Loading @@ -321,6 +345,7 @@ receive_thread(struct Masscan *masscan, ); } LOG(1, "end receive thread\n"); /* Loading @@ -328,6 +353,8 @@ receive_thread(struct Masscan *masscan, */ dedup_destroy(dedup); output_destroy(out); if (pcapfile) pcapfile_close(pcapfile); } /*************************************************************************** Loading Loading @@ -529,7 +556,7 @@ int main(int argc, char *argv[]) rawsock_init(); /* Set randomization seed for SYN-cookies */ syn_set_entropy(); syn_set_entropy(masscan->seed); /* * Apply excludes. People ask us not to scan them, so we maintain a list Loading
src/masscan.h +7 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,12 @@ struct Masscan */ unsigned rotate_output; /** * A random seed for randomization if zero, otherwise we'll use * the configured seed for repeatable tests. */ uint64_t seed; /** * When doing "--rotate daily", the rotation is done at GMT. In order * to fix this, add an offset. Loading @@ -146,6 +152,7 @@ struct Masscan } nmap; char rotate_directory[256]; char pcap_filename[256]; struct rte_ring *packet_buffers; struct rte_ring *pending_packets; Loading
src/output.c +17 −13 Original line number Diff line number Diff line Loading @@ -253,19 +253,6 @@ output_create(struct Masscan *masscan) return out; } /*************************************************************************** ***************************************************************************/ void output_destroy(struct Output *out) { if (out == NULL) return; if (out->fp) close_rotate(out, out->fp); free(out); } /*************************************************************************** ***************************************************************************/ static const char * Loading Loading @@ -506,3 +493,20 @@ output_report(struct Output *out, int status, unsigned ip, unsigned port, unsign } /*************************************************************************** ***************************************************************************/ void output_destroy(struct Output *out) { if (out == NULL) return; if (out->period) output_do_rotate(out); /*TODO: this leaves an empty file behind */ if (out->fp) close_rotate(out, out->fp); free(out); }
src/output.h +1 −0 Original line number Diff line number Diff line Loading @@ -8,4 +8,5 @@ void output_destroy(struct Output *output); void output_report(struct Output *output, int status, unsigned ip, unsigned port, unsigned reason, unsigned ttl); #endif