Skip to content

Commit ed97751

Browse files
committed
Land rapid7#2999, @j0hnf's modifiction to check_dir_file to handle file:
2 parents 68d8afc + cd45ed0 commit ed97751

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

modules/auxiliary/admin/smb/check_dir_file.rb

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Metasploit3 < Msf::Auxiliary
1111

1212
# Exploit mixins should be called first
1313
include Msf::Exploit::Remote::SMB
14+
include Msf::Exploit::Remote::SMB::Authenticated
1415
include Msf::Auxiliary::Scanner
1516
include Msf::Auxiliary::Report
1617

@@ -33,6 +34,7 @@ def initialize
3334
'Author' =>
3435
[
3536
'patrick',
37+
'j0hn__f'
3638
],
3739
'References' =>
3840
[
@@ -47,44 +49,56 @@ def initialize
4749

4850
end
4951

50-
def run_host(ip)
51-
52-
vprint_status("Connecting to the server...")
53-
52+
def check_path(path)
5453
begin
55-
connect()
56-
smb_login()
57-
58-
vprint_status("Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
59-
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
60-
61-
vprint_status("Checking for file/folder #{datastore['RPATH']}...")
62-
63-
if (fd = simple.open("\\#{datastore['RPATH']}", 'o')) # mode is open only - do not create/append/write etc
64-
print_good("File FOUND: \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']}")
65-
fd.close
66-
end
67-
rescue ::Rex::HostUnreachable
68-
vprint_error("Host #{rhost} offline.")
69-
rescue ::Rex::Proto::SMB::Exceptions::LoginError
70-
vprint_error("Host #{rhost} login error.")
54+
if (fd = simple.open("\\#{path}", 'o')) # mode is open only - do not create/append/write etc
55+
print_good("File FOUND: \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{path}")
56+
fd.close
57+
end
7158
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode => e
72-
if e.get_error(e.error_code) == "STATUS_FILE_IS_A_DIRECTORY"
73-
print_good("Directory FOUND: \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']}")
74-
elsif e.get_error(e.error_code) == "STATUS_OBJECT_NAME_NOT_FOUND"
75-
vprint_error("Object \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']} NOT found!")
76-
elsif e.get_error(e.error_code) == "STATUS_OBJECT_PATH_NOT_FOUND"
77-
vprint_error("Object PATH \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']} NOT found!")
78-
elsif e.get_error(e.error_code) == "STATUS_ACCESS_DENIED"
59+
case e.get_error(e.error_code)
60+
when "STATUS_FILE_IS_A_DIRECTORY"
61+
print_good("Directory FOUND: \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{path}")
62+
when "STATUS_OBJECT_NAME_NOT_FOUND"
63+
vprint_error("Object \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{path} NOT found!")
64+
when "STATUS_OBJECT_PATH_NOT_FOUND"
65+
vprint_error("Object PATH \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{path} NOT found!")
66+
when "STATUS_ACCESS_DENIED"
7967
vprint_error("Host #{rhost} reports access denied.")
80-
elsif e.get_error(e.error_code) == "STATUS_BAD_NETWORK_NAME"
68+
when "STATUS_BAD_NETWORK_NAME"
8169
vprint_error("Host #{rhost} is NOT connected to #{datastore['SMBDomain']}!")
82-
elsif e.get_error(e.error_code) == "STATUS_INSUFF_SERVER_RESOURCES"
70+
when "STATUS_INSUFF_SERVER_RESOURCES"
8371
vprint_error("Host #{rhost} rejected with insufficient resources!")
72+
when "STATUS_OBJECT_NAME_INVALID"
73+
vprint_error("opeining \\#{path} bad filename")
8474
else
8575
raise e
8676
end
8777
end
8878
end
8979

80+
def run_host(ip)
81+
vprint_status("Connecting to the server...")
82+
83+
begin
84+
connect
85+
smb_login
86+
87+
vprint_status("Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
88+
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
89+
vprint_status("Checking for file/folder #{datastore['RPATH']}...")
90+
91+
datastore['RPATH'].each_line do |path|
92+
check_path(path.chomp)
93+
end #end do
94+
rescue ::Rex::HostUnreachable
95+
vprint_error("Host #{rhost} offline.")
96+
rescue ::Rex::Proto::SMB::Exceptions::LoginError
97+
print_error("Host #{rhost} login error.")
98+
rescue ::Rex::ConnectionRefused
99+
print_error "Host #{rhost} unable to connect - connection refused"
100+
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode
101+
print_error "Host #{rhost} unable to connect to share #{datastore['SMBSHARE']}"
102+
end # end begin
103+
end # end def
90104
end

0 commit comments

Comments
 (0)