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/delete_file.rb
Views: 11623
##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::Constants192021def initialize22super(23'Name' => 'SMB File Delete Utility',24'Description' => %Q{25This module deletes a file from a target share and path. The usual reason26to use this module is to work around limitations in an existing SMB client that may not27be able to take advantage of pass-the-hash style authentication.28},29'Author' =>30[31'mubix' # copied from hdm upload_file module32],33'License' => MSF_LICENSE,34)3536register_options([37OptString.new('SMBSHARE', [true, 'The name of a share on the RHOST', 'C$'])38])39end4041def smb_delete_files42if session43print_status("Using existing session #{session.sid}")44client = session.client45self.simple = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)46else47vprint_status("Connecting to the server...")48connect()49smb_login()50end5152vprint_status("Mounting the remote share \\\\#{simple.address}\\#{datastore['SMBSHARE']}'...")53self.simple.connect("\\\\#{simple.address}\\#{datastore['SMBSHARE']}")5455remote_paths.each do |remote_path|56begin57simple.delete("\\#{remote_path}")5859# If there's no exception raised at this point, we assume the file has been removed.60print_good("Deleted: #{remote_path}")61rescue Rex::Proto::SMB::Exceptions::ErrorCode, RubySMB::Error::RubySMBError => e62elog("Cannot delete #{remote_path}:", error: e)63print_error("Cannot delete #{remote_path}: #{e.message}")64end65end66end6768def 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