Skip to content

Commit fddc2c2

Browse files
committed
Catch the specific exception. Include the error code in the error message.
1 parent 69a4a32 commit fddc2c2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

modules/auxiliary/admin/smb/psexec_command.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ def get_output(file)
138138
def exclusive_access(*files)
139139
begin
140140
simple.connect("\\\\#{@ip}\\#{@smbshare}")
141-
rescue
141+
rescue Rex::Proto::SMB::Exceptions::ErrorCode => accesserror
142+
print_status("Unable to get handle: #{accesserror}")
142143
return false
143144
end
144-
files.each do |file|
145+
files.each do |file|
145146
begin
146147
print_status("checking if the file is unlocked")
147148
fd = smb_open(file, 'rwo')
@@ -154,14 +155,14 @@ def exclusive_access(*files)
154155
end
155156
return true
156157
end
157-
158-
158+
159+
159160
# Removes files created during execution.
160161
def cleanup_after(*files)
161162
begin
162163
simple.connect("\\\\#{@ip}\\#{@smbshare}")
163-
rescue
164-
print_error("Unable to connect for cleanup. Maybe you'll need to manually remove #{left.join(", ")} from the target.")
164+
rescue Rex::Proto::SMB::Exceptions::ErrorCode => accesserror
165+
print_error("Unable to connect for cleanup: #{accesserror}. Maybe you'll need to manually remove #{left.join(", ")} from the target.")
165166
return
166167
end
167168
print_status("Executing cleanup...")

0 commit comments

Comments
 (0)