From 37727147f67de894753106a451a27734264e3692 Mon Sep 17 00:00:00 2001 From: Robert David Graham <robert_david_graham@yahoo.com> Date: Tue, 6 Mar 2018 21:41:28 -0500 Subject: [PATCH] top ports --- src/main-conf.c | 17 +++++++++++++---- src/masscan.h | 7 +++++++ xcode4/masscan.xcodeproj/project.pbxproj | 4 ++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main-conf.c b/src/main-conf.c index 76805b8..b938926 100644 --- a/src/main-conf.c +++ b/src/main-conf.c @@ -893,7 +893,7 @@ ARRAY(const char *rhs) } static void -config_top_ports(struct RangeList *ports, unsigned n) +config_top_ports(struct Masscan *masscan, unsigned n) { unsigned i; static const unsigned short top_tcp_ports[] = { @@ -974,9 +974,16 @@ config_top_ports(struct RangeList *ports, unsigned n) 52848,52869,54045,54328,55055,55056,55555,55600,56737,56738,57294, 57797,58080,60020,60443,61532,61900,62078,63331,64623,64680,65000, 65129,65389}; + struct RangeList *ports = &masscan->ports; + if (masscan->scan_type.tcp) { for (i=0; i<n && i<sizeof(top_tcp_ports)/sizeof(top_tcp_ports[0]); i++) rangelist_add_range(ports, top_tcp_ports[i], top_tcp_ports[i]); + } + if (masscan->scan_type.udp) { + for (i=0; i<n && i<sizeof(top_tcp_ports)/sizeof(top_tcp_ports[0]); i++) + rangelist_add_range(ports, top_tcp_ports[i], top_tcp_ports[i]); + } } /*************************************************************************** @@ -1774,7 +1781,7 @@ masscan_set_parameter(struct Masscan *masscan, exit(1); } else if (EQUALS("top-ports", name)) { unsigned n = (unsigned)parseInt(value); - config_top_ports(&masscan->ports, n); + config_top_ports(masscan, n); } else if (EQUALS("traceroute", name)) { fprintf(stderr, "nmap(%s): unsupported\n", name); exit(1); @@ -2168,12 +2175,14 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) fprintf(stderr, "nmap(%s): IP proto scan not yet supported\n", argv[i]); exit(1); case 'S': /* TCP SYN scan - THIS IS WHAT WE DO! */ + masscan->scan_type.tcp = 1; break; case 'T': /* TCP connect scan */ fprintf(stderr, "nmap(%s): connect() is too synchronous for cool kids\n", argv[i]); fprintf(stderr, "WARNING: doing SYN scan anyway\n"); break; case 'U': /* UDP scan */ + masscan->scan_type.udp = 1; break; case 'V': fprintf(stderr, "nmap(%s): unlikely this will be supported\n", argv[i]); @@ -2187,8 +2196,8 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) case 'Y': break; case 'Z': - fprintf(stderr, "nmap(%s): SCTP scan not yet supported\n", argv[i]); - exit(1); + masscan->scan_type.sctp = 1; + break; default: fprintf(stderr, "nmap(%s): unsupported option\n", argv[i]); exit(1); diff --git a/src/masscan.h b/src/masscan.h index 124b812..234388e 100644 --- a/src/masscan.h +++ b/src/masscan.h @@ -95,6 +95,13 @@ struct Masscan * which can be other things, like "Operation_SelfTest" */ enum Operation op; + + struct { + unsigned tcp:1; + unsigned udp:1; + unsigned sctp:1; + unsigned ping:1; + } scan_type; /** * One or more network adapters that we'll use for scanning. Each adapter diff --git a/xcode4/masscan.xcodeproj/project.pbxproj b/xcode4/masscan.xcodeproj/project.pbxproj index 00f639d..23d14ae 100644 --- a/xcode4/masscan.xcodeproj/project.pbxproj +++ b/xcode4/masscan.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 11126597197A086B00DC5987 /* out-unicornscan.c in Sources */ = {isa = PBXBuildFile; fileRef = 11126596197A086B00DC5987 /* out-unicornscan.c */; }; + 112A871A1F9D8DF200D4D240 /* out-ndjson.c in Sources */ = {isa = PBXBuildFile; fileRef = 112A87191F9D8DF200D4D240 /* out-ndjson.c */; }; 11420DD319A2D47A00DB5BFE /* proto-vnc.c in Sources */ = {isa = PBXBuildFile; fileRef = 11420DD219A2D47A00DB5BFE /* proto-vnc.c */; }; 11420DD819A8160500DB5BFE /* proto-ftp.c in Sources */ = {isa = PBXBuildFile; fileRef = 11420DD719A8160500DB5BFE /* proto-ftp.c */; }; 11420DDB19A84A9F00DB5BFE /* proto-smtp.c in Sources */ = {isa = PBXBuildFile; fileRef = 11420DDA19A84A9E00DB5BFE /* proto-smtp.c */; }; @@ -106,6 +107,7 @@ /* Begin PBXFileReference section */ 11126596197A086B00DC5987 /* out-unicornscan.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "out-unicornscan.c"; sourceTree = "<group>"; }; + 112A87191F9D8DF200D4D240 /* out-ndjson.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "out-ndjson.c"; sourceTree = "<group>"; }; 113AD3B818208A1900D5E067 /* masscan-status.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "masscan-status.h"; sourceTree = "<group>"; }; 11420DD219A2D47A00DB5BFE /* proto-vnc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "proto-vnc.c"; sourceTree = "<group>"; }; 11420DD519A2D48C00DB5BFE /* proto-vnc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "proto-vnc.h"; sourceTree = "<group>"; }; @@ -357,6 +359,7 @@ 11B360C91F9016AD0020F3A3 /* out */ = { isa = PBXGroup; children = ( + 112A87191F9D8DF200D4D240 /* out-ndjson.c */, 11623F69191E0DB00075EEE6 /* out-certs.c */, 11A868081816F3A7008E00B8 /* in-binary.c */, 11A868091816F3A7008E00B8 /* in-binary.h */, @@ -627,6 +630,7 @@ 11BA29691890560C0064A759 /* script-ntp-monlist.c in Sources */, 11BA296B189060220064A759 /* proto-ntp.c in Sources */, 11B05EA618B9649F009C935E /* crypto-blackrock2.c in Sources */, + 112A871A1F9D8DF200D4D240 /* out-ndjson.c in Sources */, 11B05EA718B9649F009C935E /* main-readrange.c in Sources */, 11A50CAE191C128F006D5802 /* out-json.c in Sources */, 11623F6A191E0DB00075EEE6 /* out-certs.c in Sources */, -- GitLab