metasploit-framework/modules/auxiliary/admin/smb/delete_file.rb

76 lines
2.1 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
class Metasploit3 < Msf::Auxiliary
# Exploit mixins should be called first
2015-02-13 23:17:59 +00:00
include Msf::Exploit::Remote::SMB::Client
include Msf::Exploit::Remote::SMB::Client::Authenticated
2015-11-10 02:15:40 +00:00
include Msf::Exploit::Remote::SMB::Client::RemotePaths
include Msf::Auxiliary::Report
include Msf::Auxiliary::Scanner
# 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 18:48:25 +00: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.
},
'Author' =>
[
'mubix' # copied from hdm upload_file module
],
'License' => MSF_LICENSE
)
register_options([
OptString.new('SMBSHARE', [true, 'The name of a share on the RHOST', 'C$'])
], self.class)
end
def peer
"#{rhost}:#{rport}"
end
def smb_delete_files
vprint_status("#{peer}: Connecting to the server...")
connect()
smb_login()
vprint_status("#{peer}: Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
remote_paths.each do |remote_path|
begin
simple.delete("\\#{remote_path}")
2013-10-23 17:28:25 +00:00
# If there's no exception raised at this point, we assume the file has been removed.
2014-12-30 17:38:53 +00:00
print_good("#{peer}: Deleted: #{remote_path}")
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
print_error("#{peer}: Cannot delete #{remote_path}: #{e.message}")
end
end
2013-10-23 17:28:25 +00:00
end
def run_host(_ip)
2013-10-23 17:28:25 +00:00
begin
smb_delete_files
2013-10-23 17:28:25 +00:00
rescue Rex::Proto::SMB::Exceptions::LoginError => e
print_error("#{peer}: Unable to login: #{e.message}")
2013-10-23 17:28:25 +00:00
end
end
end