id = "POP3 Capabilites (nl)" description = "retrieves POP3 server capabilites (without pop3-library dependency) " author = "Philip Pickering " license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"default"} require 'shortport' require 'stdnse' portrule = shortport.port_or_service({110}, "pop3") function stat (line) return string.match(line, "+OK") end action = function(host, port) local socket = nmap.new_socket() if not socket:connect(host.ip, port.number) then return "no connection" end status, line = socket:receive_lines(1) if not stat(line) then return "no pop connection" end local capstr = "" if string.find(line, "<[%p%w]+>") then capstr = "APOP " end socket:send("CAPA\r\n") status, line = socket:receive_buf("\r\n", false) if stat(line) then status, line = socket:receive_buf("\r\n", false) while line do if line ~= "." then local capability = string.sub(line, string.find(line, "[%w-]+")) line = string.sub(line, #capability + 1) capstr = capstr .. " " .. capability local word local argstr = "" for word in string.gmatch(line, "[%w-]+") do argstr = argstr .. word .. " " end if argstr ~= "" then capstr = capstr .. '(' .. string.sub(argstr, 1, #argstr -1) .. ')' end else break end status, line = socket:receive_buf("\r\n", false) end end socket:send("QUIT\r\n") status, line = socket:receive_buf("\r\n", false) socket:close() if capstr ~= "" then return capstr else return "server doesn't support CAPA" end end