Skip to content

Commit d159aa6

Browse files
Royce DavisRoyce Davis
authored andcommitted
Changed error handeling of command.rb module
1 parent ac518f7 commit d159aa6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

modules/auxiliary/admin/smb/command.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ def run_host(ip)
7373
end
7474

7575
smbshare = datastore['SMBSHARE']
76-
begin
77-
execute_command(smbshare, ip, cmd, text, bat)
76+
77+
if execute_command(smbshare, ip, cmd, text, bat)
7878
get_output(smbshare, ip, text)
79+
else
7980
cleanup_after(smbshare, ip, cmd, text, bat)
80-
rescue
81-
# Something went terribly wrong
8281
return
8382
end
83+
cleanup_after(smbshare, ip, cmd, text, bat)
8484
end
8585

8686

@@ -95,9 +95,10 @@ def execute_command(smbshare, ip, cmd, text, bat)
9595
simple.connect(smbshare)
9696
print_status("Executing your command on host: #{ip}")
9797
psexec(smbshare, execute)
98+
return True
9899
rescue StandardError => execerror
99-
print_error("Unable to execute specified command: #{execerror}")
100-
return execerror
100+
print_error("#{ip} - Unable to execute specified command: #{execerror}")
101+
return False
101102
end
102103
end
103104

@@ -120,7 +121,7 @@ def get_output(smbshare, ip, file)
120121
print_good("Command completed successfuly! Output from: #{ip}\r\n#{output}")
121122
rescue StandardError => output_error
122123
print_error("#{ip} - Error getting command output. #{output_error.class}. #{output_error}.")
123-
return
124+
return output_error
124125
end
125126
end
126127

0 commit comments

Comments
 (0)