2013-06-25 15:22:51 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# web site for more information on licensing and terms of use.
|
2013-06-26 03:09:45 +00:00
|
|
|
# http://metasploit.com/
|
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'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::Smtp
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'SMTP Open Relay Detection',
|
|
|
|
'Description' => 'SMTP Open Relay Detection',
|
|
|
|
'References' =>
|
|
|
|
[
|
2013-06-26 03:09:45 +00:00
|
|
|
['URL', 'http://www.ietf.org/rfc/rfc2821.txt'],
|
2013-06-25 15:22:51 +00:00
|
|
|
],
|
|
|
|
'Author' => 'Campbell Murray',
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2013-06-26 03:09:45 +00:00
|
|
|
def peer
|
|
|
|
"#{rhost}:#{rport}"
|
|
|
|
end
|
|
|
|
|
2013-06-25 15:22:51 +00:00
|
|
|
def run_host(ip)
|
2013-06-26 03:09:45 +00:00
|
|
|
begin
|
|
|
|
connect
|
|
|
|
rescue
|
|
|
|
print_error("#{peer} - Unable to establish an SMTP session")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-25 15:22:51 +00:00
|
|
|
banner_sanitized = Rex::Text.to_hex_ascii(banner.to_s)
|
2013-06-26 03:09:45 +00:00
|
|
|
print_status("#{peer} - SMTP #{banner_sanitized}")
|
2013-06-25 15:22:51 +00:00
|
|
|
report_service(:host => rhost, :port => rport, :name => "smtp", :info => banner)
|
2013-06-26 03:09:45 +00:00
|
|
|
do_test_relay
|
|
|
|
end
|
2013-06-25 15:22:51 +00:00
|
|
|
|
2013-06-25 20:43:58 +00:00
|
|
|
def do_test_relay
|
2013-06-26 03:09:45 +00:00
|
|
|
res = raw_send_recv("EHLO X\r\n")
|
|
|
|
vprint_status("#{peer} - #{res.inspect}")
|
|
|
|
|
|
|
|
res = raw_send_recv("MAIL FROM: #{datastore['MAILFROM']}\r\n")
|
|
|
|
vprint_status("#{peer} - #{res.inspect}")
|
|
|
|
|
|
|
|
res = raw_send_recv("RCPT TO: #{datastore['MAILTO']}\r\n")
|
|
|
|
vprint_status("#{peer} - #{res.inspect}")
|
|
|
|
|
|
|
|
res = raw_send_recv("DATA\r\n")
|
|
|
|
vprint_status("#{peer} - #{res.inspect}")
|
|
|
|
|
|
|
|
res = raw_send_recv("#{Rex::Text.rand_text_alpha(rand(10)+5)}\r\n.\r\n")
|
|
|
|
vprint_status("#{peer} - #{res.inspect}")
|
|
|
|
|
|
|
|
if res =~ /250/
|
|
|
|
print_good("#{peer} - Potential open SMTP relay detected")
|
|
|
|
else
|
|
|
|
print_status "#{peer} - No relay detected"
|
|
|
|
end
|
2013-06-25 15:22:51 +00:00
|
|
|
end
|
|
|
|
end
|