1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-10 09:49:05 +00:00

Fix error:

SCRIPT ENGINE (506.424s): ./scripts/pop3-capabilities.nse against a.b.1.47:995
ended with error: ./scripts/pop3-capabilities.nse:32: bad argument #1 to
'pairs' (table expected, got string)

which happens because pop3.lua returns a string error message instead of a table
of capabilities if it can't connect the socket or obtain a response from a
connected socket.
It now returns nil, err_message in these cases and the documentation now reflects
this - pop3-capabilities.nse silently returns and prints a debug message.

Added a 10s timeout for the socket in pop3.lua capabilities - 30s was a bit much.
This commit is contained in:
jah
2009-02-03 01:15:25 +00:00
parent abd6137d61
commit c8442d3946
2 changed files with 11 additions and 6 deletions

View File

@@ -143,14 +143,16 @@ end
-- See RFC 2449. -- See RFC 2449.
-- @param host Host to be queried. -- @param host Host to be queried.
-- @param port Port to connect to. -- @param port Port to connect to.
-- @return Table containing capabilities. -- @return Table containing capabilities or nil on error.
-- @return nil or String error message.
function capabilities(host, port) function capabilities(host, port)
local socket = nmap.new_socket() local socket = nmap.new_socket()
local capas = {} local capas = {}
if not socket:connect(host.ip, port.number) then return "no conn" end socket:set_timeout(10000)
if not socket:connect(host.ip, port.number) then return nil, "Could Not Connect" end
status, line = socket:receive_lines(1) status, line = socket:receive_lines(1)
if not stat(line) then return "no popconn" end if not stat(line) then return nil, "No Response" end
if string.find(line, "<[%p%w]+>") then capas.APOP = true end if string.find(line, "<[%p%w]+>") then capas.APOP = true end

View File

@@ -24,8 +24,8 @@ require 'stdnse'
portrule = shortport.port_or_service({110}, "pop3") portrule = shortport.port_or_service({110}, "pop3")
action = function(host, port) action = function(host, port)
local capa = pop3.capabilities(host, port) local capa, err = pop3.capabilities(host, port)
if capa then if type(capa) == "table" then
-- Convert the capabilities table into an array of strings. -- Convert the capabilities table into an array of strings.
local capstrings = {} local capstrings = {}
local cap, args local cap, args
@@ -43,6 +43,9 @@ action = function(host, port)
table.insert(capstrings, capstr) table.insert(capstrings, capstr)
end end
return stdnse.strjoin(" ", capstrings) return stdnse.strjoin(" ", capstrings)
elseif type(err) == "string" then
stdnse.print_debug(1, "%s: '%s' for %s", filename, err, host.ip)
return
else else
return "server doesn't support CAPA" return "server doesn't support CAPA"
end end