Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/admin/smb/upload_file.rb
Views: 11784
##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' => %Q{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[26'hdm' # metasploit module27],28'References' =>29[30],31'License' => MSF_LICENSE,32)3334register_options([35OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server', 'C$'])36])3738end3940def run_host(_ip)41validate_lpaths!42validate_rpaths!43begin44if session45print_status("Using existing session #{session.sid}")46client = session.client47self.simple = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)4849else50vprint_status("Connecting to the server...")51connect52smb_login()53end5455vprint_status("Mounting the remote share \\\\#{simple.address}\\#{datastore['SMBSHARE']}'...")56self.simple.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|66begin67vprint_status("Trying to upload #{local_path} to #{remote_path}...")6869fd = simple.open("#{remote_path}", 'wct', write: true)70data = ::File.read(datastore['LPATH'], ::File.size(datastore['LPATH']), mode: 'rb')71fd.write(data)72fd.close7374print_good("#{local_path} uploaded to #{remote_path}")75rescue Rex::Proto::SMB::Exceptions::ErrorCode => e76elog("Unable to upload #{local_path} to #{remote_path}", error: e)77print_error("Unable to upload #{local_path} to #{remote_path} : #{e.message}")78end79end80rescue Rex::Proto::SMB::Exceptions::LoginError => e81elog("Unable to login:", error: e)82print_error("Unable to login: #{e.message}")83end84end85end868788