Nmap Development mailing list archives

[NSE][PATCH] dns.lua timeout based on nmap.timing_level()


From: jah <jah () zadkiel plus com>
Date: Sun, 07 Sep 2008 05:40:04 +0100

Hi,

The attached changes the socket timeout used in dns.sendPackets which is
currently a very long 10 seconds to use values based on nmap timing
templates.  The times used would be 10 seconds for T0, 7s, 5s, 3s and 2s
for T4 and T5.
It also adds the ability to specify timeout in the options table passed
to dns.query().

Regards,

jah

--- dns.lua.orig        2008-09-06 05:05:52.343750000 +0100
+++ dns.lua     2008-09-07 05:29:51.625000000 +0100
@@ -38,11 +38,12 @@
 --@param data Data to be sent
 --@param host Host to connect to
 --@param port Port to connect to
+--@param timeout Number of ms to wait for a response.
 --@param cnt Number of tries
 --@return success as boolean and response if available
-local function sendPackets(data, host, port, cnt)
+local function sendPackets(data, host, port, timeout, cnt)
    local socket = nmap.new_socket()
-   socket:set_timeout(10000)
+   socket:set_timeout(timeout)
    socket:connect(host, port, "udp")
 
    for i = 1, cnt do 
@@ -142,6 +143,8 @@
    if not tries then tries = 10 end -- don't get into an infinite loop
 
    if not options.sendCount then options.sendCount = 2 end
+   
+   if type( options.timeout ) ~= "number" then options.timeout = get_default_timeout() end
 
    if type(dtype) == "string" then
       dtype = types[dtype]
@@ -174,7 +177,7 @@
 
    local data = encode(pkt)
 
-   local status, response = sendPackets(data, host, port, options.sendCount)
+   local status, response = sendPackets(data, host, port, options.timeout, options.sendCount)
 
 
    -- if working with know nameservers, try the others
@@ -714,3 +717,9 @@
    return pkt
 end
 
+
+get_default_timeout = function()
+  local timeout = {[0] = 10000, 7000, 5000, 3000, 2000, 2000}
+  return timeout[nmap.timing_level()] or 3000
+end
+

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org

Current thread: