diff --git a/modules/auxiliary/admin/smb/psexec_command.rb b/modules/auxiliary/admin/smb/psexec_command.rb index 5747494726..593db5af84 100644 --- a/modules/auxiliary/admin/smb/psexec_command.rb +++ b/modules/auxiliary/admin/smb/psexec_command.rb @@ -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