mirror of
https://github.com/nmap/nmap.git
synced 2025-12-15 12:19:02 +00:00
fixed a bug in the pop3-capabilities script that would fail parsing the
response from some servers.
This commit is contained in:
@@ -151,44 +151,49 @@ end
|
|||||||
-- @return Table containing capabilities or nil on error.
|
-- @return Table containing capabilities or nil on error.
|
||||||
-- @return nil or String error message.
|
-- @return nil or String error message.
|
||||||
function capabilities(host, port)
|
function capabilities(host, port)
|
||||||
local socket = nmap.new_socket()
|
|
||||||
|
local socket, line, bopt, first_line = comm.tryssl(host, port, "" , {timeout=10000, recv_before=true})
|
||||||
|
if not socket then
|
||||||
|
return nil, "Could Not Connect"
|
||||||
|
end
|
||||||
|
if not stat(first_line) then
|
||||||
|
return nil, "No Response"
|
||||||
|
end
|
||||||
|
|
||||||
local capas = {}
|
local capas = {}
|
||||||
local opts = {timeout=10000, recv_before=true}
|
if string.find(first_line, "<[%p%w]+>") then
|
||||||
local i = 1
|
capas.APOP = {}
|
||||||
|
|
||||||
local socket, line, bopt, first_line = comm.tryssl(host, port, "CAPA\r\n" , opts)
|
|
||||||
if not socket then return nil, "Could Not Connect" end
|
|
||||||
if not stat(first_line) then return nil, "No Response" end
|
|
||||||
|
|
||||||
if string.find(first_line, "<[%p%w]+>") then capas.APOP = true end
|
|
||||||
|
|
||||||
local lines = stdnse.strsplit("\r\n",line)
|
|
||||||
local line = lines[1]
|
|
||||||
|
|
||||||
if not stat(line) then
|
|
||||||
capas.capa = false
|
|
||||||
else
|
|
||||||
while line do
|
|
||||||
if line ~= "." then
|
|
||||||
local capability = string.sub(line, string.find(line, "[%w-]+"))
|
|
||||||
line = string.sub(line, #capability + 1)
|
|
||||||
capas[capability] = true
|
|
||||||
local args = {}
|
|
||||||
local w
|
|
||||||
for w in string.gmatch(line, "[%w-]+") do
|
|
||||||
table.insert(args, w)
|
|
||||||
end
|
end
|
||||||
if #args == 1 then capas[capability] = args[1]
|
|
||||||
else if #args > 1 then capas[capability] = args
|
local status = socket:send("CAPA\r\n")
|
||||||
end end
|
if( not(status) ) then
|
||||||
else
|
return nil, "Failed to send"
|
||||||
break
|
|
||||||
end
|
|
||||||
line = lines[i]
|
|
||||||
i = i + 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
status, line = socket:receive_buf("%.", false)
|
||||||
|
if( not(status) ) then
|
||||||
|
return nil, "Failed to receive"
|
||||||
end
|
end
|
||||||
socket:close()
|
socket:close()
|
||||||
|
|
||||||
|
local lines = stdnse.strsplit("\r\n",line)
|
||||||
|
if not stat(table.remove(lines,1)) then
|
||||||
|
capas.capa = false
|
||||||
|
return capas
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, line in ipairs(lines) do
|
||||||
|
if ( line and #line>0 ) then
|
||||||
|
local capability = line:sub(line:find("[%w-]+"))
|
||||||
|
line = line:sub(#capability + 2)
|
||||||
|
if ( line ~= "" ) then
|
||||||
|
capas[capability] = stdnse.strsplit(" ", line)
|
||||||
|
else
|
||||||
|
capas[capability] = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return capas
|
return capas
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -31,19 +31,12 @@ action = function(host, port)
|
|||||||
if type(capa) == "table" 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
|
|
||||||
for cap, args in pairs(capa) do
|
for cap, args in pairs(capa) do
|
||||||
local capstr = cap
|
if ( #args > 0 ) then
|
||||||
if type(args) == "string" then capstr = capstr .. "(" .. args .. ")" end
|
table.insert(capstrings, ("%s(%s)"):format(cap, stdnse.strjoin(" ", args)))
|
||||||
if type(args) == "table" then
|
else
|
||||||
local arg
|
table.insert(capstrings, cap)
|
||||||
capstr = capstr .. "("
|
|
||||||
for i, arg in ipairs(args) do
|
|
||||||
capstr = capstr .. arg .. " "
|
|
||||||
end
|
end
|
||||||
capstr = string.sub(capstr, 1, #capstr - 1) .. ")"
|
|
||||||
end
|
|
||||||
table.insert(capstrings, capstr)
|
|
||||||
end
|
end
|
||||||
return stdnse.strjoin(" ", capstrings)
|
return stdnse.strjoin(" ", capstrings)
|
||||||
elseif type(err) == "string" then
|
elseif type(err) == "string" then
|
||||||
|
|||||||
Reference in New Issue
Block a user