2013-06-25 15:22:51 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2013-06-25 15:22:51 +00:00
|
|
|
##
|
2013-06-26 03:09:45 +00:00
|
|
|
|
2013-06-25 15:22:51 +00:00
|
|
|
require 'msf/core'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2013-06-25 15:22:51 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::Smtp
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
2013-06-25 15:22:51 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'SMTP Open Relay Detection',
|
|
|
|
'Description' => %q{
|
|
|
|
This module tests if an SMTP server will accept (via a code 250)
|
2014-02-12 08:44:53 +00:00
|
|
|
an e-mail by using a variation of testing methods.
|
|
|
|
Some of the extended methods will try to abuse configuration or mailserver flaws.
|
2013-08-30 21:28:54 +00:00
|
|
|
},
|
|
|
|
'References' =>
|
|
|
|
[
|
2014-03-17 08:09:29 +00:00
|
|
|
['URL', 'http://www.ietf.org/rfc/rfc2821.txt'],
|
2014-02-12 08:44:53 +00:00
|
|
|
['URL', 'https://svn.nmap.org/nmap/scripts/smtp-open-relay.nse'],
|
2013-08-30 21:28:54 +00:00
|
|
|
],
|
2014-03-17 08:09:29 +00:00
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'Campbell Murray',
|
|
|
|
'xistence <xistence[at]0x90.nl>',
|
|
|
|
],
|
2013-08-30 21:28:54 +00:00
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
2014-02-12 08:44:53 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptBool.new('EXTENDED', [true, 'Do all the 16 extended checks', false]),
|
|
|
|
], self.class)
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2013-06-25 15:22:51 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run_host(ip)
|
|
|
|
begin
|
|
|
|
connect
|
2014-02-12 08:44:53 +00:00
|
|
|
banner_sanitized = Rex::Text.to_hex_ascii(banner.to_s)
|
2016-02-01 22:06:34 +00:00
|
|
|
print_status("SMTP #{banner_sanitized}")
|
2014-02-12 08:44:53 +00:00
|
|
|
report_service(:host => rhost, :port => rport, :name => "smtp", :info => banner)
|
|
|
|
|
|
|
|
if datastore['EXTENDED']
|
|
|
|
|
|
|
|
if banner_sanitized =~ /220 (.*) /
|
|
|
|
serverhost = $1
|
|
|
|
end
|
|
|
|
|
|
|
|
mailfromuser = datastore['MAILFROM'].split("@").first
|
|
|
|
mailfromdomain = datastore['MAILFROM'].split("@").last
|
|
|
|
mailtouser = datastore['MAILTO'].split("@").first
|
|
|
|
mailtodomain = datastore['MAILTO'].split("@").last
|
|
|
|
|
|
|
|
do_test_relay(1, "MAIL FROM:<>", "RCPT TO:<#{datastore['MAILTO']}>")
|
|
|
|
do_test_relay(2, "MAIL FROM:<#{datastore['MAILFROM']}>", "RCPT TO:<#{datastore['MAILTO']}>")
|
|
|
|
do_test_relay(3, "MAIL FROM:<#{mailfromuser}@#{serverhost}>", "RCPT TO:<#{datastore['MAILTO']}>")
|
|
|
|
do_test_relay(4, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<#{mailtouser}@[#{rhost}]>")
|
|
|
|
do_test_relay(5, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<#{mailtouser}\%#{mailtodomain}@[#{rhost}]>")
|
|
|
|
do_test_relay(6, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<#{mailtouser}\%#{mailtodomain}@#{serverhost}>")
|
|
|
|
do_test_relay(7, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<\"#{mailtouser}@#{mailtodomain}\">")
|
|
|
|
do_test_relay(8, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<\"#{mailtouser}\%#{mailtodomain}\">")
|
|
|
|
do_test_relay(9, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<#{mailtouser}@#{mailtodomain}@[#{rhost}]>")
|
|
|
|
do_test_relay(10, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<\"#{mailtouser}@#{mailtodomain}\"@[#{rhost}]>")
|
|
|
|
do_test_relay(11, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<#{mailtouser}@#{mailtodomain}@#{serverhost}>")
|
|
|
|
do_test_relay(12, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<@[#{rhost}]:#{mailtouser}@#{mailtodomain}>")
|
|
|
|
do_test_relay(13, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<@#{serverhost}:#{mailtouser}@#{mailtodomain}>")
|
|
|
|
do_test_relay(14, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<#{mailtodomain}!#{mailtouser}>")
|
|
|
|
do_test_relay(15, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<#{mailtodomain}!#{mailtouser}@[#{rhost}]>")
|
|
|
|
do_test_relay(16, "MAIL FROM:<#{mailfromuser}@[#{rhost}]>", "RCPT TO:<#{mailtodomain}!#{mailtouser}@#{serverhost}>")
|
|
|
|
else
|
|
|
|
do_test_relay(nil, "MAIL FROM:<#{datastore['MAILFROM']}>", "RCPT TO:<#{datastore['MAILTO']}>")
|
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
rescue
|
2016-02-01 22:06:34 +00:00
|
|
|
print_error("Unable to establish an SMTP session")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2013-06-25 15:22:51 +00:00
|
|
|
|
2014-02-12 08:44:53 +00:00
|
|
|
def do_test_relay(testnumber, mailfrom, mailto)
|
|
|
|
begin
|
|
|
|
connect
|
|
|
|
|
|
|
|
res = raw_send_recv("EHLO X\r\n")
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_status("#{res.inspect}")
|
2013-06-26 03:09:45 +00:00
|
|
|
|
2014-02-12 08:44:53 +00:00
|
|
|
res = raw_send_recv("#{mailfrom}\r\n")
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_status("#{res.inspect}")
|
2013-06-26 03:09:45 +00:00
|
|
|
|
2014-02-12 08:44:53 +00:00
|
|
|
res = raw_send_recv("#{mailto}\r\n")
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_status("#{res.inspect}")
|
2013-06-26 03:09:45 +00:00
|
|
|
|
2014-02-12 08:44:53 +00:00
|
|
|
res = raw_send_recv("DATA\r\n")
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_status("#{res.inspect}")
|
2013-06-26 03:09:45 +00:00
|
|
|
|
2014-02-12 08:44:53 +00:00
|
|
|
res = raw_send_recv("#{Rex::Text.rand_text_alpha(rand(10)+5)}\r\n.\r\n")
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_status("#{res.inspect}")
|
2013-06-26 03:09:45 +00:00
|
|
|
|
2014-02-12 08:44:53 +00:00
|
|
|
if res =~ /250/
|
|
|
|
if testnumber.nil?
|
2016-02-01 22:06:34 +00:00
|
|
|
print_good("Potential open SMTP relay detected: - #{mailfrom} -> #{mailto}")
|
2014-02-12 08:44:53 +00:00
|
|
|
else
|
2016-02-01 22:06:34 +00:00
|
|
|
print_good("Test ##{testnumber} - Potential open SMTP relay detected: - #{mailfrom} -> #{mailto}")
|
2014-02-12 08:44:53 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if testnumber.nil?
|
2016-02-01 22:06:34 +00:00
|
|
|
print_status "No relay detected"
|
2014-02-12 08:44:53 +00:00
|
|
|
else
|
2016-02-01 22:06:34 +00:00
|
|
|
print_status "Test ##{testnumber} - No relay detected"
|
2014-02-12 08:44:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue
|
2016-02-01 22:06:34 +00:00
|
|
|
print_error("Test ##{testnumber} - Unable to establish an SMTP session")
|
2014-02-12 08:44:53 +00:00
|
|
|
return
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
end
|
2013-07-01 20:37:37 +00:00
|
|
|
end
|