Land #7556, Prevent psexec_command from dying when one host errors

bug/bundler_fix
wchen-r7 2016-11-15 12:17:01 -06:00
commit f50e609d12
No known key found for this signature in database
GPG Key ID: 2384DB4EF06F730B
1 changed files with 14 additions and 4 deletions

View File

@ -99,9 +99,9 @@ class MetasploitModule < Msf::Auxiliary
print_status("Executing the command...")
begin
return psexec(execute)
rescue Rex::Proto::DCERPC::Exceptions::Error, Rex::Proto::SMB::Exceptions::Error => exec_command_error
rescue Rex::Proto::DCERPC::Exceptions::Error, Rex::Proto::SMB::Exceptions::Error => e
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}", 'rex', LEV_3)
print_error("Unable to execute specified command: #{exec_command_error}")
print_error("Unable to execute specified command: #{e}")
return false
end
end
@ -136,8 +136,13 @@ class MetasploitModule < Msf::Auxiliary
# check if our process is done using these files
def exclusive_access(*files)
begin
simple.connect("\\\\#{@ip}\\#{@smbshare}")
files.each do |file|
rescue Rex::Proto::SMB::Exceptions::ErrorCode => accesserror
print_status("Unable to get handle: #{accesserror}")
return false
end
files.each do |file|
begin
print_status("checking if the file is unlocked")
fd = smb_open(file, 'rwo')
@ -154,7 +159,12 @@ class MetasploitModule < Msf::Auxiliary
# Removes files created during execution.
def cleanup_after(*files)
simple.connect("\\\\#{@ip}\\#{@smbshare}")
begin
simple.connect("\\\\#{@ip}\\#{@smbshare}")
rescue Rex::Proto::SMB::Exceptions::ErrorCode => accesserror
print_error("Unable to connect for cleanup: #{accesserror}. Maybe you'll need to manually remove #{files.join(", ")} from the target.")
return
end
print_status("Executing cleanup...")
files.each do |file|
begin