Path: blob/master/modules/auxiliary/admin/smb/delete_file.rb
19567 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::SMB1415# Aliases for common classes16SIMPLE = Rex::Proto::SMB::SimpleClient17XCEPT = Rex::Proto::SMB::Exceptions18CONST = Rex::Proto::SMB::Constants1920def initialize21super(22'Name' => 'SMB File Delete Utility',23'Description' => %(24This module deletes a file from a target share and path. The usual reason25to use this module is to work around limitations in an existing SMB client that may not26be able to take advantage of pass-the-hash style authentication.27),28'Author' => [29'mubix' # copied from hdm upload_file module30],31'License' => MSF_LICENSE,32'Notes' => {33'Stability' => [OS_RESOURCE_LOSS],34'SideEffects' => [],35'Reliability' => []36}37)3839register_options([40OptString.new('SMBSHARE', [true, 'The name of a share on the RHOST', 'C$'])41])42end4344def smb_delete_files45if session46print_status("Using existing session #{session.sid}")47self.simple = session.simple_client48else49vprint_status('Connecting to the server...')50connect51smb_login52end5354vprint_status("Mounting the remote share \\\\#{simple.address}\\#{datastore['SMBSHARE']}'...")55simple.connect("\\\\#{simple.address}\\#{datastore['SMBSHARE']}")5657remote_paths.each do |remote_path|58simple.delete("\\#{remote_path}")5960# If there's no exception raised at this point, we assume the file has been removed.61print_good("Deleted: #{remote_path}")62rescue Rex::Proto::SMB::Exceptions::ErrorCode, RubySMB::Error::RubySMBError => e63elog("Cannot delete #{remote_path}:", error: e)64print_error("Cannot delete #{remote_path}: #{e.message}")65end66end6768def run_host(_ip)69validate_rpaths!7071begin72smb_delete_files73rescue Rex::Proto::SMB::Exceptions::LoginError => e74elog('Unable to login', error: e)75print_error("Unable to login: #{e.message}")76end77end78end798081