Skip to content

Commit 85b5c5a

Browse files
committed
Refactor check_path
1 parent 1e29bef commit 85b5c5a

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

modules/auxiliary/admin/smb/check_dir_file.rb

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,34 @@ def initialize
4949

5050
end
5151

52+
def check_path(path)
53+
begin
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
58+
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode => e
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"
67+
vprint_error("Host #{rhost} reports access denied.")
68+
when "STATUS_BAD_NETWORK_NAME"
69+
vprint_error("Host #{rhost} is NOT connected to #{datastore['SMBDomain']}!")
70+
when "STATUS_INSUFF_SERVER_RESOURCES"
71+
vprint_error("Host #{rhost} rejected with insufficient resources!")
72+
when "STATUS_OBJECT_NAME_INVALID"
73+
vprint_error("opeining \\#{path} bad filename")
74+
else
75+
raise e
76+
end
77+
end
78+
end
79+
5280
def run_host(ip)
5381
vprint_status("Connecting to the server...")
5482

@@ -61,33 +89,7 @@ def run_host(ip)
6189
vprint_status("Checking for file/folder #{datastore['RPATH']}...")
6290

6391
datastore['RPATH'].each_line do |path|
64-
path.chomp!
65-
66-
begin
67-
if (fd = simple.open("\\#{path.chomp}", 'o')) # mode is open only - do not create/append/write etc
68-
print_good("File FOUND: \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{path}")
69-
fd.close
70-
end
71-
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode => e
72-
case e.get_error(e.error_code)
73-
when "STATUS_FILE_IS_A_DIRECTORY"
74-
print_good("Directory FOUND: \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{path}")
75-
when "STATUS_OBJECT_NAME_NOT_FOUND"
76-
vprint_error("Object \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{path} NOT found!")
77-
when "STATUS_OBJECT_PATH_NOT_FOUND"
78-
vprint_error("Object PATH \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{path} NOT found!")
79-
when "STATUS_ACCESS_DENIED"
80-
vprint_error("Host #{rhost} reports access denied.")
81-
when "STATUS_BAD_NETWORK_NAME"
82-
vprint_error("Host #{rhost} is NOT connected to #{datastore['SMBDomain']}!")
83-
when "STATUS_INSUFF_SERVER_RESOURCES"
84-
vprint_error("Host #{rhost} rejected with insufficient resources!")
85-
when "STATUS_OBJECT_NAME_INVALID"
86-
vprint_error("opeining \\#{path} bad filename")
87-
else
88-
raise e
89-
end
90-
end
92+
check_path(path.chomp)
9193
end #end do
9294
rescue ::Rex::HostUnreachable
9395
vprint_error("Host #{rhost} offline.")

0 commit comments

Comments
 (0)