diff --git a/nselib/pop3.lua b/nselib/pop3.lua index e820e2d8e..33cd4d3c6 100644 --- a/nselib/pop3.lua +++ b/nselib/pop3.lua @@ -143,14 +143,16 @@ end -- See RFC 2449. -- @param host Host to be queried. -- @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) local socket = nmap.new_socket() 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) - 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 diff --git a/scripts/pop3-capabilities.nse b/scripts/pop3-capabilities.nse index 9cfbe5b38..e5d831436 100644 --- a/scripts/pop3-capabilities.nse +++ b/scripts/pop3-capabilities.nse @@ -24,8 +24,8 @@ require 'stdnse' portrule = shortport.port_or_service({110}, "pop3") action = function(host, port) - local capa = pop3.capabilities(host, port) - if capa then + local capa, err = pop3.capabilities(host, port) + if type(capa) == "table" then -- Convert the capabilities table into an array of strings. local capstrings = {} local cap, args @@ -43,6 +43,9 @@ action = function(host, port) table.insert(capstrings, capstr) end return stdnse.strjoin(" ", capstrings) + elseif type(err) == "string" then + stdnse.print_debug(1, "%s: '%s' for %s", filename, err, host.ip) + return else return "server doesn't support CAPA" end