--- a/service_scan.cc +++ b/service_scan.cc @@ -218,6 +218,9 @@ // when SSL is detected -- we redo all probes through SSL. If freeFP, any // service fingerprint is freed too. void resetProbes(bool freefp); + // Number of milliseconds used so far to complete the present probe. Timeval + // can omitted, it is just there as an optimization in case you have it handy. + int probe_timemsused(const ServiceProbe *probe, const struct timeval *now = NULL); // Number of milliseconds left to complete the present probe, or 0 if // the probe is already expired. Timeval can omitted, it is just there // as an optimization in case you have it handy. @@ -1816,9 +1819,8 @@ probe_state = PROBESTATE_INITIAL; } - -int ServiceNFO::probe_timemsleft(const ServiceProbe *probe, const struct timeval *now) { - int timeused, timeleft; +int ServiceNFO::probe_timemsused(const ServiceProbe *probe, const struct timeval *now) { + int timeused; if (now) timeused = TIMEVAL_MSEC_SUBTRACT(*now, currentprobe_exec_time); @@ -1832,7 +1834,16 @@ // probe == currentProbe(). Check that this remains the case. assert(probe == currentProbe()); - timeleft = probe->totalwaitms - timeused; + return timeused; +} + +int ServiceNFO::probe_timemsleft(const ServiceProbe *probe, const struct timeval *now) { + + // Historically this function was always called with the assumption that + // probe == currentProbe(). Check that this remains the case. + assert(probe == currentProbe()); + + int timeleft = probe->totalwaitms - probe_timemsused(probe, now); return (timeleft < 0)? 0 : timeleft; } @@ -2480,7 +2491,7 @@ if (readstrlen > 0) svc->addToServiceFingerprint(svc->currentProbe()->getName(), readstr, readstrlen); - if (probe->isNullProbe() && readstrlen == 0) { + if (probe->isNullProbe() && readstrlen == 0 && svc->probe_timemsused(probe) < TCPWRAPPED_TIMEOUT) { // TODO: Perhaps should do further verification before making this assumption end_svcprobe(nsp, PROBESTATE_FINISHED_TCPWRAPPED, SG, svc, nsi); } else { @@ -2498,7 +2509,7 @@ // BSD sometimes gives it case ECONNABORTED: // Jerk hung up on us. Probably didn't like our probe. We treat it as with EOF above. - if (probe->isNullProbe()) { + if (probe->isNullProbe() && svc->probe_timemsused(probe) < TCPWRAPPED_TIMEOUT) { // TODO: Perhaps should do further verification before making this assumption end_svcprobe(nsp, PROBESTATE_FINISHED_TCPWRAPPED, SG, svc, nsi); } else { --- a/service_scan.h +++ b/service_scan.h @@ -146,6 +146,7 @@ #define SERVICEMATCH_REGEX 1 // #define SERVICEMATCH_STATIC 2 -- no longer supported +#define TCPWRAPPED_TIMEOUT 2000 // connections closed after this timeout are not considered "tcpwrapped" /********************** STRUCTURES ***********************************/ // This is returned when we find a match