Path: blob/master/modules/auxiliary/admin/smb/download_file.rb
28527 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::RemotePaths11include Msf::Auxiliary::Report12include Msf::Auxiliary::Scanner13include Msf::OptionalSession::SMB1415def initialize16super(17'Name' => 'SMB File Download Utility',18'Description' => %(19This module downloads a file from a target share and path. The usual reason20to use this module is to work around limitations in an existing SMB client that may not21be able to take advantage of pass-the-hash style authentication.22),23'Author' => [24'mubix' # copied from hdm upload_file module25],26'License' => MSF_LICENSE,27'Notes' => {28'Stability' => [CRASH_SAFE],29'SideEffects' => [],30'Reliability' => []31},32'References' => [33[ 'ATT&CK', Mitre::Attack::Technique::T1021_002_SMB_WINDOWS_ADMIN_SHARES ]34]35)3637register_options([38OptString.new('SMBSHARE', [true, 'The name of a share on the RHOST', 'C$'])39])40end4142def smb_download43vprint_status('Connecting...')44if session4546print_status("Using existing session #{session.sid}")47self.simple = session.simple_client48else49connect50smb_login51end5253vprint_status("Mounting the remote share \\\\#{simple.address}\\#{datastore['SMBSHARE']}'...")54simple.connect("\\\\#{simple.address}\\#{datastore['SMBSHARE']}")5556remote_paths.each do |remote_path|57vprint_status("Trying to download #{remote_path}...")5859data = ''60fd = simple.open(remote_path.to_s, 'o')61begin62data = fd.read63ensure64fd.close65end6667fname = remote_path.split('\\')[-1]68path = store_loot('smb.shares.file', 'application/octet-stream', rhost, data, fname)69print_good("#{remote_path} saved as: #{path}")70rescue Rex::Proto::SMB::Exceptions::ErrorCode => e71elog("Unable to download #{remote_path}:", error: e)72print_error("Unable to download #{remote_path}: #{e.message}")73end74end7576def run_host(_ip)77validate_rpaths!7879begin80smb_download81rescue Rex::Proto::SMB::Exceptions::LoginError => e82elog("Unable to login: #{e.message}", error: e)83print_error("Unable to login: #{e.message}")84end85end86end878889