diff --git a/CHANGELOG b/CHANGELOG index 1bfed4f14..7127b36f1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ # Nmap Changelog ($Id$); -*-text-*- +o Update the HTTP library to use the new timing_level functionality to + set connection and response timeouts. An error preventing the new + timing_level feature from working was also fixed. [Jah] + o Added a new timing_level() function to NSE which reports the Nmap timing level from 0 to 5, as set by the Nmap -T option. The default is 3. [Thomas Buchanan] diff --git a/nse_nmaplib.cc b/nse_nmaplib.cc index e2e45719b..979181322 100644 --- a/nse_nmaplib.cc +++ b/nse_nmaplib.cc @@ -99,6 +99,7 @@ int luaopen_nmap (lua_State *L) {"debugging", l_get_debugging}, {"have_ssl", l_get_have_ssl}, {"fetchfile", l_fetchfile}, + {"timing_level", l_get_timing_level}, {NULL, NULL} }; diff --git a/nselib/http.lua b/nselib/http.lua index 9d8c15047..fab0729a4 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -85,12 +85,19 @@ request = function( host, port, data, options ) local result = {status=nil,header={},body=""} local socket = nmap.new_socket() + local default_timeout = {} if options.timeout then socket:set_timeout( options.timeout ) + else + default_timeout = get_default_timeout( nmap.timing_level() ) + socket:set_timeout( default_timeout.connect ) end if not socket:connect( host, port, protocol ) then return result end + if not options.timeout then + socket:set_timeout( default_timeout.request ) + end if not socket:send( data ) then return result end @@ -147,3 +154,18 @@ request = function( host, port, data, options ) end +get_default_timeout = function( nmap_timing ) + local timeout = {} + if nmap_timing >= 0 and nmap_timing <= 3 then + timeout.connect = 10000 + timeout.request = 15000 + end + if nmap_timing >= 4 then + timeout.connect = 5000 + timeout.request = 10000 + end + if nmap_timing >= 5 then + timeout.request = 7000 + end + return timeout +end \ No newline at end of file