From c25165def21e86dc8059bd7f7133c892fea8454f Mon Sep 17 00:00:00 2001 From: david Date: Mon, 21 Dec 2009 20:24:45 +0000 Subject: [PATCH] Add a default timeout of 5000 ms to the ntp-info script, and don't try sending the second probe if the first caused an error. This is based on the results of a test by Richard Sammet showing that the default timeout of 30 s is too long when scanning many open|filtered ports that are in fact filtered. --- scripts/ntp-info.nse | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/ntp-info.nse b/scripts/ntp-info.nse index 1b03e8fd6..80b34fa50 100644 --- a/scripts/ntp-info.nse +++ b/scripts/ntp-info.nse @@ -38,6 +38,10 @@ require "shortport" portrule = shortport.port_or_service(123, "ntp", {"udp", "tcp"}) +-- This script run against open|filtered ports, so don't wait too long if +-- there's no response. +local TIMEOUT = 5000 + -- Transform an array into a table where the array's values all map to true. local function make_set(a) local i, v, result @@ -69,8 +73,11 @@ action = function(host, port) local rlreq = string.char(0x16, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) - status, buftres = comm.exchange(host, port, treq, {proto=port.protocol}) - if status then + status, buftres = comm.exchange(host, port, treq, {proto=port.protocol, timeout=TIMEOUT}) + if not status then + -- Don't try the second probe if this one didn't work. + return nil + else local _, sec, frac, tstamp _, sec, frac = bin.unpack(">II", buftres, 33) @@ -82,7 +89,7 @@ action = function(host, port) table.insert(output, string.format("receive time stamp: %s", os.date("%c", tstamp))) end - status, bufrlres = comm.exchange(host, port, rlreq, {proto=port.protocol}) + status, bufrlres = comm.exchange(host, port, rlreq, {proto=port.protocol, timeout=TIMEOUT}) if status then -- This only looks at the first fragment of what can possibly be several