Nmap smtp-open-relay NSE Script


This page contains detailed information about how to use the smtp-open-relay NSE script. For list of all NSE scripts, visit the Nmap NSE Library.

Select:
Overview
Error Messages

Script Overview


Script source code: https://github.com/nmap/nmap/tree/master/scripts/smtp-open-relay.nse
Script categories: discovery, intrusive, external
Target service / protocol: smtp, smtps, submission
Target network port(s): 25, 465, 587
List of CVEs: -

Script Description


The smtp-open-relay.nse script attempts to relay mail by issuing a predefined combination of SMTP commands. The goal of this script is to tell if a SMTP server is vulnerable to mail relaying.

An SMTP server that works as an open relay, is a email server that does not verify if the user is authorised to send email from the specified email address. Therefore, users would be able to send email originating from any third-party email address that they want.

The checks are done based in combinations of MAIL FROM and RCPT TO commands. The list is hardcoded in the source file. The script will output all the working combinations that the server allows if nmap is in verbose mode otherwise the script will print the number of successful tests. The script will not output if the server requires authentication.

If debug is enabled and an error occurs while testing the target host, the error will be printed with the list of any combinations that were found prior to the error.

Smtp-open-relay NSE Script Arguments


This is a full list of arguments supported by the smtp-open-relay.nse script:

smtp.domain

Or smtp-open-relay.domain Define the domain to be used in the anti-spam tests and EHLO command (default is nmap.scanme.org)

smtp-open-relay.from

Define the source email address to be used (without the domain, default is antispam)

smtp-open-relay.ip

Use this to change the IP address to be used (default is the target IP address)

smtp-open-relay.to

Define the destination email address to be used (without the domain, default is relaytest)

smbdomain

The domain to log in with. If you aren't in a domain environment, then anything will (should?) be accepted by the server.

smbhash

A password hash to use when logging in. This is given as a single hex string (32 characters) or a pair of hex strings (both 32 characters, optionally separated by a single character). These hashes are the LanMan or NTLM hash of the user's password, and are stored on disk or in memory. They can be retrieved from memory using the fgdump or pwdump tools.

smbnoguest

Use to disable usage of the 'guest' account.

smbpassword

The password to connect with. Be cautious with this, since some servers will lock accounts if the incorrect password is given. Although it's rare that the Administrator account can be locked out, in the off chance that it can, you could get yourself in trouble. To use a blank password, leave this parameter off altogether.

smbtype

The type of SMB authentication to use. These are the possible options:

  • v1: Sends LMv1 and NTLMv1.
  • LMv1: Sends LMv1 only.
  • NTLMv1: Sends NTLMv1 only (default).
  • v2: Sends LMv2 and NTLMv2.
  • LMv2: Sends LMv2 only.
  • NTLMv2: Doesn't exist; the protocol doesn't support NTLMv2 alone. The default, NTLMv1, is a pretty decent compromise between security and compatibility. If you are paranoid, you might want to use v2 or lmv2 for this. (Actually, if you're paranoid, you should be avoiding this protocol altogether!). If you're using an extremely old system, you might need to set this to v1 or lm, which are less secure but more compatible. For information, see smbauth.lua.

smbusername

The SMB username to log in with. The forms "DOMAIN\username" and "username@DOMAIN" are not understood. To set a domain, use the smbdomain argument.

- - -
To use these script arguments, add them to the Nmap command line using the --script-args arg1=value,[arg2=value,..] syntax. For example:

nmap --script=smtp-open-relay --script-args smtp.domain=value,smtp-open-relay.from=value <target>

Smtp-open-relay NSE Script Example Usage


Here's an example of how to use the smtp-open-relay.nse script:

nmap --script smtp-open-relay.nse [--script-args smtp-open-relay.domain=<domain>,smtp-open-relay.ip=<address>,...] -p 25,465,587 <host>

Smtp-open-relay NSE Script Example Output


Here's a sample output from the smtp-open-relay.nse script:

Host script results:
| smtp-open-relay: Server is an open relay (1/16 tests)
|_MAIL FROM:<[email protected]> -> RCPT TO:<[email protected]>

Smtp-open-relay NSE Script Example XML Output


There is no sample XML output for this module. However, by providing the -oX <file> option, Nmap will produce a XML output and save it in the file.xml file.

Author


  • Arturo Buanzo Busleiman

References


See Also


Related NSE scripts to the smtp-open-relay.nse script:

Visit Nmap NSE Library for more scripts.

The smtp-open-relay.nse script may fail with the following error messages. Check for the possible causes by using the code snippets highlighted below found in the script source code. This can often times help in identifying the root cause of the problem.

Couldn't establish connection on port %i


Here is a relevant code snippet related to the "Couldn't establish connection on port %i" error message:

111:	
112:	  local domain, from, to, ip = get_parameters(host)
113:	
114:	  local socket, response = smtp.connect(host, port, options)
115:	  if not socket then
116:	    return false, string.format("Couldn't establish connection on port %i",
117:	      port.number)
118:	  end
119:	
120:	  local srvname = string.match(response, "%d+%s([%w]+[%w%.-]*)")
121:	

Server isn't an open relay, authentication needed


Here is a relevant code snippet related to the "Server isn't an open relay, authentication needed" error message:

211:	
212:	  for index = 1, #tests do
213:	    status, response = smtp.reset(socket)
214:	    if not status then
215:	      if string.match(response, "530") then
216:	        return false, "Server isn't an open relay, authentication needed"
217:	      end
218:	      return failure(response)
219:	    end
220:	
221:	    status, response = smtp.query(socket, "MAIL",

Failed to issue %s command (%s)


Here is a relevant code snippet related to the "Failed to issue %s command (%s)" error message:

222:	      string.format("FROM:<%s>",
223:	      tests[index]["from"]))
224:	    -- If this command fails to be sent, then something went
225:	    -- wrong with the connection.
226:	    if not status then
227:	      return failure(string.format("Failed to issue %s command (%s)",
228:	        tests[index]["from"], response))
229:	    end
230:	
231:	    if string.match(response, "530") then
232:	      smtp.quit(socket)

Server isn't an open relay, authentication needed


Here is a relevant code snippet related to the "Server isn't an open relay, authentication needed" error message:

228:	        tests[index]["from"], response))
229:	    end
230:	
231:	    if string.match(response, "530") then
232:	      smtp.quit(socket)
233:	      return false, "Server isn't an open relay, authentication needed"
234:	    elseif smtp.check_reply("MAIL", response) then
235:	      -- Lets try to actually relay.
236:	      status, response = smtp.query(socket, "RCPT",
237:	        string.format("TO:<%s>",
238:	        tests[index]["to"]))

Failed to issue %s command (%s)


Here is a relevant code snippet related to the "Failed to issue %s command (%s)" error message:

235:	      -- Lets try to actually relay.
236:	      status, response = smtp.query(socket, "RCPT",
237:	        string.format("TO:<%s>",
238:	        tests[index]["to"]))
239:	      if not status then
240:	        return failure(string.format("Failed to issue %s command (%s)",
241:	          tests[index]["to"], response))
242:	      end
243:	
244:	      if string.match(response, "530") then
245:	        smtp.quit(socket)

Server isn't an open relay, authentication needed


Here is a relevant code snippet related to the "Server isn't an open relay, authentication needed" error message:

241:	          tests[index]["to"], response))
242:	      end
243:	
244:	      if string.match(response, "530") then
245:	        smtp.quit(socket)
246:	        return false, "Server isn't an open relay, authentication needed"
247:	      elseif smtp.check_reply("RCPT", response) then
248:	        -- Save the working from and to combination.
249:	        table.insert(result,
250:	          string.format("MAIL FROM:<%s> -> RCPT TO:<%s>",
251:	          tests[index]["from"], tests[index]["to"]))

Server doesn't seem to be an open relay, all tests failed


Here is a relevant code snippet related to the "Server doesn't seem to be an open relay, all tests failed" error message:

278:	        for index, test in ipairs(result) do
279:	          table.insert(final, test)
280:	        end
281:	      end
282:	
283:	      return table.concat(final, "\n ")
284:	    end
285:	
286:	    return "Server doesn't seem to be an open relay, all tests failed"
287:	  end
288:	end

Version


This page has been created based on Nmap version 7.92.

Go back to menu.