From f5e32d305f227ab3dd62fa3ecab2cebb9a0e856d Mon Sep 17 00:00:00 2001 From: fyodor Date: Sat, 11 Aug 2007 03:24:04 +0000 Subject: [PATCH] merge soc07 r4780 - Moved OSScan warning message (may not be reliable because could not find 1 open and 1 closed port) so it is printed along with the OSScan results instead of above it --- CHANGELOG | 4 ++++ Target.cc | 14 +++++++++++++- Target.h | 12 +++++++++++- nse_nmaplib.cc | 2 +- osscan.cc | 4 ++-- osscan2.cc | 4 ++-- output.cc | 12 +++++++++--- 7 files changed, 42 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d18467e23..371be7fbb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ # Nmap Changelog ($Id$); -*-text-*- +o Relocated OSScan warning message (could not find 1 closed and 1 open + port). Now output.cc prints the warning along with a targets OSScan + results. [Eddie] + o Fixed a bug which caused port 0 to be improperly used for gen1 OS detection in some cases when your scan includes port 0 (it isn't included by default). Thanks to Sebastian Wolfgarten for the report diff --git a/Target.cc b/Target.cc index 435354b96..2a73cd575 100644 --- a/Target.cc +++ b/Target.cc @@ -122,7 +122,7 @@ void Target::Initialize() { distance = -1; FPR1 = NULL; FPR = NULL; - osscan_performed = 0; + osscan_flag = OS_NOTPERF; wierd_responses = flags = 0; memset(&to, 0, sizeof(to)); memset(&targetsock, 0, sizeof(targetsock)); @@ -443,3 +443,15 @@ const u8 *Target::SrcMACAddress() { const u8 *Target::NextHopMACAddress() { return (NextHopMACaddress_set)? NextHopMACaddress : NULL; } + +int Target::osscanPerformed(void) { + return osscan_flag; +} + +void Target::osscanSetFlag(int flag) { + if(osscan_flag == OS_PERF_UNREL) + return; + else + osscan_flag = flag; +} + diff --git a/Target.h b/Target.h index d2a334d1e..c2fb2394f 100644 --- a/Target.h +++ b/Target.h @@ -112,6 +112,10 @@ #define INET6_ADDRSTRLEN 46 #endif +enum osscan_flags { + OS_NOTPERF=0, OS_PERF, OS_PERF_UNREL +}; + struct host_timeout_nfo { unsigned long msecs_used; /* How many msecs has this Target used? */ bool toclock_running; /* Is the clock running right now? */ @@ -220,11 +224,13 @@ class Target { const char *deviceName(); const char *deviceFullName(); + int osscanPerformed(void); + void osscanSetFlag(int flag); + struct seq_info seq; int distance; FingerPrintResults *FPR1; /* FP results get by the old OS scan system. */ FingerPrintResults *FPR; /* FP results get by the new OS scan system. */ - int osscan_performed; /* nonzero if an osscan was performed */ PortList ports; // unsigned int up; @@ -253,6 +259,10 @@ class Target { devtype interface_type; char devname[32]; char devfullname[32]; + /* 0 (OS_NOTPERF) if os detection not performed + * 1 (OS_PERF) if os detection performed + * 2 (OS_PERF_UNREL) if an unreliable os detection has been performed */ + int osscan_flag; }; #endif /* TARGET_H */ diff --git a/nse_nmaplib.cc b/nse_nmaplib.cc index ce971353e..dd9b25f72 100644 --- a/nse_nmaplib.cc +++ b/nse_nmaplib.cc @@ -195,7 +195,7 @@ void set_hostinfo(lua_State* l, Target *currenths) { * result, we will use it in the scripts * matches which aren't perfect are not needed in the scripts */ - if( currenths->osscan_performed && + if( currenths->osscanPerformed() && FPR != NULL && FPR->overall_results == OSSCAN_SUCCESS && FPR->num_perfect_matches > 0 && diff --git a/osscan.cc b/osscan.cc index 1d8dd13be..c1c1bc9cd 100644 --- a/osscan.cc +++ b/osscan.cc @@ -560,7 +560,7 @@ static FingerPrint *get_fingerprint(Target *target, struct seq_info *si) { snprintf(filter, sizeof(filter), "dst host %s and (icmp or (tcp and src host %s))", inet_ntoa(target->v4source()), target->targetipstr()); set_pcap_filter(target->deviceName(), pd, filter); - target->osscan_performed = 1; /* Let Nmap know that we did try an OS scan */ + target->osscanSetFlag(OS_PERF); /* Let Nmap know that we did try an OS scan */ /* Lets find an open port to use */ openport = (unsigned long) -1; @@ -1506,7 +1506,7 @@ o.current_scantype = OS_SCAN; log_write(LOG_STDOUT|LOG_NORMAL|LOG_SKID, "Skipping OS Scan due to absence of open (or perhaps closed) ports\n"); return 1; } else { - log_write(LOG_STDOUT|LOG_NORMAL|LOG_SKID,"Warning: OS detection will be MUCH less reliable because we did not find at least 1 open and 1 closed TCP port\n"); + target->osscanSetFlag(OS_PERF_UNREL); } } diff --git a/osscan2.cc b/osscan2.cc index 0616ce844..4fd06f2b7 100644 --- a/osscan2.cc +++ b/osscan2.cc @@ -2852,7 +2852,7 @@ HostOsScanInfo::HostOsScanInfo(Target *t, OsScanInfo *OsSI) { if (target->FPR == NULL) target->FPR = new FingerPrintResults; - target->osscan_performed = 1; + target->osscanSetFlag(OS_PERF); hss = new HostOsScanStats(t); } @@ -2898,7 +2898,7 @@ OsScanInfo::OsScanInfo(vector &Targets) { log_write(LOG_STDOUT|LOG_NORMAL|LOG_SKID, "Skipping OS Scan against %s due to absence of open (or perhaps closed) ports\n", Targets[targetno]->NameIP()); continue; } else { - log_write(LOG_STDOUT|LOG_NORMAL|LOG_SKID,"Warning: OS detection for %s will be MUCH less reliable because we did not find at least 1 open and 1 closed TCP port\n", Targets[targetno]->targetipstr()); + Targets[targetno]->osscanSetFlag(OS_PERF_UNREL); } } diff --git a/output.cc b/output.cc index d7c7376e9..a64bb6abf 100644 --- a/output.cc +++ b/output.cc @@ -1337,10 +1337,11 @@ void printosscanoutput(Target *currenths) { FingerPrintResults *FPR; int osscanSys = 0; int distance = -1; + int osscan_flag; - if (!currenths->osscan_performed) + if (!(osscan_flag = currenths->osscanPerformed())) return; - + if (currenths->FPR == NULL && currenths->FPR1 == NULL) { return; } else if (currenths->FPR != NULL && currenths->FPR1 == NULL) { @@ -1387,7 +1388,12 @@ void printosscanoutput(Target *currenths) { "\n", FPR->osscan_closedudpport); } - + + if(osscan_flag == OS_PERF_UNREL && + !(FPR->overall_results == OSSCAN_TOOMANYMATCHES || + (FPR->num_perfect_matches > 8 && !o.debugging))) + log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port\n"); + // If the FP can't be submitted anyway, might as well make a guess. const char *reason = FPR->OmitSubmissionFP(); printosclassificationoutput(FPR->getOSClassification(),