Path: blob/master/modules/auxiliary/admin/smb/upload_file.rb
19593 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary67# Exploit mixins should be called first8include Msf::Exploit::Remote::SMB::Client9include Msf::Exploit::Remote::SMB::Client::Authenticated10include Msf::Exploit::Remote::SMB::Client::LocalPaths11include Msf::Exploit::Remote::SMB::Client::RemotePaths12include Msf::Auxiliary::Report13include Msf::Auxiliary::Scanner14include Msf::OptionalSession::SMB1516def initialize17super(18'Name' => 'SMB File Upload Utility',19'Description' => %(20This module uploads a file to a target share and path. The only reason21to use this module is if your existing SMB client is not able to support the features22of the Metasploit Framework that you need, like pass-the-hash authentication.23),24'Author' => [25'hdm' # metasploit module26],27'References' => [28],29'License' => MSF_LICENSE,30'Notes' => {31'Stability' => [CRASH_SAFE],32'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK],33'Reliability' => []34}35)3637register_options([38OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server', 'C$'])39])40end4142def run_host(_ip)43validate_lpaths!44validate_rpaths!45begin46if session47print_status("Using existing session #{session.sid}")48self.simple = session.simple_client49else50vprint_status('Connecting to the server...')51connect52smb_login53end5455vprint_status("Mounting the remote share \\\\#{simple.address}\\#{datastore['SMBSHARE']}'...")56simple.connect("\\\\#{simple.address}\\#{datastore['SMBSHARE']}")5758remote_path = remote_paths.first5960if local_paths.nil?61print_error('Local paths not specified')62return63end6465local_paths.each do |local_path|66vprint_status("Trying to upload #{local_path} to #{remote_path}...")6768fd = simple.open(remote_path.to_s, 'wct', write: true)69data = ::File.read(datastore['LPATH'], ::File.size(datastore['LPATH']), mode: 'rb')70fd.write(data)71fd.close7273print_good("#{local_path} uploaded to #{remote_path}")74rescue Rex::Proto::SMB::Exceptions::ErrorCode => e75elog("Unable to upload #{local_path} to #{remote_path}", error: e)76print_error("Unable to upload #{local_path} to #{remote_path} : #{e.message}")77end78rescue Rex::Proto::SMB::Exceptions::LoginError => e79elog('Unable to login:', error: e)80print_error("Unable to login: #{e.message}")81end82end83end848586