Skip to content

Commit e16cea6

Browse files
Royce DavisRoyce Davis
authored andcommitted
Fixed execerror, redundant if statement, and poor exception handling
1 parent 795ea5b commit e16cea6

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

modules/auxiliary/admin/smb/command.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def execute_command(smbshare, ip, text, bat)
8181
print_status("Executing your command on host: #{ip}")
8282
psexec(smbshare, execute)
8383
return true
84-
rescue StandardError => execerror
85-
print_error("#{ip} - Unable to execute specified command: #{execerror}")
84+
rescue StandardError => exec_command_cerror
85+
print_error("#{ip} - Unable to execute specified command: #{exec_command_error}")
8686
return false
8787
end
8888
end
@@ -273,18 +273,10 @@ def psexec(smbshare, command)
273273
#print_status("Deleting \\#{filename}...")
274274
select(nil, nil, nil, 1.0)
275275
#This is not really useful but will prevent double \\ on the wire :)
276-
if datastore['SHARE'] =~ /.[\\\/]/
277276
simple.connect(smbshare)
278277
simple.delete("%WINDIR%\\Temp\\msfcommandoutput.txt")
279-
else
280-
simple.connect(smbshare)
281-
simple.delete("%WINDIR%\\Temp\\msfcommandoutput.txt")
282-
end
283-
284-
rescue ::Interrupt
285-
raise $!
286-
rescue ::Exception
287-
#raise $!
278+
rescue StandardError => psexec_cleanup_error
279+
print_error("Error occured cleaning up the service. #{psexec_cleanup_error}")
288280
end
289281
simple.disconnect("IPC$")
290282
simple.disconnect(smbshare)

0 commit comments

Comments
 (0)