From ee6bc188448a1fb020ec9b44fddd0d03f51a0512 Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 6 Oct 2020 18:44:12 +0000 Subject: [PATCH] Only warn about protocol specs in port list with -p. Fixes #2135 --- nmap.cc | 30 ++++++++++++++++++++++++++++++ scan_lists.cc | 51 +++++++++++++++++++-------------------------------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/nmap.cc b/nmap.cc index c0f4a1e55..6e3e91e63 100644 --- a/nmap.cc +++ b/nmap.cc @@ -1534,6 +1534,36 @@ void apply_delayed_options() { else getpts((char *) (o.fastscan ? "[P:0-]" : "0-"), &ports); // Default protocols to scan } else if (!o.noportscan) { + if (o.portlist) { + for (const char *p=o.portlist; *p != '\0'; p++) { + if (*(p+1) == ':') { + switch(*p) { + case 'T': + if (!o.TCPScan()) { + error("WARNING: Your ports include \"T:\" but you haven't specified any TCP scan type."); + } + break; + case 'U': + if (!o.UDPScan()) { + error("WARNING: Your ports include \"U:\" but you haven't specified UDP scan with -sU."); + } + break; + case 'S': + if (!o.SCTPScan()) { + error("WARNING: Your ports include \"S:\" but you haven't specified any SCTP scan type."); + } + break; + case 'P': + if (!o.ipprotscan) { + error("WARNING: Your ports include \"P:\" but you haven't specified IP Protocol scan with -sO."); + } + break; + default: + break; + } + } + } + } gettoppts(o.topportlevel, o.portlist, &ports, o.exclude_portlist); } diff --git a/scan_lists.cc b/scan_lists.cc index d1e106c8a..f8621984a 100644 --- a/scan_lists.cc +++ b/scan_lists.cc @@ -337,39 +337,26 @@ static void getpts_aux(const char *origexpr, int nested, u8 *porttbl, int range_ while (isspace((int) (unsigned char) *current_range)) current_range++; /* I don't know why I should allow spaces here, but I will */ - if (change_range_type) { - if (*current_range == 'T' && *(current_range+1) == ':') { - current_range += 2; - range_type = SCAN_TCP_PORT; - if (!o.TCPScan()) { - error("WARNING: Your ports include \"T:\" but you haven't specified any TCP scan type."); - } - continue; - } - if (*current_range == 'U' && *(current_range+1) == ':') { - current_range += 2; - range_type = SCAN_UDP_PORT; - if (!o.UDPScan()) { - error("WARNING: Your ports include \"U:\" but you haven't specified UDP scan with -sU."); - } - continue; - } - if (*current_range == 'S' && *(current_range+1) == ':') { - current_range += 2; - range_type = SCAN_SCTP_PORT; - if (!o.SCTPScan()) { - error("WARNING: Your ports include \"S:\" but you haven't specified any SCTP scan type."); - } - continue; - } - if (*current_range == 'P' && *(current_range+1) == ':') { - current_range += 2; - range_type = SCAN_PROTOCOLS; - if (!o.ipprotscan) { - error("WARNING: Your ports include \"P:\" but you haven't specified IP Protocol scan with -sO."); - } - continue; + if (change_range_type && *(current_range+1) == ':') { + switch (*current_range) { + case 'T': + range_type = SCAN_TCP_PORT; + break; + case 'U': + range_type = SCAN_UDP_PORT; + break; + case 'S': + range_type = SCAN_SCTP_PORT; + break; + case 'P': + range_type = SCAN_PROTOCOLS; + break; + default: + fatal("Error parsing port list: Unknown protocol specifier '%c'.", *current_range); + break; } + current_range += 2; + continue; } if (*current_range == '[') {