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
|
2014-12-29 18:02:40 -08:00
|
|
|
include Msf::Auxiliary::Scanner
|
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' =>
|
|
|
|
|
[
|
2013-10-22 21:13:30 -04:00
|
|
|
'mubix' # copied from hdm upload_file module
|
2013-10-22 16:31:56 -04:00
|
|
|
],
|
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
register_options([
|
2014-12-30 09:21:29 -08:00
|
|
|
OptString.new('SMBSHARE', [true, 'The name of a share on the RHOST', 'C$'])
|
2017-05-03 15:42:21 -05:00
|
|
|
])
|
2013-10-22 16:31:56 -04:00
|
|
|
end
|
|
|
|
|
|
2014-12-30 09:21:29 -08:00
|
|
|
def smb_delete_files
|
2016-06-08 12:16:50 -05:00
|
|
|
vprint_status("Connecting to the server...")
|
2013-10-22 16:31:56 -04:00
|
|
|
connect()
|
|
|
|
|
smb_login()
|
|
|
|
|
|
2016-06-08 12:16:50 -05:00
|
|
|
vprint_status("Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
|
2013-10-22 16:31:56 -04:00
|
|
|
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
|
|
|
|
|
|
2014-12-30 09:21:29 -08:00
|
|
|
remote_paths.each do |remote_path|
|
|
|
|
|
begin
|
|
|
|
|
simple.delete("\\#{remote_path}")
|
2013-10-23 12:28:25 -05:00
|
|
|
|
2014-12-30 09:21:29 -08:00
|
|
|
# If there's no exception raised at this point, we assume the file has been removed.
|
2016-06-08 12:16:50 -05:00
|
|
|
print_good("Deleted: #{remote_path}")
|
2014-12-30 09:21:29 -08:00
|
|
|
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
|
2015-12-08 11:06:59 -06:00
|
|
|
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
|
2016-06-08 12:16:50 -05:00
|
|
|
print_error("Cannot delete #{remote_path}: #{e.message}")
|
2014-12-30 09:21:29 -08:00
|
|
|
end
|
|
|
|
|
end
|
2013-10-23 12:28:25 -05:00
|
|
|
end
|
|
|
|
|
|
2014-12-29 18:02:40 -08:00
|
|
|
def run_host(_ip)
|
2013-10-23 12:28:25 -05:00
|
|
|
begin
|
2014-12-30 09:21:29 -08:00
|
|
|
smb_delete_files
|
2013-10-23 12:28:25 -05:00
|
|
|
rescue Rex::Proto::SMB::Exceptions::LoginError => e
|
2015-12-08 11:06:59 -06:00
|
|
|
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
|
2016-06-08 12:16:50 -05:00
|
|
|
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
|