2010-09-20 04:03:26 +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
|
2010-09-20 04:03:26 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2010-09-20 04:03:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Exploit mixins should be called first
|
2015-02-13 23:17:59 +00:00
|
|
|
include Msf::Exploit::Remote::SMB::Client
|
2015-11-10 02:15:40 +00:00
|
|
|
include Msf::Exploit::Remote::SMB::Client::Authenticated
|
|
|
|
include Msf::Exploit::Remote::SMB::Client::LocalPaths
|
|
|
|
include Msf::Exploit::Remote::SMB::Client::RemotePaths
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Auxiliary::Report
|
2014-12-30 02:02:40 +00:00
|
|
|
include Msf::Auxiliary::Scanner
|
2013-08-30 21:28:54 +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 Upload Utility',
|
|
|
|
'Description' => %Q{
|
|
|
|
This module uploads a file to a target share and path. The only reason
|
|
|
|
to use this module is if your existing SMB client is not able to support the features
|
|
|
|
of the Metasploit Framework that you need, like pass-the-hash authentication.
|
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'hdm' # metasploit module
|
|
|
|
],
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options([
|
2014-12-30 17:21:29 +00:00
|
|
|
OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server', 'C$'])
|
2013-08-30 21:28:54 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-12-30 02:02:40 +00:00
|
|
|
def run_host(_ip)
|
|
|
|
begin
|
2016-06-08 17:16:50 +00:00
|
|
|
vprint_status("Connecting to the server...")
|
2014-12-30 02:02:40 +00:00
|
|
|
connect()
|
|
|
|
smb_login()
|
2013-08-30 21:28:54 +00:00
|
|
|
|
2016-06-08 17:16:50 +00:00
|
|
|
vprint_status("Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
|
2014-12-30 02:02:40 +00:00
|
|
|
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
|
2013-08-30 21:28:54 +00:00
|
|
|
|
2014-12-30 17:21:29 +00:00
|
|
|
remote_path = remote_paths.first
|
2016-06-09 21:21:49 +00:00
|
|
|
|
|
|
|
if local_paths.nil?
|
|
|
|
print_error("Local paths not specified")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-12-30 17:21:29 +00:00
|
|
|
local_paths.each do |local_path|
|
|
|
|
begin
|
2016-06-08 17:16:50 +00:00
|
|
|
vprint_status("Trying to upload #{local_path} to #{remote_path}...")
|
2014-12-30 17:21:29 +00:00
|
|
|
|
|
|
|
fd = simple.open("\\#{remote_path}", 'rwct')
|
|
|
|
data = ::File.read(datastore['LPATH'], ::File.size(datastore['LPATH']))
|
|
|
|
fd.write(data)
|
|
|
|
fd.close
|
|
|
|
|
2016-06-08 17:16:50 +00:00
|
|
|
print_good("#{local_path} uploaded to #{remote_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 upload #{local_path} to #{remote_path} : #{e.message}")
|
2014-12-30 17:21:29 +00:00
|
|
|
end
|
|
|
|
end
|
2014-12-30 02:02:40 +00:00
|
|
|
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}")
|
2014-12-30 02:02:40 +00:00
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2010-09-20 04:03:26 +00:00
|
|
|
end
|