From bf457ee12cad23290bd9b51ddb66e26227dd5da5 Mon Sep 17 00:00:00 2001 From: dmiller Date: Sat, 20 Sep 2014 05:40:46 +0000 Subject: [PATCH] Normalize some timeouts in scripts Added use of stdnse.parse_timespec for timeout args. Used comm.lua default timeouts in a couple cases. Corrected 2 cases of incorrect documentation ("Default 60" when the default was 30 seconds). --- scripts/acarsd-info.nse | 2 +- scripts/ganglia-info.nse | 22 ++++++---------------- scripts/mikrotik-routeros-brute.nse | 7 ++++--- scripts/qconn-exec.nse | 2 +- scripts/weblogic-t3-info.nse | 3 +-- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/scripts/acarsd-info.nse b/scripts/acarsd-info.nse index 0beecd7e0..0e39a93d8 100644 --- a/scripts/acarsd-info.nse +++ b/scripts/acarsd-info.nse @@ -52,7 +52,7 @@ action = function(host, port) local result = {} -- Set timeout - local timeout = tonumber(nmap.registry.args[SCRIPT_NAME .. '.timeout']) + local timeout = stdnse.parse_timespec(stdnse.get_script_args(SCRIPT_NAME .. ".timeout")) if not timeout or timeout < 0 then timeout = 10 end -- Set bytes diff --git a/scripts/ganglia-info.nse b/scripts/ganglia-info.nse index a29423f08..4e0b308cb 100644 --- a/scripts/ganglia-info.nse +++ b/scripts/ganglia-info.nse @@ -25,9 +25,7 @@ For more information about Ganglia, see: -- nmap --script ganglia-info --script-args ganglia-info.timeout=60,ganglia-info.bytes=1000000 -p -- -- @args ganglia-info.timeout --- Set the timeout in seconds. The default value is 60. --- This should be enough for a grid of more than 100 hosts at 200Kb/s. --- About 5KB-10KB of data is returned for each host in the cluster. +-- Set the timeout in seconds. The default value is 30. -- @args ganglia-info.bytes -- Set the number of bytes to retrieve. The default value is 1000000. -- This should be enough for a grid of more than 100 hosts. @@ -92,24 +90,16 @@ action = function( host, port ) local result = {} -- Set timeout - local timeout = nmap.registry.args[SCRIPT_NAME .. '.timeout'] - if not timeout then - timeout = 30 - else - tonumber(timeout) - end + local timeout = stdnse.parse_timespec(stdnse.get_script_args(SCRIPT_NAME .. '.timeout')) + timeout = timeout or 30 -- Set bytes - local bytes = nmap.registry.args[SCRIPT_NAME .. '.bytes'] - if not bytes then - bytes = 1000000 - else - tonumber(bytes) - end + local bytes = stdnse.get_script_args(SCRIPT_NAME .. '.bytes') + bytes = tonumber(bytes) or 1000000 -- Retrieve grid data in XML format over TCP stdnse.debug1("Connecting to %s:%s", host.targetname or host.ip, port.number) - local status, data = comm.get_banner(host, port, {timeout=timeout*1000,bytes=bytes}) + local status, data = comm.get_banner(host, port, {request_timeout=timeout*1000,bytes=bytes}) if not status then stdnse.debug1("Timeout exceeded for %s:%s (Timeout: %ss).", host.targetname or host.ip, port.number, timeout) return diff --git a/scripts/mikrotik-routeros-brute.nse b/scripts/mikrotik-routeros-brute.nse index ff9c64825..bdcf70bb2 100644 --- a/scripts/mikrotik-routeros-brute.nse +++ b/scripts/mikrotik-routeros-brute.nse @@ -27,10 +27,12 @@ license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"intrusive", "brute"} local shortport = require "shortport" -local comm = require "comm" +local bin = require "bin" local brute = require "brute" local creds = require "creds" +local nmap = require "nmap" local stdnse = require "stdnse" +local string = require "string" local openssl = stdnse.silent_require "openssl" portrule = shortport.portnumber(8728, "tcp") @@ -88,13 +90,12 @@ Driver = } action = function(host, port) - local result local thread_num = stdnse.get_script_args(SCRIPT_NAME..".threads") or 1 local options = {timeout = 5000} local bengine = brute.Engine:new(Driver, host, port, options) bengine:setMaxThreads(thread_num) bengine.options.script_name = SCRIPT_NAME - _, result = bengine:start() + local _, result = bengine:start() return result end diff --git a/scripts/qconn-exec.nse b/scripts/qconn-exec.nse index 7d632bc1e..4bc61a1ba 100644 --- a/scripts/qconn-exec.nse +++ b/scripts/qconn-exec.nse @@ -41,7 +41,7 @@ For more information about QNX QCONN, see: -- |_ http://metasploit.org/modules/exploit/unix/misc/qnx_qconn_exec -- -- @args qconn-exec.timeout --- Set the timeout in seconds. The default value is 60. +-- Set the timeout in seconds. The default value is 30. -- -- @args qconn-exec.bytes -- Set the number of bytes to retrieve. The default value is 1024. diff --git a/scripts/weblogic-t3-info.nse b/scripts/weblogic-t3-info.nse index ca5dac421..9c07f726d 100644 --- a/scripts/weblogic-t3-info.nse +++ b/scripts/weblogic-t3-info.nse @@ -17,8 +17,7 @@ end action = function(host, port) local status, result = comm.exchange(host, port, - "t3 12.1.2\nAS:2048\nHL:19\n\n", - {proto=port.protocol, timeout=5000}) + "t3 12.1.2\nAS:2048\nHL:19\n\n") if (not status) then return nil