2011-08-18 04:10:17 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-08-18 04:10:17 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
# Exploit mixins should be called first
|
|
|
|
include Msf::Exploit::Remote::SMB
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
# Aliases for common classes
|
|
|
|
SIMPLE = Rex::Proto::SMB::SimpleClient
|
|
|
|
XCEPT = Rex::Proto::SMB::Exceptions
|
|
|
|
CONST = Rex::Proto::SMB::Constants
|
|
|
|
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'SMB Scanner Check File/Directory Utility',
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Description' => %Q{
|
|
|
|
This module is useful when checking an entire network
|
|
|
|
of SMB hosts for the presence of a known file or directory.
|
|
|
|
An example would be to scan all systems for the presence of
|
|
|
|
antivirus or known malware outbreak. Typically you must set
|
2011-10-17 02:42:01 +00:00
|
|
|
RPATH, SMBUser, SMBDomain and SMBPass to operate correctly.
|
2011-08-18 04:10:17 +00:00
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'patrick',
|
|
|
|
],
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options([
|
|
|
|
OptString.new('SMBSHARE', [true, 'The name of an accessible share on the server', 'C$']),
|
2012-02-18 03:07:44 +00:00
|
|
|
OptString.new('RPATH', [true, 'The name of the remote file/directory relative to the share'])
|
2011-08-18 04:10:17 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_status("Connecting to the server...")
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2011-08-18 04:10:17 +00:00
|
|
|
begin
|
|
|
|
connect()
|
|
|
|
smb_login()
|
|
|
|
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_status("Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
|
2011-08-18 04:10:17 +00:00
|
|
|
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
|
|
|
|
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_status("Checking for file/folder #{datastore['RPATH']}...")
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2011-08-18 04:10:17 +00:00
|
|
|
if (fd = simple.open("\\#{datastore['RPATH']}", 'o')) # mode is open only - do not create/append/write etc
|
|
|
|
print_good("File FOUND: \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']}")
|
|
|
|
fd.close
|
|
|
|
end
|
|
|
|
rescue ::Rex::HostUnreachable
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_error("Host #{rhost} offline.")
|
2011-08-18 04:10:17 +00:00
|
|
|
rescue ::Rex::Proto::SMB::Exceptions::LoginError
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_error("Host #{rhost} login error.")
|
2011-08-18 04:10:17 +00:00
|
|
|
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode => e
|
|
|
|
if e.get_error(e.error_code) == "STATUS_FILE_IS_A_DIRECTORY"
|
|
|
|
print_good("Directory FOUND: \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']}")
|
|
|
|
elsif e.get_error(e.error_code) == "STATUS_OBJECT_NAME_NOT_FOUND"
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_error("Object \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']} NOT found!")
|
2011-08-18 04:10:17 +00:00
|
|
|
elsif e.get_error(e.error_code) == "STATUS_OBJECT_PATH_NOT_FOUND"
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_error("Object PATH \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']} NOT found!")
|
2011-08-18 04:10:17 +00:00
|
|
|
elsif e.get_error(e.error_code) == "STATUS_ACCESS_DENIED"
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_error("Host #{rhost} reports access denied.")
|
2011-08-18 04:10:17 +00:00
|
|
|
elsif e.get_error(e.error_code) == "STATUS_BAD_NETWORK_NAME"
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_error("Host #{rhost} is NOT connected to #{datastore['SMBDomain']}!")
|
2011-08-18 04:10:17 +00:00
|
|
|
elsif e.get_error(e.error_code) == "STATUS_INSUFF_SERVER_RESOURCES"
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_error("Host #{rhost} rejected with insufficient resources!")
|
2011-08-18 04:10:17 +00:00
|
|
|
else
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|