Files
metasploit-gs/modules/auxiliary/admin/smb/delete_file.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.4 KiB
Ruby
Raw Normal View History

2013-10-22 16:31:56 -04:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-22 16:31:56 -04:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Auxiliary
2013-10-22 16:31:56 -04:00
# Exploit mixins should be called first
2015-02-13 17:17:59 -06:00
include Msf::Exploit::Remote::SMB::Client
include Msf::Exploit::Remote::SMB::Client::Authenticated
2015-11-09 18:15:40 -08:00
include Msf::Exploit::Remote::SMB::Client::RemotePaths
2013-10-22 16:31:56 -04:00
include Msf::Auxiliary::Report
include Msf::Auxiliary::Scanner
include Msf::OptionalSession::SMB
2013-10-22 16:31:56 -04:00
# Aliases for common classes
SIMPLE = Rex::Proto::SMB::SimpleClient
XCEPT = Rex::Proto::SMB::Exceptions
CONST = Rex::Proto::SMB::Constants
def initialize
super(
'Name' => 'SMB File Delete Utility',
'Description' => %Q{
2013-10-28 13:48:25 -05:00
This module deletes a file from a target share and path. The usual reason
to use this module is to work around limitations in an existing SMB client that may not
be able to take advantage of pass-the-hash style authentication.
2013-10-22 16:31:56 -04:00
},
'Author' =>
[
'mubix' # copied from hdm upload_file module
2013-10-22 16:31:56 -04:00
],
'License' => MSF_LICENSE,
)
2013-10-22 16:31:56 -04:00
register_options([
OptString.new('SMBSHARE', [true, 'The name of a share on the RHOST', 'C$'])
])
2013-10-22 16:31:56 -04:00
end
def smb_delete_files
if session
print_status("Using existing session #{session.sid}")
client = session.client
self.simple = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)
else
vprint_status("Connecting to the server...")
connect()
smb_login()
end
2013-10-22 16:31:56 -04:00
vprint_status("Mounting the remote share \\\\#{simple.address}\\#{datastore['SMBSHARE']}'...")
self.simple.connect("\\\\#{simple.address}\\#{datastore['SMBSHARE']}")
2013-10-22 16:31:56 -04:00
remote_paths.each do |remote_path|
begin
simple.delete("\\#{remote_path}")
2013-10-23 12:28:25 -05:00
# If there's no exception raised at this point, we assume the file has been removed.
print_good("Deleted: #{remote_path}")
rescue Rex::Proto::SMB::Exceptions::ErrorCode, RubySMB::Error::RubySMBError => e
elog("Cannot delete #{remote_path}:", error: e)
print_error("Cannot delete #{remote_path}: #{e.message}")
end
end
2013-10-23 12:28:25 -05:00
end
def run_host(_ip)
2021-06-03 11:43:09 +01:00
validate_rpaths!
2013-10-23 12:28:25 -05:00
begin
smb_delete_files
2013-10-23 12:28:25 -05:00
rescue Rex::Proto::SMB::Exceptions::LoginError => e
elog('Unable to login', error: e)
print_error("Unable to login: #{e.message}")
2013-10-23 12:28:25 -05:00
end
2013-10-22 16:31:56 -04:00
end
end