diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 9e543c75097d8..eaf55cae44c70 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -2614,15 +2614,13 @@ def verify_session(session_id, quiet = false) # Custom error code to handle timeout errors # # @param message [String] The message to be printed when a timeout error is hit - + # @return [Proc] proc function that prints the specified error when the error types match def log_on_timeout_error(message) proc do |e| - handled = false - if e.is_a?(Rex::TimeoutError) || e.is_a?(Timeout::Error) - elog(e) - print_error(message) - :handled - end + next unless e.is_a?(Rex::TimeoutError) || e.is_a?(Timeout::Error) + elog(e) + print_error(message) + :handled end end diff --git a/lib/rex/post/meterpreter/ui/console.rb b/lib/rex/post/meterpreter/ui/console.rb index 3370499f25e96..14077a7e02a48 100644 --- a/lib/rex/post/meterpreter/ui/console.rb +++ b/lib/rex/post/meterpreter/ui/console.rb @@ -101,19 +101,20 @@ def run_command(dispatcher, method, arguments) begin super rescue Exception => e - unless self.client.on_error_proc && self.client.on_error_proc.call(e) == :handled - case e - when Rex::TimeoutError, Rex::InvalidDestination - log_error(e.message) - when Timeout::Error - log_error('Operation timed out.') - when RequestError - log_error(e.to_s) - when ::Errno::EPIPE, ::OpenSSL::SSL::SSLError, ::IOError - self.client.kill - when ::Exception - log_error("Error running command #{method}: #{e.class} #{e}") - end + is_error_handled = self.client.on_error_proc && self.client.on_error_proc.call(e) == :handled + return if is_error_handled + case e + when Rex::TimeoutError, Rex::InvalidDestination + log_error(e.message) + when Timeout::Error + log_error('Operation timed out.') + when RequestError + log_error(e.to_s) + when ::Errno::EPIPE, ::OpenSSL::SSL::SSLError, ::IOError + self.client.kill + when ::Exception + log_error("Error running command #{method}: #{e.class} #{e}") + elog(e) end end end diff --git a/lib/rex/ui/interactive.rb b/lib/rex/ui/interactive.rb index 646d344a3c932..e6d66ab4d5eb5 100644 --- a/lib/rex/ui/interactive.rb +++ b/lib/rex/ui/interactive.rb @@ -131,7 +131,7 @@ def detach # # A function to be run when the session hits an error # - + # @return [Proc,nil] A function to be run when the session hits an error attr_accessor :on_error_proc protected