1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00

Minor updates to smtp-open-relay.nse from Duarte Silva.

This commit is contained in:
david
2010-03-09 20:17:55 +00:00
parent 82fe004f3b
commit d3150aa5a3

View File

@@ -10,6 +10,9 @@ The checks are done based in combinations of MAIL FROM and RCPT TO commands. The
hardcoded in the source file. The script will output all the working combinations that the hardcoded in the source file. The script will output all the working combinations that the
server allows, or none if the server requires authentication or if there wasn't any working server allows, or none if the server requires authentication or if there wasn't any working
combinations. combinations.
If debug is enabled and an error occurrs while testing the target host, the error will be
printed with the list of any combinations that were found prior to the error.
]] ]]
--- ---
@@ -23,7 +26,8 @@ combinations.
-- | MAIL FROM:<antispam@[10.0.1.2]> -> RCPT TO:<"relaytest%nmap.scanme.org"> -- | MAIL FROM:<antispam@[10.0.1.2]> -> RCPT TO:<"relaytest%nmap.scanme.org">
-- |_ MAIL FROM:<antispam@[10.0.1.2]> -> RCPT TO:<nmap.scanme.org!relaytest> -- |_ MAIL FROM:<antispam@[10.0.1.2]> -> RCPT TO:<nmap.scanme.org!relaytest>
-- --
-- @args smtp-open-relay.domain Define the domain to be used in the anti-spam tests (default is nmap.scanme.org) -- @args smtp-open-relay.domain Define the domain to be used in the anti-spam tests and EHLO command (default
-- is nmap.scanme.org)
-- @args smtp-open-relay.ip Use this to change the IP address to be used (default is the target IP address) -- @args smtp-open-relay.ip Use this to change the IP address to be used (default is the target IP address)
-- --
-- @changelog -- @changelog
@@ -52,6 +56,9 @@ combinations.
-- + More information in the script description -- + More information in the script description
-- + Script will output the reason for failed commands (at the connection level) -- + Script will output the reason for failed commands (at the connection level)
-- * If some combinations were already found before an error, the script will report them -- * If some combinations were already found before an error, the script will report them
-- 2010-03-07 Duarte Silva <duarte.silva@myf00.net>
-- * Fixed socket left open when receive_lines function call fails
-- * Minor comments changes
----------------------------------------------------------------------- -----------------------------------------------------------------------
author = "Arturo 'Buanzo' Busleiman <buanzo@buanzo.com.ar>" author = "Arturo 'Buanzo' Busleiman <buanzo@buanzo.com.ar>"
@@ -71,19 +78,24 @@ portrule = shortport.port_or_service({ 25, 465, 587 }, { "smtp", "smtps", "submi
--@return False in case of failure --@return False in case of failure
--@return True and the response in case of success --@return True and the response in case of success
function dorequest(socket, request) function dorequest(socket, request)
-- Exception handler -- Exception handler.
local catch = function() local catch = function()
socket:close() socket:close()
end end
-- Try function
local try = nmap.new_try(catch) local try = nmap.new_try(catch)
-- Lets send the command -- Lets send the command.
try(socket:send(request)) try(socket:send(request))
-- Receive server response
-- Receive server response.
local status, response = socket:receive_lines(1) local status, response = socket:receive_lines(1)
if not status then if not status then
-- Close the socket (the call to receive_lines doesn't use try).
socket:close()
-- Supported error messages.
local messages = { local messages = {
["EOF"] = "connection closed", ["EOF"] = "connection closed",
["TIMEOUT"] = "connection timeout", ["TIMEOUT"] = "connection timeout",
@@ -131,7 +143,7 @@ function go(host, port)
return false, string.format("Couldn't establish connection on port %i", port.number) return false, string.format("Couldn't establish connection on port %i", port.number)
end end
-- Close socket and return if EHLO command failed -- Close socket and return if EHLO command failed.
if not string.match(response, "^250") then if not string.match(response, "^250") then
quit() quit()
return false, "Failed to issue EHLO command" return false, "Failed to issue EHLO command"
@@ -165,9 +177,14 @@ function go(host, port)
local status local status
-- This function is used when something goes wrong with the connection. It makes sure that -- This function is used when something goes wrong with the connection. It makes sure that
-- if it found working combinations before the error occurred, they will be returned. -- if it found working combinations before the error occurred, they will be returned. If the
-- debug flag is enabled the error message will be appended to the combinations list.
local failure = function(message) local failure = function(message)
if #result > 0 then if #result > 0 then
if nmap.debugging() > 0 then
table.insert(result, string.format("ERROR: %s", message))
end
return true, result return true, result
else else
return false, message return false, message
@@ -184,7 +201,7 @@ function go(host, port)
-- If reset the envelope, doesn't work for one, wont work for others (critical command). -- If reset the envelope, doesn't work for one, wont work for others (critical command).
if not string.match(response, "^250") then if not string.match(response, "^250") then
quit() quit()
-- Check if server needs authentication.
if string.match(response, "^530") then if string.match(response, "^530") then
return false, "Server isn't an open relay, authentication needed" return false, "Server isn't an open relay, authentication needed"
else else
@@ -231,7 +248,7 @@ end
action = function(host, port) action = function(host, port)
local status, result = go(host, port) local status, result = go(host, port)
-- No combinations found -- No combinations found.
if #result == 0 then if #result == 0 then
return stdnse.format_output(false, "All tests failed, server doesn't seem to be an open relay") return stdnse.format_output(false, "All tests failed, server doesn't seem to be an open relay")
end end