diff --git a/lib/metasploit/framework/data_service/proxy/core.rb b/lib/metasploit/framework/data_service/proxy/core.rb index 4204592279e47..4ead138847d17 100644 --- a/lib/metasploit/framework/data_service/proxy/core.rb +++ b/lib/metasploit/framework/data_service/proxy/core.rb @@ -167,8 +167,7 @@ def data_service_operation(&block) end def log_error(exception, ui_message) - elog "#{ui_message}: #{exception.message}" - exception.backtrace.each { |line| elog "#{line}" } + elog(ui_message, error: exception) # TODO: We should try to surface the original exception, instead of just a generic one. # This should not display the full backtrace, only the message. raise exception diff --git a/lib/metasploit/framework/ntds/parser.rb b/lib/metasploit/framework/ntds/parser.rb index 0ea69821cc5e8..ad9884aaa8dab 100644 --- a/lib/metasploit/framework/ntds/parser.rb +++ b/lib/metasploit/framework/ntds/parser.rb @@ -56,7 +56,7 @@ def pull_batch begin raw_batch_data = channel.read(BATCH_SIZE) rescue EOFError => e - elog("NTDS Parser: Error pulling batch - #{e}") + elog('NTDS Parser: Error pulling batch', error: e) raw_batch_data = nil end raw_batch_data diff --git a/lib/msf/base/sessions/meterpreter.rb b/lib/msf/base/sessions/meterpreter.rb index bf70944d8c19d..e04385f1f5bdc 100644 --- a/lib/msf/base/sessions/meterpreter.rb +++ b/lib/msf/base/sessions/meterpreter.rb @@ -559,7 +559,7 @@ def load_session_info rescue ::Exception => e # Log the error but otherwise ignore it so we don't kill the # session if reporting failed for some reason - elog("Error loading sysinfo: #{e.class}: #{e}") + elog('Error loading sysinfo', error: e) dlog("Call stack:\n#{e.backtrace.join("\n")}") end end diff --git a/lib/msf/base/sessions/pingback.rb b/lib/msf/base/sessions/pingback.rb index f825a8cd974bd..ea38a422d4432 100644 --- a/lib/msf/base/sessions/pingback.rb +++ b/lib/msf/base/sessions/pingback.rb @@ -70,10 +70,7 @@ def uuid_read rescue => e # TODO: Can we have a more specific exception handler? # Test: what if we send no bytes back? What if we send less than 16 bytes? Or more than? - elog("Can't get original UUID") - elog("Exception Class: #{e.class.name}") - elog("Exception Message: #{e.message}") - elog("Exception Backtrace: #{e.backtrace}") + elog('Can\'t get original UUID', error: e) end else print_warning("WARNING: UUID verification and logging is not available, because the database is not active.") diff --git a/lib/msf/base/simple/auxiliary.rb b/lib/msf/base/simple/auxiliary.rb index 9779263b99c6a..1464d9f2bab66 100644 --- a/lib/msf/base/simple/auxiliary.rb +++ b/lib/msf/base/simple/auxiliary.rb @@ -212,9 +212,7 @@ def self.job_run_proc(ctx, &block) end end - elog("Auxiliary failed: #{e.class} #{e}", 'core', LEV_0) - dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3) - + elog('Auxiliary failed', error: e) mod.cleanup end diff --git a/lib/msf/base/simple/evasion.rb b/lib/msf/base/simple/evasion.rb index 1342d8ddeffe7..5d53f7204389d 100644 --- a/lib/msf/base/simple/evasion.rb +++ b/lib/msf/base/simple/evasion.rb @@ -95,8 +95,7 @@ def self.run_simple(oevasion, opts, &block) rescue ::Exception => e evasion.error = e evasion.print_error("evasion failed: #{e}") - elog("Evasion failed (#{evasion.refname}): #{e}", 'core', LEV_0) - dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3) + elog("Evasion failed (#{evasion.refname})", error: e) end nil diff --git a/lib/msf/base/simple/exploit.rb b/lib/msf/base/simple/exploit.rb index 41c6caea4e61b..84550592e36aa 100644 --- a/lib/msf/base/simple/exploit.rb +++ b/lib/msf/base/simple/exploit.rb @@ -150,8 +150,7 @@ def self.exploit_simple(oexploit, opts, &block) rescue ::Exception => e exploit.error = e exploit.print_error("Exploit failed: #{e}") - elog("Exploit failed (#{exploit.refname}): #{e}", 'core', LEV_0) - dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3) + elog("Exploit failed (#{exploit.refname})", error: e) end return driver.session if driver diff --git a/lib/msf/base/simple/post.rb b/lib/msf/base/simple/post.rb index 69554992c1c43..6122d8e08641e 100644 --- a/lib/msf/base/simple/post.rb +++ b/lib/msf/base/simple/post.rb @@ -137,9 +137,7 @@ def self.job_run_proc(ctx) end end - elog("Post failed: #{e.class} #{e}", 'core', LEV_0) - dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_3) - + elog('Post failed', error: e) mod.cleanup return @@ -162,4 +160,3 @@ def self.job_cleanup_proc(ctx) end end - diff --git a/lib/msf/core/auxiliary/scanner.rb b/lib/msf/core/auxiliary/scanner.rb index d2edc3e4bb044..e29c8f1120769 100644 --- a/lib/msf/core/auxiliary/scanner.rb +++ b/lib/msf/core/auxiliary/scanner.rb @@ -124,7 +124,7 @@ def run raise $! rescue ::Exception => e print_status("Error: #{targ}: #{e.class} #{e.message}") - elog("Error running against host #{targ}: #{e.message}\n#{e.backtrace.join("\n")}") + elog("Error running against host #{targ}", error: e) ensure nmod.cleanup end diff --git a/lib/msf/core/db_manager.rb b/lib/msf/core/db_manager.rb index b89e603eb8337..211110af1d344 100644 --- a/lib/msf/core/db_manager.rb +++ b/lib/msf/core/db_manager.rb @@ -169,7 +169,7 @@ def initialize_database_support rescue ::Exception => e self.error = e - elog("DB is not enabled due to load error: #{e}") + elog('DB is not enabled due to load error', error: e) return false end @@ -221,20 +221,24 @@ def init_db(opts) # already true or if framework.db.connect called after_establish_connection. if !! error if error.to_s =~ /RubyGem version.*pg.*0\.11/i - elog("***") - elog("*") - elog("* Metasploit now requires version 0.11 or higher of the 'pg' gem for database support") - elog("* There a three ways to accomplish this upgrade:") - elog("* 1. If you run Metasploit with your system ruby, simply upgrade the gem:") - elog("* $ rvmsudo gem install pg ") - elog("* 2. Use the Community Edition web interface to apply a Software Update") - elog("* 3. Uninstall, download the latest version, and reinstall Metasploit") - elog("*") - elog("***") - elog("") - elog("") + err_msg = <<~ERROR + *** + * + * Metasploit now requires version 0.11 or higher of the 'pg' gem for database support + * There are three ways to accomplish this upgrade: + * 1. If you run Metasploit with your system ruby, simply upgrade the gem: + * $ rvmsudo gem install pg + * 2. Use the Community Edition web interface to apply a Software Update + * 3. Uninstall, download the latest version, and reinstall Metasploit + * + *** + + + ERROR + elog(err_msg) end + # +error+ is not an instance of +Exception+, it is, in fact, a +String+ elog("Failed to connect to the database: #{error}") end diff --git a/lib/msf/core/db_manager/connection.rb b/lib/msf/core/db_manager/connection.rb index 6dd2c17078bc1..d19ed3218e452 100644 --- a/lib/msf/core/db_manager/connection.rb +++ b/lib/msf/core/db_manager/connection.rb @@ -18,8 +18,7 @@ def after_establish_connection migrate rescue ::Exception => exception self.error = exception - elog("DB.connect threw an exception: #{exception}") - dlog("Call stack: #{exception.backtrace.join("\n")}", LEV_1) + elog('DB.connect threw an exception', error: exception) # remove connection to prevent issues when re-establishing connection ActiveRecord::Base.remove_connection @@ -59,8 +58,7 @@ def connect(opts={}) end rescue ::Exception => e self.error = e - elog("DB.connect threw an exception: #{e}") - dlog("Call stack: #{$@.join"\n"}", LEV_1) + elog('DB.connect threw an exception', error: e) return false ensure after_establish_connection @@ -135,7 +133,7 @@ def disconnect self.modules_cached = false rescue ::Exception => e self.error = e - elog("DB.disconnect threw an exception: #{e}") + elog('DB.disconnect threw an exception:', error: e) end end end diff --git a/lib/msf/core/db_manager/migration.rb b/lib/msf/core/db_manager/migration.rb index 4c6430bd5207b..2a6d7ec71cca1 100644 --- a/lib/msf/core/db_manager/migration.rb +++ b/lib/msf/core/db_manager/migration.rb @@ -46,8 +46,7 @@ def migrate(verbose=false) # as StandardError rescue StandardError => error self.error = error - elog("DB.migrate threw an exception: #{error}") - dlog("Call stack:\n#{error.backtrace.join "\n"}") + elog('DB.migrate threw an exception', error: error) end end diff --git a/lib/msf/core/db_manager/module_cache.rb b/lib/msf/core/db_manager/module_cache.rb index 1ede1a095e406..66eb2a14069c6 100644 --- a/lib/msf/core/db_manager/module_cache.rb +++ b/lib/msf/core/db_manager/module_cache.rb @@ -307,8 +307,8 @@ def update_all_module_details next if not obj begin update_module_details(obj) - rescue ::Exception - elog("Error updating module details for #{obj.fullname}: #{$!.class} #{$!}") + rescue ::Exception => e + elog("Error updating module details for #{obj.fullname}", error: e) end end end diff --git a/lib/msf/core/encoded_payload.rb b/lib/msf/core/encoded_payload.rb index 4c734156f614c..1e4f6133c7a9f 100644 --- a/lib/msf/core/encoded_payload.rb +++ b/lib/msf/core/encoded_payload.rb @@ -235,9 +235,8 @@ def encode next_encoder = true break - rescue ::Exception - elog("#{err_start}: Broken encoder #{encoder.refname}: #{$!}", 'core', LEV_0) - dlog("#{err_start}: Call stack\n#{$@.join("\n")}", 'core', LEV_1) + rescue ::Exception => e + elog("Broken encoder #{encoder.refname}", error: e) next_encoder = true break end diff --git a/lib/msf/core/exploit.rb b/lib/msf/core/exploit.rb index 5691d3635c43c..0773efeaf5bda 100644 --- a/lib/msf/core/exploit.rb +++ b/lib/msf/core/exploit.rb @@ -1482,26 +1482,22 @@ def handle_exception e when Rex::ConnectionError self.fail_reason = Msf::Exploit::Failure::Unreachable self.print_error("Exploit failed [#{self.fail_reason}]: #{msg}") - elog("Exploit failed (#{self.refname}): #{msg}", 'core', LEV_0) - dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3) + elog("Exploit failed (#{self.refname}): #{msg}", error: e) when Rex::BindFailed self.fail_reason = Msf::Exploit::Failure::BadConfig self.print_error("Exploit failed [#{self.fail_reason}]: #{msg}") - elog("Exploit failed (#{self.refname}): #{msg}", 'core', LEV_0) - dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3) + elog("Exploit failed (#{self.refname}): #{msg}", error: e) when Timeout::Error self.fail_reason = Msf::Exploit::Failure::TimeoutExpired self.print_error("Exploit failed [#{self.fail_reason}]: #{msg}") - elog("Exploit failed (#{self.refname}): #{msg}", 'core', LEV_0) - dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3) + elog("Exploit failed (#{self.refname}): #{msg}", error: e) when ::Interrupt self.fail_reason = Msf::Exploit::Failure::UserInterrupt self.print_error("Exploit failed [#{self.fail_reason}]: #{msg}") - elog("Exploit failed (#{self.refname}): #{msg}", 'core', LEV_0) - dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3) + elog("Exploit failed (#{self.refname}): #{msg}", error: e) else # Compare as a string since not all error classes may be loaded @@ -1531,8 +1527,7 @@ def handle_exception e self.print_error("Exploit failed [#{self.fail_reason}]: #{msg}") end - elog("Exploit failed (#{self.refname}): #{msg}", 'core', LEV_0) - dlog("Call stack:\n#{e.backtrace.join("\n")}", 'core', LEV_3) + elog("Exploit failed (#{self.refname}): #{msg}", error: e) end # Record the error to various places diff --git a/lib/msf/core/exploit/file_dropper.rb b/lib/msf/core/exploit/file_dropper.rb index a6f0c97c3a27d..fbcd55b9e7e05 100644 --- a/lib/msf/core/exploit/file_dropper.rb +++ b/lib/msf/core/exploit/file_dropper.rb @@ -108,8 +108,7 @@ def cleanup file_rm(file) rescue ::Exception => e vprint_error("Failed to delete #{file}: #{e}") - elog("Failed to delete #{file}: #{e.class}: #{e}") - elog("Call stack:\n#{e.backtrace.join("\n")}") + elog("Failed to delete #{file}", error: e) end end end @@ -125,8 +124,7 @@ def cleanup dir_rm(dir) rescue ::Exception => e vprint_error("Failed to delete #{dir}: #{e}") - elog("Failed to delete #{dir}: #{e.class}: #{e}") - elog("Call stack:\n#{e.backtrace.join("\n")}") + elog("Failed to delete #{dir}", error: e) end end end diff --git a/lib/msf/core/exploit/remote/browser_exploit_server.rb b/lib/msf/core/exploit/remote/browser_exploit_server.rb index a062435bcc983..e32eeef95b3ec 100644 --- a/lib/msf/core/exploit/remote/browser_exploit_server.rb +++ b/lib/msf/core/exploit/remote/browser_exploit_server.rb @@ -601,7 +601,7 @@ def on_request_uri(cli, request) begin method(:on_request_exploit).call(cli, request, browser_info) rescue BESException => e - elog("BESException: #{e.message}\n#{e.backtrace * "\n"}") + elog('BESException', error: e) send_not_found(cli) print_error("BESException: #{e.message}") end diff --git a/lib/msf/core/exploit/smb/client/psexec.rb b/lib/msf/core/exploit/smb/client/psexec.rb index 2fec215607dc4..832b353b9068f 100644 --- a/lib/msf/core/exploit/smb/client/psexec.rb +++ b/lib/msf/core/exploit/smb/client/psexec.rb @@ -227,7 +227,7 @@ def execute_command(text, bat, cmd) begin return psexec(execute) rescue Rex::Proto::DCERPC::Exceptions::Error, Rex::Proto::SMB::Exceptions::Error => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}", 'rex', LEV_3) + elog('Unable to execute specified command', 'rex', LEV_3, error: e) print_error("Unable to execute specified command: #{e}") return false end diff --git a/lib/msf/core/framework.rb b/lib/msf/core/framework.rb index e1d9d7a0d8586..e732dc1a5d887 100644 --- a/lib/msf/core/framework.rb +++ b/lib/msf/core/framework.rb @@ -386,8 +386,7 @@ def session_event(name, session, opts={}) address = session.session_host if not (address and address.length > 0) - elog("Session with no session_host/target_host/tunnel_peer") - dlog("#{session.inspect}", LEV_3) + elog("Session with no session_host/target_host/tunnel_peer. Session Info: #{session.inspect}") return end diff --git a/lib/msf/core/handler.rb b/lib/msf/core/handler.rb index 4a4afaa0d2932..0b984f41007f9 100644 --- a/lib/msf/core/handler.rb +++ b/lib/msf/core/handler.rb @@ -210,7 +210,7 @@ def create_session(conn, opts={}) rescue ::Exception => e # We just wanna show and log the error, not trying to swallow it. print_error("#{e.class} #{e.message}") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog('Could not allocate a new Session.', error: e) raise e end diff --git a/lib/msf/core/handler/bind_named_pipe.rb b/lib/msf/core/handler/bind_named_pipe.rb index f74b8cbe30550..b9dc626416524 100644 --- a/lib/msf/core/handler/bind_named_pipe.rb +++ b/lib/msf/core/handler/bind_named_pipe.rb @@ -352,7 +352,7 @@ def start_handler begin session = handle_connection(simple_copy.pipe, opts) rescue => e - elog("Exception raised from BindNamedPipe.handle_connection: #{$!}") + elog('Exception raised from BindNamedPipe.handle_connection', error: e) end } } diff --git a/lib/msf/core/handler/bind_tcp.rb b/lib/msf/core/handler/bind_tcp.rb index ed91f62c4fa4f..419707bb15bc9 100644 --- a/lib/msf/core/handler/bind_tcp.rb +++ b/lib/msf/core/handler/bind_tcp.rb @@ -163,8 +163,8 @@ def start_handler conn_threads << framework.threads.spawn("BindTcpHandlerSession", false, client) { |client_copy| begin handle_connection(wrap_aes_socket(client_copy), opts) - rescue - elog("Exception raised from BindTcp.handle_connection: #{$!}") + rescue => e + elog('Exception raised from BindTcp.handle_connection', error: e) end } else diff --git a/lib/msf/core/handler/bind_udp.rb b/lib/msf/core/handler/bind_udp.rb index 392a66d5bb13b..48a8ada8740ea 100644 --- a/lib/msf/core/handler/bind_udp.rb +++ b/lib/msf/core/handler/bind_udp.rb @@ -182,8 +182,8 @@ def start_handler conn_threads << framework.threads.spawn("BindUdpHandlerSession", false, client) { |client_copy| begin handle_connection(client_copy, opts) - rescue - elog("Exception raised from BindUdp.handle_connection: #{$!}") + rescue => e + elog('Exception raised from BindUdp.handle_connection', error: e) end } else diff --git a/lib/msf/core/handler/reverse_tcp.rb b/lib/msf/core/handler/reverse_tcp.rb index 2cba8cf02a566..f2a11da33824a 100644 --- a/lib/msf/core/handler/reverse_tcp.rb +++ b/lib/msf/core/handler/reverse_tcp.rb @@ -159,8 +159,8 @@ def start_handler else handle_connection(wrap_aes_socket(client), opts) end - rescue StandardError - elog("Exception raised from handle_connection: #{$ERROR_INFO.class}: #{$ERROR_INFO}\n\n#{$ERROR_POSITION.join("\n")}") + rescue StandardError => e + elog('Exception raised from handle_connection', error: e) end end } diff --git a/lib/msf/core/handler/reverse_tcp_double.rb b/lib/msf/core/handler/reverse_tcp_double.rb index f4f845f6d7f0e..9445687fb5f8b 100644 --- a/lib/msf/core/handler/reverse_tcp_double.rb +++ b/lib/msf/core/handler/reverse_tcp_double.rb @@ -97,8 +97,8 @@ def start_handler sock_inp, sock_out = detect_input_output(client_a_copy, client_b_copy) chan = TcpReverseDoubleSessionChannel.new(framework, sock_inp, sock_out) handle_connection(chan.lsock, { datastore: datastore }) - rescue - elog("Exception raised from handle_connection: #{$!}\n\n#{$@.join("\n")}") + rescue => e + elog('Exception raised from handle_connection', error: e) end } end while true diff --git a/lib/msf/core/handler/reverse_tcp_double_ssl.rb b/lib/msf/core/handler/reverse_tcp_double_ssl.rb index 3a7daa0e1b45b..d60423f1ad73e 100644 --- a/lib/msf/core/handler/reverse_tcp_double_ssl.rb +++ b/lib/msf/core/handler/reverse_tcp_double_ssl.rb @@ -146,8 +146,8 @@ def start_handler sock_inp, sock_out = detect_input_output(client_a_copy, client_b_copy) chan = TcpReverseDoubleSSLSessionChannel.new(framework, sock_inp, sock_out) handle_connection(chan.lsock, { datastore: datastore }) - rescue - elog("Exception raised from handle_connection: #{$!}\n\n#{$@.join("\n")}") + rescue => e + elog('Exception raised from handle_connection', error: e) end } end while true diff --git a/lib/msf/core/handler/reverse_udp.rb b/lib/msf/core/handler/reverse_udp.rb index f6560f5cb4018..7dd8fa926796e 100644 --- a/lib/msf/core/handler/reverse_udp.rb +++ b/lib/msf/core/handler/reverse_udp.rb @@ -222,8 +222,8 @@ def start_handler else handle_connection(client, opts) end - rescue ::Exception - elog("Exception raised from handle_connection: #{$!.class}: #{$!}\n\n#{$@.join("\n")}") + rescue ::Exception => e + elog('Exception raised from handle_connection', error: e) end end } diff --git a/lib/msf/core/module/external.rb b/lib/msf/core/module/external.rb index 6f4ca01acded8..09de99a3c334f 100644 --- a/lib/msf/core/module/external.rb +++ b/lib/msf/core/module/external.rb @@ -19,7 +19,7 @@ def execute_module(path, method: :run, args: datastore, fail_on_exit: true) rescue Interrupt => e raise e rescue Exception => e - elog e.backtrace.join("\n") + elog('Unable to execute External Module', error: e) fail_with Msf::Module::Failure::Unknown, e.message end end diff --git a/lib/msf/core/modules/loader/base.rb b/lib/msf/core/modules/loader/base.rb index e0f798140988b..66196ec086f12 100644 --- a/lib/msf/core/modules/loader/base.rb +++ b/lib/msf/core/modules/loader/base.rb @@ -304,7 +304,7 @@ def reload_module(original_metasploit_class_or_instance) reloaded_module_instance.datastore.update(original_metasploit_instance.datastore) end else - elog("Failed to create instance of #{original_metasploit_class_or_instance.refname} after reload.", 'core') + elog("Failed to create instance of #{original_metasploit_class_or_instance.refname} after reload.") # Return the old module instance to avoid an strace trace return original_metasploit_class_or_instance diff --git a/lib/msf/core/modules/loader/executable.rb b/lib/msf/core/modules/loader/executable.rb index 6ebfad73819b0..5a16c8c736047 100644 --- a/lib/msf/core/modules/loader/executable.rb +++ b/lib/msf/core/modules/loader/executable.rb @@ -93,7 +93,7 @@ def read_module_content(parent_path, type, module_reference_name) return '' end rescue ::Exception => e - elog "Unable to load module #{full_path} #{e.class} #{e} #{e.backtrace.join "\n"}" + elog("Unable to load module #{full_path}", error: e) # XXX migrate this to a full load_error when we can tell the user why the # module did not load and/or how to resolve it. # load_error(full_path, e) diff --git a/lib/msf/core/modules/metadata/cache.rb b/lib/msf/core/modules/metadata/cache.rb index d9346336dcaae..e5de81addd76f 100644 --- a/lib/msf/core/modules/metadata/cache.rb +++ b/lib/msf/core/modules/metadata/cache.rb @@ -76,7 +76,7 @@ def refresh_metadata(module_sets) refresh_metadata_instance_internal(module_instance) has_changes = true rescue Exception => e - elog("Error updating module details for #{module_instance.fullname}: #{$!.class} #{$!} : #{e.message}") + elog("Error updating module details for #{module_instance.fullname}", error: e) end end end diff --git a/lib/msf/core/modules/metadata/store.rb b/lib/msf/core/modules/metadata/store.rb index d47561ae8cf48..5eb35b412a615 100644 --- a/lib/msf/core/modules/metadata/store.rb +++ b/lib/msf/core/modules/metadata/store.rb @@ -39,7 +39,7 @@ def update_store end } rescue => e - elog("Unable to update metadata store: #{e.message}") + elog('Unable to update metadata store', error: e) end end @@ -60,7 +60,7 @@ def load_metadata retry else @console.print_warning('Unable to load module metadata from disk see error log') - elog("Unable to load module metadata: #{e.message}") + elog('Unable to load module metadata', error: e) end end @@ -120,10 +120,9 @@ def load_cache_from_file_store begin @module_metadata_cache[k] = Msf::Modules::Metadata::Obj.from_hash(v) rescue => e - elog("Unable to load module metadata object with key: #{k}") + elog("Unable to load module metadata object with key: #{k}", error: e) end } end end - diff --git a/lib/msf/core/post/windows/dotnet.rb b/lib/msf/core/post/windows/dotnet.rb index 49e60c3cc0e2b..21f5cabff19cb 100644 --- a/lib/msf/core/post/windows/dotnet.rb +++ b/lib/msf/core/post/windows/dotnet.rb @@ -21,7 +21,7 @@ def search_for_version(dotnet_subkey) subkeys = registry_enumvals(dotnet_subkey) rescue Rex::Post::Meterpreter::RequestError => e print_status("Encountered exception in search_for_version: #{e.class} #{e}") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end unless subkeys.nil? subkeys.each do |subkey| @@ -44,7 +44,7 @@ def get_versionception(dotnet_vkey) subkeys = registry_enumkeys(dotnet_vkey) rescue Rex::Post::Meterpreter::RequestError => e print_status("Encountered exception in get_versionception: #{e.class} #{e}") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end unless subkeys.nil? subkeys.each do |subkey| @@ -69,7 +69,7 @@ def get_dotnet_versions dotnet_keys = registry_enumkeys(key) rescue Rex::Post::Meterpreter::RequestError => e print_status("Encountered exception in get_dotnet_version: #{e.class} #{e}") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end unless dotnet_keys.nil? dotnet_keys.each do |temp_key| diff --git a/lib/msf/core/post/windows/priv.rb b/lib/msf/core/post/windows/priv.rb index 0e3b5d4ee1c4f..662b2a3de8312 100644 --- a/lib/msf/core/post/windows/priv.rb +++ b/lib/msf/core/post/windows/priv.rb @@ -78,7 +78,7 @@ def steal_token(computer_name, user_name) rescue Rex::Post::Meterpreter::RequestError => e # It could raise an exception even when the token is successfully stolen, # so we will just log the exception and move on. - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end true diff --git a/lib/msf/core/rpc/v10/rpc_plugin.rb b/lib/msf/core/rpc/v10/rpc_plugin.rb index e8160ab5de568..8145c42913f37 100644 --- a/lib/msf/core/rpc/v10/rpc_plugin.rb +++ b/lib/msf/core/rpc/v10/rpc_plugin.rb @@ -41,7 +41,7 @@ def rpc_load(path, xopts = {}) return { "result" => "success" } end rescue ::Exception => e - elog("Error loading plugin #{path}: #{e}\n\n#{e.backtrace.join("\n")}", 'core', 0) + elog("Error loading plugin #{path}:", error: e) return { "result" => "failure" } end diff --git a/lib/msf/core/rpc/v10/service.rb b/lib/msf/core/rpc/v10/service.rb index 24ed976756612..8966942ded2b2 100644 --- a/lib/msf/core/rpc/v10/service.rb +++ b/lib/msf/core/rpc/v10/service.rb @@ -92,7 +92,7 @@ def on_request_uri(cli, req) begin res.body = process(req).to_msgpack rescue Msf::RPC::Exception => e - elog("RPC Exception: #{e.class} #{e} #{e.backtrace} #{cli.inspect} #{req.inspect}") + elog('RPC Exception', error: e) res.body = process_exception(e).to_msgpack res.code = e.code end @@ -155,7 +155,7 @@ def process(req) ::Timeout.timeout(self.dispatcher_timeout) { self.handlers[group].send(mname, *msg) } rescue ::Exception => e - elog("RPC Exception: #{e.class} #{e.to_s} #{e.backtrace} #{msg.inspect} #{req.inspect}") + elog('RPC Exception', error: e) process_exception(e) end end diff --git a/lib/msf/core/session_manager.rb b/lib/msf/core/session_manager.rb index 2db050ec6f001..7554ed4b3aff1 100644 --- a/lib/msf/core/session_manager.rb +++ b/lib/msf/core/session_manager.rb @@ -138,8 +138,7 @@ def initialize(framework) # rescue ::Exception => e respawn_cnt += 1 - elog("Exception #{respawn_cnt}/#{respawn_max} in monitor thread #{e.class} #{e}") - elog("Call stack: \n#{e.backtrace.join("\n")}") + elog("Exception #{respawn_cnt}/#{respawn_max} in monitor thread", error: e) if respawn_cnt < respawn_max ::IO.select(nil, nil, nil, 10.0) retry diff --git a/lib/msf/core/thread_manager.rb b/lib/msf/core/thread_manager.rb index 4bbaca75e954a..afe1313953314 100644 --- a/lib/msf/core/thread_manager.rb +++ b/lib/msf/core/thread_manager.rb @@ -84,7 +84,7 @@ def spawn_monitor end rescue ::Exception => e - elog("thread monitor: #{e} #{e.backtrace} source:#{self[:tm_call].inspect}") + elog("Thread Monitor Exception | Source: #{self[:tm_call].inspect}", error: e) end end end @@ -106,12 +106,11 @@ def spawn(name, crit, *args, &block) argv.shift.call(*argv) rescue ::Exception => e elog( - "thread exception: #{::Thread.current[:tm_name]} critical=#{::Thread.current[:tm_crit]} " \ - "error: #{e.class} #{e}\n" \ + "Thread Exception: #{::Thread.current[:tm_name]} critical=#{::Thread.current[:tm_crit]} " \ " source:\n" \ - " #{::Thread.current[:tm_call].join "\n "}" + " #{::Thread.current[:tm_call].join "\n "}", + error: e ) - elog("Call Stack\n#{e.backtrace.join("\n")}") raise e ensure if framework.db && framework.db.active && framework.db.is_local? diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 4eb639d025f53..85530b33af10d 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -779,7 +779,7 @@ def load_plugin(args) print_status("Successfully loaded plugin: #{inst.name}") end rescue ::Exception => e - elog("Error loading plugin #{path}: #{e}\n\n#{e.backtrace.join("\n")}", 'core', 0) + elog("Error loading plugin #{path}", error: e) print_error("Failed to load plugin from #{path}: #{e}") end end @@ -1005,7 +1005,7 @@ def cmd_route(*args) cmd_route_help end rescue => error - elog("#{error}\n\n#{error.backtrace.join("\n")}") + elog(error) print_error(error.message) end end @@ -1632,7 +1632,7 @@ def cmd_set(*args) end rescue OptionValidateError => e print_error(e.message) - elog(e.message) + elog('Exception encountered in cmd_set', error: e) end # Set PAYLOAD from TARGET diff --git a/lib/msf/ui/console/command_dispatcher/db.rb b/lib/msf/ui/console/command_dispatcher/db.rb index 9575105bdb028..47a34403c2ffa 100644 --- a/lib/msf/ui/console/command_dispatcher/db.rb +++ b/lib/msf/ui/console/command_dispatcher/db.rb @@ -1500,15 +1500,15 @@ def cmd_db_import(*args) print_error("Please note that there were #{warnings} warnings") if warnings > 1 print_error("Please note that there was one warning") if warnings == 1 - rescue Msf::DBImportError + rescue Msf::DBImportError => e print_error("Failed to import #{filename}: #{$!}") - elog("Failed to import #{filename}: #{$!.class}: #{$!}") + elog("Failed to import #{filename}", error: e) dlog("Call stack: #{$@.join("\n")}", LEV_3) next rescue REXML::ParseException => e print_error("Failed to import #{filename} due to malformed XML:") print_error("#{e.class}: #{e}") - elog("Failed to import #{filename}: #{e.class}: #{e}") + elog("Failed to import #{filename}", error: e) dlog("Call stack: #{$@.join("\n")}", LEV_3) next end diff --git a/lib/msf/ui/console/command_dispatcher/evasion.rb b/lib/msf/ui/console/command_dispatcher/evasion.rb index dba8d46914d1a..e6ca5d75bdb78 100644 --- a/lib/msf/ui/console/command_dispatcher/evasion.rb +++ b/lib/msf/ui/console/command_dispatcher/evasion.rb @@ -36,7 +36,7 @@ def cmd_run(*args) print_error('Evasion interrupted by the console user') rescue ::Exception => e print_error("Evasion failed: #{e.class} #{e}") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog('Evasion Failed', error: e) end end diff --git a/lib/msf/ui/console/module_command_dispatcher.rb b/lib/msf/ui/console/module_command_dispatcher.rb index 45d0c070d74ba..cbafc746fdfa3 100644 --- a/lib/msf/ui/console/module_command_dispatcher.rb +++ b/lib/msf/ui/console/module_command_dispatcher.rb @@ -105,7 +105,7 @@ def check_multiple(hosts) if exception.kind_of?(::Interrupt) raise exception else - elog("#{exception} #{exception.class}:\n#{exception.backtrace.join("\n")}") + elog('Error encountered with first Thread', error: exception) end end @@ -252,20 +252,20 @@ def check_simple(instance=nil) rescue ::Rex::ConnectionError, ::Rex::ConnectionProxyError, ::Errno::ECONNRESET, ::Errno::EINTR, ::Rex::TimeoutError, ::Timeout::Error => e # Connection issues while running check should be handled by the module print_error("Check failed: #{e.class} #{e}") - elog("#{e.message}\n#{e.backtrace.join("\n")}") + elog('Check Failed', error: e) rescue ::Msf::Exploit::Failed => e # Handle fail_with and other designated exploit failures print_error("Check failed: #{e.class} #{e}") - elog("#{e.message}\n#{e.backtrace.join("\n")}") + elog('Check Failed', error: e) rescue ::RuntimeError => e # Some modules raise RuntimeError but we don't necessarily care about those when we run check() - elog("#{e.message}\n#{e.backtrace.join("\n")}") + elog('Check Failed', error: e) rescue ::NotImplementedError => e print_error(e.message) - elog("#{e.message}\n#{e.backtrace.join("\n")}") + elog('Check Failed', error: e) rescue ::Exception => e print_error("Check failed: #{e.class} #{e}") - elog("#{e.message}\n#{e.backtrace.join("\n")}") + elog('Check Failed', error: e) end end diff --git a/lib/rex/json_hash_file.rb b/lib/rex/json_hash_file.rb index fc282d057c44c..dc1afe02ab1e6 100644 --- a/lib/rex/json_hash_file.rb +++ b/lib/rex/json_hash_file.rb @@ -85,7 +85,7 @@ def parse_data(data) begin JSON.parse(data) rescue JSON::ParserError => e - # elog("JSONHashFile @ #{path} was corrupt: #{e.class} #{e}" + elog("JSONHashFile at #{path} was corrupt", error: e) {} end end diff --git a/lib/rex/logging/log_dispatcher.rb b/lib/rex/logging/log_dispatcher.rb index e816e57608521..2cd3345d81e9b 100644 --- a/lib/rex/logging/log_dispatcher.rb +++ b/lib/rex/logging/log_dispatcher.rb @@ -108,7 +108,7 @@ def set_level(src, level) # This method returns the log level threshold of a given source. # def get_level(src) - log_levels[src] + log_levels.fetch(src, DEFAULT_LOG_LEVEL) end attr_accessor :log_sinks, :log_sinks_lock # :nodoc: @@ -118,8 +118,6 @@ def get_level(src) end end -### -# # An instance of the log dispatcher exists in the global namespace, along # with stubs for many of the common logging methods. Various sources can # register themselves as a log sink such that logs can be directed at @@ -130,12 +128,47 @@ def get_level(src) ### ExceptionCallStack = "__EXCEPTCALLSTACK__" +BACKTRACE_LOG_LEVEL = 3 # Equal to LEV_3 +DEFAULT_LOG_LEVEL = 0 # Equal to LEV_3 + def dlog(msg, src = 'core', level = 0) $dispatcher.log(LOG_DEBUG, src, level, msg) end -def elog(msg, src = 'core', level = 0) - $dispatcher.log(LOG_ERROR, src, level, msg) +# Logs errors in a standard format for each Log Level. +# +# @param msg [String] Contains message from the developer explaining why an error was encountered. +# Can also be an +Exception+, in which case a log is built from the +Exception+ with no accompanying message. +# +# @param src [String] Used to indicate where the error is originating from. Most commonly set to 'core'. +# +# @param log_level [Integer] Indicates the level of logging the message should be recorded at. If log_level is greater than +# the global log level set for +src+, then the log is not recorded. +# +# @param error [Exception] Exception of an error that needs to be logged. For all log messages, the class and message of +# an exception is added to a log message. If the global log level set for +src+ is greater than +BACKTRACE_LOG_LEVEL+, +# then the stack trace for an error is also added to the log message. +# +# (Eg Loop Iterations, Variables, Function Calls). +# +# @return [NilClass]. +def elog(msg, src = 'core', log_level = 0, error: nil) + error = msg.is_a?(Exception) ? msg : error + + if error.nil? || !error.is_a?(Exception) + $dispatcher.log(LOG_ERROR, src, log_level, msg) + else + error_details = "#{error.class} #{error.message}" + if get_log_level(src) >= BACKTRACE_LOG_LEVEL + error_details << "\nCall stack:\n#{error.backtrace.join("\n")}" + end + + if msg.is_a?(Exception) + $dispatcher.log(LOG_ERROR, src, log_level,"#{error_details}") + else + $dispatcher.log(LOG_ERROR, src, log_level,"#{msg} - #{error_details}") + end + end end def wlog(msg, src = 'core', level = 0) diff --git a/lib/rex/post/hwbridge/ui/console/command_dispatcher.rb b/lib/rex/post/hwbridge/ui/console/command_dispatcher.rb index a9d6d65a28ee2..978af818580f6 100644 --- a/lib/rex/post/hwbridge/ui/console/command_dispatcher.rb +++ b/lib/rex/post/hwbridge/ui/console/command_dispatcher.rb @@ -73,9 +73,7 @@ def msf_loaded? def log_error(msg) print_error(msg) - elog(msg, 'hwbridge') - - dlog("Call stack:\n#{$@.join("\n")}", 'hwbridge') + elog(msg, 'hwbridge', error: $!) end end diff --git a/lib/rex/post/hwbridge/ui/console/command_dispatcher/automotive.rb b/lib/rex/post/hwbridge/ui/console/command_dispatcher/automotive.rb index bdb57793965d8..16ccb61df9912 100644 --- a/lib/rex/post/hwbridge/ui/console/command_dispatcher/automotive.rb +++ b/lib/rex/post/hwbridge/ui/console/command_dispatcher/automotive.rb @@ -310,10 +310,9 @@ def cmd_testerpresent(*args) client.automotive.cansend(bus, id, "023E00") sleep(2) end - rescue ::Exception - print_error("Error in TesterPResent: #{$!.class} #{$!}") - elog("Error in TesterPreset: #{$!.class} #{$!}") - dlog("Callstack: #{$@.join("\n")}") + rescue ::Exception => e + print_error('Error in TesterPresent') + elog('Error in TesterPreset', error: e) end self.tpjobs[myjid] = nil print_status("TesterPreset #{myjid} has stopped (#{::Thread.current[:args].inspect})") diff --git a/lib/rex/post/hwbridge/ui/console/command_dispatcher/core.rb b/lib/rex/post/hwbridge/ui/console/command_dispatcher/core.rb index 124ee8ca55eec..4309b0e1c61d4 100644 --- a/lib/rex/post/hwbridge/ui/console/command_dispatcher/core.rb +++ b/lib/rex/post/hwbridge/ui/console/command_dispatcher/core.rb @@ -402,10 +402,9 @@ def cmd_run(*args) # the rest of the arguments get passed in through the binding client.execute_script(script_name, args) end - rescue - print_error("Error in script: #{$!.class} #{$!}") - elog("Error in script: #{$!.class} #{$!}") - dlog("Callstack: #{$@.join("\n")}") + rescue => e + print_error("Error in script: #{script_name}") + elog("Error in script: #{script_name}", error: e) end end @@ -451,11 +450,11 @@ def cmd_bgrun(*args) ::Thread.current[:args] = xargs.dup begin # the rest of the arguments get passed in through the binding - client.execute_script(args.shift, args) - rescue ::Exception - print_error("Error in script: #{$!.class} #{$!}") - elog("Error in script: #{$!.class} #{$!}") - dlog("Callstack: #{$@.join("\n")}") + script_name = args.shift + client.execute_script(script_name, args) + rescue ::Exception => e + print_error("Error in script: #{script_name}") + elog("Error in script #{script_name}", error: e) end self.bgjobs[myjid] = nil print_status("Background script with Job ID #{myjid} has completed (#{::Thread.current[:args].inspect})") diff --git a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb index 366cd8f09c3d0..577975aef6ded 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb @@ -157,7 +157,7 @@ def init_video_chat(remote_browser_path, server, channel, offerer_id) write_file("#{tmp_dir}\\interface.html", interface) write_file("#{tmp_dir}\\api.js", api) rescue RuntimeError => e - elog("webcam_chat failed. #{e.class} #{e}") + elog('webcam_chat failed', error: e) raise "Unable to initialize the interface on the target machine" end @@ -175,7 +175,7 @@ def init_video_chat(remote_browser_path, server, channel, offerer_id) begin write_file(profile_path, setting) rescue RuntimeError => e - elog("webcam_chat failed: #{e.class} #{e}") + elog('webcam_chat failed', error: e) raise "Unable to write the necessary setting for Firefox." end args = "-p #{profile_name}" @@ -186,7 +186,7 @@ def init_video_chat(remote_browser_path, server, channel, offerer_id) begin session.sys.process.execute(remote_browser_path, "#{args} #{tmp_dir}\\interface.html", exec_opts) rescue RuntimeError => e - elog("webcam_chat failed. #{e.class} #{e}") + elog('webcam_chat failed', error: e) raise "Unable to start the remote browser: #{e.message}" end end diff --git a/lib/rex/post/meterpreter/packet_dispatcher.rb b/lib/rex/post/meterpreter/packet_dispatcher.rb index ef464ac5d8891..a55badce65a26 100644 --- a/lib/rex/post/meterpreter/packet_dispatcher.rb +++ b/lib/rex/post/meterpreter/packet_dispatcher.rb @@ -96,7 +96,7 @@ def on_passive_request(cli, req) cli.send_response(resp) rescue => e send_queue.unshift(resp) if resp - elog("Exception sending a reply to the reader request: #{cli.inspect} #{e.class} #{e} #{e.backtrace}") + elog("Exception sending a reply to the reader request #{cli.inspect}", error: e) end end @@ -416,7 +416,7 @@ def monitor_socket # If we have any packets that weren't handled, they go back # on the incomplete queue so that they're prioritised over # new packets that are coming in off the wire. - dlog("Requeuing #{incomplete.length} packet(s)", 'meterpreter', LEV_1) if incomplete.length > 0 + dlog("Requeuing #{incomplete.length} packet(s)", 'meterpreter', LEV_1) if incomplete.length > 0 while incomplete.length > 0 @incomplete_queue << incomplete.shift end @@ -663,7 +663,7 @@ def on_passive_request(cli, req) cli.send_response(resp) rescue ::Exception => e send_queue.unshift(rpkt) if rpkt - elog("Exception sending a reply to the reader request: #{cli.inspect} #{e.class} #{e} #{e.backtrace}") + elog("Exception sending a reply to the reader request #{cli.inspect}", error: e) end else resp.body = "" @@ -678,7 +678,7 @@ def on_passive_request(cli, req) end rescue ::Exception => e - elog("Exception handling request: #{cli.inspect} #{req.inspect} #{e.class} #{e} #{e.backtrace}") + elog("Exception handling request: #{cli.inspect} #{req.inspect}", error: e) end end diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb index bbb438c4584b2..35c889befd82a 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb @@ -1177,9 +1177,9 @@ def cmd_migrate(*args) begin server = client.sys.process.open rescue TimeoutError => e - elog(e.to_s) + elog('Server Timeout', error: e) rescue RequestError => e - elog(e.to_s) + elog('Request Error', error: e) end service = client.pfservice @@ -1445,10 +1445,9 @@ def cmd_run(*args) # the rest of the arguments get passed in through the binding client.execute_script(script_name, args) end - rescue - print_error("Error in script: #{$!.class} #{$!}") - elog("Error in script: #{$!.class} #{$!}") - dlog("Callstack: #{$@.join("\n")}") + rescue => e + print_error("Error in script: #{script_name}") + elog("Error in script: #{script_name}", error: e) end end @@ -1499,11 +1498,11 @@ def cmd_bgrun(*args) ::Thread.current[:args] = xargs.dup begin # the rest of the arguments get passed in through the binding - client.execute_script(args.shift, args) - rescue ::Exception - print_error("Error in script: #{$!.class} #{$!}") - elog("Error in script: #{$!.class} #{$!}") - dlog("Callstack: #{$@.join("\n")}") + script_name = args.shift + client.execute_script(script_name, args) + rescue ::Exception => e + print_error("Error in script: #{script_name}") + elog("Error in script: #{script_name}", error: e) end self.bgjobs[myjid] = nil print_status("Background script with Job ID #{myjid} has completed (#{::Thread.current[:args].inspect})") @@ -1849,4 +1848,3 @@ def tab_complete_channels end end end - diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb index 18172d0416b2d..181b253a3ac3d 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb @@ -106,7 +106,7 @@ def cmd_getsystem( *args ) translate_technique_index(technique).each do |desc| print_error(desc) end - elog("#{e.class} #{e.message} (Technique: #{technique})\n#{e.backtrace * "\n"}") + elog("Technique: #{technique})", error: e) return end diff --git a/lib/rex/proto/dcerpc/svcctl/packet.rb b/lib/rex/proto/dcerpc/svcctl/packet.rb index f0ad1a9f4c9a9..678c450cc531e 100644 --- a/lib/rex/proto/dcerpc/svcctl/packet.rb +++ b/lib/rex/proto/dcerpc/svcctl/packet.rb @@ -56,7 +56,7 @@ def openscmanagerw(rhost, access = SC_MANAGER_ALL_ACCESS) end end rescue Rex::Proto::DCERPC::Exceptions::Fault => e - elog("Error getting scm handle: #{e}") + elog('Error getting scm handle', error: e) end [scm_handle, scm_status] @@ -120,7 +120,7 @@ def createservicew(scm_handle, service_name, display_name, binary_path, opts) begin response = dcerpc_client.call(CREATE_SERVICE_W, stubdata) rescue Rex::Proto::DCERPC::Exceptions::Fault => e - elog("Error creating service: #{e}") + elog('Error creating service', error: e) end if response @@ -152,7 +152,7 @@ def changeservicedescription(svc_handle, service_description) response = dcerpc_client.call(CHANGE_SERVICE_CONFIG2_W, stubdata) # ChangeServiceConfig2 svc_status = error_code(response) rescue Rex::Proto::DCERPC::Exceptions::Fault => e - elog("Error changing service description : #{e}") + elog('Error changing service description', error: e) end svc_status @@ -172,7 +172,7 @@ def closehandle(handle) svc_status = error_code(response) end rescue Rex::Proto::DCERPC::Exceptions::Fault => e - elog("Error closing service handle: #{e}") + elog('Error closing service handle', error: e) end svc_status @@ -198,7 +198,7 @@ def openservicew(scm_handle, service_name, access = SERVICE_ALL_ACCESS) end end rescue Rex::Proto::DCERPC::Exceptions::Fault => e - elog("Error opening service handle: #{e}") + elog('Error opening service handle', error: e) end svc_handle @@ -250,7 +250,7 @@ def startservice(svc_handle, args=[]) svc_status = error_code(response) end rescue Rex::Proto::DCERPC::Exceptions::Fault => e - elog("Error starting service: #{e}") + elog('Error starting service', error: e) end svc_status @@ -280,7 +280,7 @@ def controlservice(svc_handle, operation) svc_status = error_code(response[28,4]) end rescue Rex::Proto::DCERPC::Exceptions::Fault => e - elog("Error controlling service: #{e}") + elog('Error controlling service', error: e) end svc_status @@ -299,7 +299,7 @@ def deleteservice(svc_handle) svc_status = error_code(response) end rescue Rex::Proto::DCERPC::Exceptions::Fault => e - elog("Error deleting service: #{e}") + elog('Error deleting service', error: e) end svc_status @@ -323,7 +323,7 @@ def queryservice(svc_handle) ret = 2 end rescue Rex::Proto::DCERPC::Exceptions::Fault => e - elog("Error deleting service: #{e}") + elog('Error deleting service', error: e) end ret diff --git a/lib/rex/proto/http/handler/erb.rb b/lib/rex/proto/http/handler/erb.rb index fa72c820e67f4..600c192945c0c 100644 --- a/lib/rex/proto/http/handler/erb.rb +++ b/lib/rex/proto/http/handler/erb.rb @@ -77,8 +77,8 @@ def on_request(cli, req) end rescue Errno::ENOENT server.send_e404(cli, req) - rescue - elog("Erb::on_request: #{$!}\n#{$@.join("\n")}", LogSource) + rescue => e + elog('Erb::on_request', LogSource, error: e) resp.code = 500 resp.message = "Internal Server Error" diff --git a/lib/rex/proto/http/handler/proc.rb b/lib/rex/proto/http/handler/proc.rb index 6976e14908e26..9cc866e2fcfb0 100644 --- a/lib/rex/proto/http/handler/proc.rb +++ b/lib/rex/proto/http/handler/proc.rb @@ -36,10 +36,10 @@ def relative_resource_required? def on_request(cli, req) begin procedure.call(cli, req) - rescue Errno::EPIPE, ::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED - elog("Proc::on_request: Client closed connection prematurely", LogSource) - rescue - elog("Proc::on_request: #{$!.class}: #{$!}\n\n#{$@.join("\n")}", LogSource) + rescue Errno::EPIPE, ::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED => e + elog('Proc::on_request: Client closed connection prematurely', LogSource, error: e) + rescue => e + elog('Proc::on_request', LogSource, error: e) if self.server and self.server.context exploit = self.server.context['MsfExploit'] if exploit diff --git a/lib/rex/proto/http/response.rb b/lib/rex/proto/http/response.rb index 5994058fadb52..1ed866306fb5d 100644 --- a/lib/rex/proto/http/response.rb +++ b/lib/rex/proto/http/response.rb @@ -126,7 +126,7 @@ def get_json_document begin json = JSON.parse(self.body) rescue JSON::ParserError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end json diff --git a/lib/rex/proto/http/server.rb b/lib/rex/proto/http/server.rb index bf8f35f4bf4b1..0b08f2855db52 100644 --- a/lib/rex/proto/http/server.rb +++ b/lib/rex/proto/http/server.rb @@ -368,8 +368,7 @@ def dispatch_request(cli, request) handler.on_request(cli, request) end else - elog("Failed to find handler for resource: #{request.resource}", - LogSource) + elog("Failed to find handler for resource: #{request.resource}", LogSource) send_e404(cli, request) end diff --git a/lib/rex/services/local_relay.rb b/lib/rex/services/local_relay.rb index c58aebbabdb09..b9f715657c59d 100644 --- a/lib/rex/services/local_relay.rb +++ b/lib/rex/services/local_relay.rb @@ -183,8 +183,8 @@ def start self.relay_thread = Rex::ThreadFactory.spawn("LocalRelay", false) { begin monitor_relays - rescue ::Exception - elog("Error in #{self} monitor_relays: #{$!}", 'rex') + rescue ::Exception => e + elog("Error in #{self} monitor_relays", 'rex', error: e) end } end @@ -494,8 +494,8 @@ def monitor_relays dlog("monitor_relays: closed stream #{e.stream}", 'rex', LEV_3) next - rescue - elog("Error in #{self} monitor_relays select: #{$!.class} #{$!}", 'rex') + rescue => e + elog("Error in #{self} monitor_relays select:", 'rex', error: e) return end @@ -516,8 +516,8 @@ def monitor_relays data = rfd.sysread(65536) rfd.other_stream.on_other_data(data) # If we catch an error, close the connection - rescue ::Exception - elog("Error in #{self} monitor_relays read: #{$!}", 'rex') + rescue ::Exception => e + elog("Error in #{self} monitor_relays read", 'rex', error: e) close_relay_conn(rfd) end end diff --git a/modules/auxiliary/admin/scada/phoenix_command.rb b/modules/auxiliary/admin/scada/phoenix_command.rb index 9dd04bf5aefec..01c0fd8d385fc 100644 --- a/modules/auxiliary/admin/scada/phoenix_command.rb +++ b/modules/auxiliary/admin/scada/phoenix_command.rb @@ -59,7 +59,7 @@ def send_recv_once(data) sock.put(data) buf = sock.get_once || '' rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end bin_to_hex(buf) diff --git a/modules/auxiliary/admin/smb/delete_file.rb b/modules/auxiliary/admin/smb/delete_file.rb index e22fb148f8def..85a3e5039b6d6 100644 --- a/modules/auxiliary/admin/smb/delete_file.rb +++ b/modules/auxiliary/admin/smb/delete_file.rb @@ -53,7 +53,7 @@ def smb_delete_files # If there's no exception raised at this point, we assume the file has been removed. print_good("Deleted: #{remote_path}") rescue Rex::Proto::SMB::Exceptions::ErrorCode => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog("Cannot delete #{remote_path}:", error: e) print_error("Cannot delete #{remote_path}: #{e.message}") end end @@ -63,7 +63,7 @@ def run_host(_ip) begin smb_delete_files rescue Rex::Proto::SMB::Exceptions::LoginError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog('Unable to login', error: e) print_error("Unable to login: #{e.message}") end end diff --git a/modules/auxiliary/admin/smb/download_file.rb b/modules/auxiliary/admin/smb/download_file.rb index 04c81877dad1c..3095d804f4888 100644 --- a/modules/auxiliary/admin/smb/download_file.rb +++ b/modules/auxiliary/admin/smb/download_file.rb @@ -56,7 +56,7 @@ def smb_download path = store_loot("smb.shares.file", "application/octet-stream", rhost, data, fname) print_good("#{remote_path} saved as: #{path}") rescue Rex::Proto::SMB::Exceptions::ErrorCode => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog("Unable to download #{remote_path}:", error: e) print_error("Unable to download #{remote_path}: #{e.message}") end end @@ -66,7 +66,7 @@ def run_host(ip) begin smb_download rescue Rex::Proto::SMB::Exceptions::LoginError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog("Unable to login: #{e.message}", error: e) print_error("Unable to login: #{e.message}") end end diff --git a/modules/auxiliary/admin/smb/upload_file.rb b/modules/auxiliary/admin/smb/upload_file.rb index 85b0b19b25674..309fbe181ca44 100644 --- a/modules/auxiliary/admin/smb/upload_file.rb +++ b/modules/auxiliary/admin/smb/upload_file.rb @@ -64,12 +64,12 @@ def run_host(_ip) print_good("#{local_path} uploaded to #{remote_path}") rescue Rex::Proto::SMB::Exceptions::ErrorCode => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog("Unable to upload #{local_path} to #{remote_path}", error: e) print_error("Unable to upload #{local_path} to #{remote_path} : #{e.message}") end end rescue Rex::Proto::SMB::Exceptions::LoginError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog("Unable to login:", error: e) print_error("Unable to login: #{e.message}") end end diff --git a/modules/auxiliary/dos/misc/ibm_tsm_dos.rb b/modules/auxiliary/dos/misc/ibm_tsm_dos.rb index ad6b7422641bf..a11ebf0978eb6 100644 --- a/modules/auxiliary/dos/misc/ibm_tsm_dos.rb +++ b/modules/auxiliary/dos/misc/ibm_tsm_dos.rb @@ -72,7 +72,7 @@ def run print_status("Packet sent!") rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => ex print_error("Exploit failed: #{ex.class} #{ex.message}") - elog("#{ex.class} #{ex.message}\n#{ex.backtrace * "\n"}") + elog(ex) ensure disconnect end diff --git a/modules/auxiliary/dos/scada/allen_bradley_pccc.rb b/modules/auxiliary/dos/scada/allen_bradley_pccc.rb index fcd22c9b23fa7..800eeec7771b7 100644 --- a/modules/auxiliary/dos/scada/allen_bradley_pccc.rb +++ b/modules/auxiliary/dos/scada/allen_bradley_pccc.rb @@ -168,7 +168,7 @@ def check end rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) ensure disconnect end @@ -202,7 +202,7 @@ def run sock.put(pccc_dos_pkt(enip_session_id, cip_connection_id)) rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) ensure disconnect end diff --git a/modules/auxiliary/scanner/ftp/bison_ftp_traversal.rb b/modules/auxiliary/scanner/ftp/bison_ftp_traversal.rb index 8aa963561d619..ed9df734297e6 100644 --- a/modules/auxiliary/scanner/ftp/bison_ftp_traversal.rb +++ b/modules/auxiliary/scanner/ftp/bison_ftp_traversal.rb @@ -103,10 +103,10 @@ def run_host(target_host) rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) rescue ::Timeout::Error, ::Errno::EPIPE => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) ensure data_disconnect disconnect diff --git a/modules/auxiliary/scanner/ftp/colorado_ftp_traversal.rb b/modules/auxiliary/scanner/ftp/colorado_ftp_traversal.rb index 7a0965a84f00f..03d33f08ef623 100644 --- a/modules/auxiliary/scanner/ftp/colorado_ftp_traversal.rb +++ b/modules/auxiliary/scanner/ftp/colorado_ftp_traversal.rb @@ -87,10 +87,10 @@ def run_host(ip) rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) rescue ::Timeout::Error, ::Errno::EPIPE => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) ensure data_disconnect disconnect diff --git a/modules/auxiliary/scanner/ftp/easy_file_sharing_ftp.rb b/modules/auxiliary/scanner/ftp/easy_file_sharing_ftp.rb index 82ef4f2a939be..51a73d528b19a 100644 --- a/modules/auxiliary/scanner/ftp/easy_file_sharing_ftp.rb +++ b/modules/auxiliary/scanner/ftp/easy_file_sharing_ftp.rb @@ -97,10 +97,10 @@ def run_host(target_host) rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) rescue ::Timeout::Error, ::Errno::EPIPE => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) ensure data_disconnect disconnect diff --git a/modules/auxiliary/scanner/ftp/konica_ftp_traversal.rb b/modules/auxiliary/scanner/ftp/konica_ftp_traversal.rb index 9434975d8e107..a018bf23f4af7 100644 --- a/modules/auxiliary/scanner/ftp/konica_ftp_traversal.rb +++ b/modules/auxiliary/scanner/ftp/konica_ftp_traversal.rb @@ -102,10 +102,10 @@ def run_host(target_host) rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) rescue ::Timeout::Error, ::Errno::EPIPE => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) ensure data_disconnect disconnect diff --git a/modules/auxiliary/scanner/ftp/pcman_ftp_traversal.rb b/modules/auxiliary/scanner/ftp/pcman_ftp_traversal.rb index b12ed9fc2f71c..8942410960401 100644 --- a/modules/auxiliary/scanner/ftp/pcman_ftp_traversal.rb +++ b/modules/auxiliary/scanner/ftp/pcman_ftp_traversal.rb @@ -100,10 +100,10 @@ def run_host(target_host) rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) rescue ::Timeout::Error, ::Errno::EPIPE => e vprint_error(e.message) - elog("#{e.class} #{e.message} #{e.backtrace * "\n"}") + elog(e) ensure data_disconnect disconnect diff --git a/modules/auxiliary/scanner/http/drupal_views_user_enum.rb b/modules/auxiliary/scanner/http/drupal_views_user_enum.rb index 6cc4603e3edd4..82ce6dcc79ea5 100644 --- a/modules/auxiliary/scanner/http/drupal_views_user_enum.rb +++ b/modules/auxiliary/scanner/http/drupal_views_user_enum.rb @@ -109,7 +109,7 @@ def run_host(ip) begin user_list = JSON.parse(res.body) rescue JSON::ParserError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog('Exception encountered parsing JSON response', error: e) return [] end if user_list.empty? diff --git a/modules/auxiliary/scanner/http/elasticsearch_traversal.rb b/modules/auxiliary/scanner/http/elasticsearch_traversal.rb index 041dcceef7933..f484e1cb4108c 100644 --- a/modules/auxiliary/scanner/http/elasticsearch_traversal.rb +++ b/modules/auxiliary/scanner/http/elasticsearch_traversal.rb @@ -106,7 +106,7 @@ def run_host(ip) begin data_hash = JSON.parse(contents) rescue JSON::ParserError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) return end diff --git a/modules/auxiliary/scanner/http/wp_nextgen_galley_file_read.rb b/modules/auxiliary/scanner/http/wp_nextgen_galley_file_read.rb index c49e8b88a2f51..22ad41d8de72f 100644 --- a/modules/auxiliary/scanner/http/wp_nextgen_galley_file_read.rb +++ b/modules/auxiliary/scanner/http/wp_nextgen_galley_file_read.rb @@ -80,7 +80,7 @@ def parse_paths(res) begin j = JSON.parse(res.body) rescue JSON::ParserError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) return [] end diff --git a/modules/auxiliary/scanner/rdp/cve_2019_0708_bluekeep.rb b/modules/auxiliary/scanner/rdp/cve_2019_0708_bluekeep.rb index 1a59145844ce0..54068fa2f3da2 100644 --- a/modules/auxiliary/scanner/rdp/cve_2019_0708_bluekeep.rb +++ b/modules/auxiliary/scanner/rdp/cve_2019_0708_bluekeep.rb @@ -100,7 +100,7 @@ def check_host(_ip) bt = e.backtrace.join("\n") vprint_error("Unexpected error: #{e.message}") vprint_line(bt) - elog("#{e.message}\n#{bt}") + elog(e) rescue RdpCommunicationError vprint_error('Error communicating RDP protocol.') status = Exploit::CheckCode::Unknown @@ -110,7 +110,7 @@ def check_host(_ip) bt = e.backtrace.join("\n") vprint_error("Unexpected error: #{e.message}") vprint_line(bt) - elog("#{e.message}\n#{bt}") + elog(e) ensure rdp_disconnect end diff --git a/modules/auxiliary/scanner/rdp/ms12_020_check.rb b/modules/auxiliary/scanner/rdp/ms12_020_check.rb index 7792ffc90dbff..89d84ba4f4b65 100644 --- a/modules/auxiliary/scanner/rdp/ms12_020_check.rb +++ b/modules/auxiliary/scanner/rdp/ms12_020_check.rb @@ -176,7 +176,7 @@ def check_host(ip) bt = e.backtrace.join("\n") vprint_error("Unexpected error: #{e.message}") vprint_line(bt) - elog("#{e.message}\n#{bt}") + elog(e) ensure disconnect end diff --git a/modules/auxiliary/scanner/smb/smb_uninit_cred.rb b/modules/auxiliary/scanner/smb/smb_uninit_cred.rb index fd5689b03b9b6..90cedc1018ff7 100644 --- a/modules/auxiliary/scanner/smb/smb_uninit_cred.rb +++ b/modules/auxiliary/scanner/smb/smb_uninit_cred.rb @@ -79,7 +79,7 @@ def is_vulnerable?(ip) dcerpc_bind(handle) rescue ::Rex::Proto::SMB::Exceptions::LoginError, ::Rex::Proto::SMB::Exceptions::ErrorCode => e - elog("#{e.message}\n#{e.backtrace * "\n"}") + elog(e) return false rescue Errno::ECONNRESET, ::Rex::Proto::SMB::Exceptions::InvalidType, @@ -87,10 +87,10 @@ def is_vulnerable?(ip) ::Rex::Proto::SMB::Exceptions::InvalidCommand, ::Rex::Proto::SMB::Exceptions::InvalidWordCount, ::Rex::Proto::SMB::Exceptions::NoReply => e - elog("#{e.message}\n#{e.backtrace * "\n"}") + elog(e) return false rescue ::Exception => e - elog("#{e.message}\n#{e.backtrace * "\n"}") + elog(e) return false end @@ -117,14 +117,14 @@ def is_vulnerable?(ip) begin dcerpc.call(0x06, stub) rescue ::Rex::Proto::SMB::Exceptions::ErrorCode => e - elog("#{e.message}\n#{e.backtrace * "\n"}") + elog(e) rescue Errno::ECONNRESET, ::Rex::Proto::SMB::Exceptions::InvalidType, ::Rex::Proto::SMB::Exceptions::ReadPacket, ::Rex::Proto::SMB::Exceptions::InvalidCommand, ::Rex::Proto::SMB::Exceptions::InvalidWordCount, ::Rex::Proto::SMB::Exceptions::NoReply => e - elog("#{e.message}\n#{e.backtrace * "\n"}") + elog(e) rescue ::Exception => e if e.to_s =~ /execution expired/i # So what happens here is that when you trigger the buggy code path, you hit this: diff --git a/modules/auxiliary/scanner/snmp/cnpilot_r_snmp_loot.rb b/modules/auxiliary/scanner/snmp/cnpilot_r_snmp_loot.rb index 53ca11b6b3b4c..38e5380139ecd 100644 --- a/modules/auxiliary/scanner/snmp/cnpilot_r_snmp_loot.rb +++ b/modules/auxiliary/scanner/snmp/cnpilot_r_snmp_loot.rb @@ -135,8 +135,7 @@ def run_host(ip) raise $! rescue ::Exception => e print_error("Unknown error: #{e.class} #{e}") - elog("Unknown error: #{e.class} #{e}") - elog("Call stack:\n#{e.backtrace.join "\n"}") + elog(e) ensure disconnect_snmp end diff --git a/modules/auxiliary/scanner/snmp/epmp1000_snmp_loot.rb b/modules/auxiliary/scanner/snmp/epmp1000_snmp_loot.rb index 5b6b445a02486..e31254ed48ff9 100644 --- a/modules/auxiliary/scanner/snmp/epmp1000_snmp_loot.rb +++ b/modules/auxiliary/scanner/snmp/epmp1000_snmp_loot.rb @@ -159,8 +159,7 @@ def run_host(ip) raise $! rescue ::Exception => e print_error("Unknown error: #{e.class} #{e}") - elog("Unknown error: #{e.class} #{e}") - elog("Call stack:\n#{e.backtrace.join "\n"}") + elog(e) ensure disconnect_snmp end diff --git a/modules/auxiliary/scanner/snmp/sbg6580_enum.rb b/modules/auxiliary/scanner/snmp/sbg6580_enum.rb index 5b2d9a3400f42..06470d15364a7 100644 --- a/modules/auxiliary/scanner/snmp/sbg6580_enum.rb +++ b/modules/auxiliary/scanner/snmp/sbg6580_enum.rb @@ -217,8 +217,7 @@ def run_host(ip) raise $! rescue ::Exception => e print_error("Unknown error: #{e.class} #{e}") - elog("Unknown error: #{e.class} #{e}") - elog("Call stack:\n#{e.backtrace.join "\n"}") + elog(e) ensure disconnect_snmp end diff --git a/modules/auxiliary/scanner/snmp/snmp_enum.rb b/modules/auxiliary/scanner/snmp/snmp_enum.rb index a1fad54228343..20e80a7d517f3 100644 --- a/modules/auxiliary/scanner/snmp/snmp_enum.rb +++ b/modules/auxiliary/scanner/snmp/snmp_enum.rb @@ -869,8 +869,7 @@ def run_host(ip) raise $! rescue ::Exception => e print_error("Unknown error: #{e.class} #{e}") - elog("Unknown error: #{e.class} #{e}") - elog("Call stack:\n#{e.backtrace.join "\n"}") + elog(e) ensure disconnect_snmp end diff --git a/modules/auxiliary/scanner/telnet/telnet_encrypt_overflow.rb b/modules/auxiliary/scanner/telnet/telnet_encrypt_overflow.rb index 7a628b6b0db07..ca22b304edd5a 100644 --- a/modules/auxiliary/scanner/telnet/telnet_encrypt_overflow.rb +++ b/modules/auxiliary/scanner/telnet/telnet_encrypt_overflow.rb @@ -126,13 +126,13 @@ def run_host(ip) end rescue ::Rex::ConnectionError, ::Errno::ECONNRESET => e print_error("A network issue has occurred: #{e.message}") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog('A network issue has occurred', error: e) rescue Timeout::Error => e print_error("#{target_host}:#{rport} Timed out after #{to} seconds") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog("#{target_host}:#{rport} Timed out after #{to} seconds", error: e) rescue ::Exception => e print_error("#{target_host}:#{rport} Error: #{e} #{e.backtrace}") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog("#{target_host}:#{rport} Error: #{e} #{e.backtrace}", error: e) ensure disconnect end diff --git a/modules/auxiliary/scanner/telnet/telnet_version.rb b/modules/auxiliary/scanner/telnet/telnet_version.rb index 727c7f6e6b7a3..7f8d9ca01401b 100644 --- a/modules/auxiliary/scanner/telnet/telnet_version.rb +++ b/modules/auxiliary/scanner/telnet/telnet_version.rb @@ -38,13 +38,13 @@ def run_host(ip) end rescue ::Rex::ConnectionError, ::Errno::ECONNRESET => e print_error("A network issue has occurred: #{e.message}") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog("A network issue has occurred", error: e) rescue Timeout::Error => e print_error("#{target_host}:#{rport}, Server timed out after #{to} seconds. Skipping.") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog("#{target_host}:#{rport}, Server timed out after #{to} seconds. Skipping.", error: e) rescue ::Exception => e print_error("#{e} #{e.backtrace}") - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end end end diff --git a/modules/auxiliary/server/browser_autopwn.rb b/modules/auxiliary/server/browser_autopwn.rb index 675335b11ad58..ee9b49e424d0c 100644 --- a/modules/auxiliary/server/browser_autopwn.rb +++ b/modules/auxiliary/server/browser_autopwn.rb @@ -984,7 +984,7 @@ def record_detection(cli, request) rescue ::Interrupt raise $! rescue ::Exception => e - elog("Reporting failed: #{e.class} : #{e.message} #{e.backtrace}") + elog('Reporting failed', error: e) end end end diff --git a/modules/exploits/linux/local/glibc_origin_expansion_priv_esc.rb b/modules/exploits/linux/local/glibc_origin_expansion_priv_esc.rb index 34e066582b2b6..131dc2d7bf6e8 100644 --- a/modules/exploits/linux/local/glibc_origin_expansion_priv_esc.rb +++ b/modules/exploits/linux/local/glibc_origin_expansion_priv_esc.rb @@ -205,10 +205,9 @@ def exploit begin so = Metasm::ELF.compile_c(cpu, so_stub).encode_string(:lib) - rescue + rescue => e print_error "Metasm encoding failed: #{$ERROR_INFO}" - elog "Metasm encoding failed: #{$ERROR_INFO.class} : #{$ERROR_INFO}" - elog "Call stack:\n#{$ERROR_INFO.backtrace.join "\n"}" + elog('Metasm encoding failed', error: e) fail_with Failure::Unknown, 'Metasm encoding failed' end diff --git a/modules/exploits/linux/local/pkexec.rb b/modules/exploits/linux/local/pkexec.rb index d39e9276b087b..50b329ead03ab 100644 --- a/modules/exploits/linux/local/pkexec.rb +++ b/modules/exploits/linux/local/pkexec.rb @@ -358,10 +358,9 @@ def exploit begin elf = Metasm::ELF.compile_c(cpu, main).encode_string - rescue + rescue => e print_error "Metasm Encoding failed: #{$ERROR_INFO}" - elog "Metasm Encoding failed: #{$ERROR_INFO.class} : #{$ERROR_INFO}" - elog "Call stack:\n#{$ERROR_INFO.backtrace.join("\n")}" + elog('Metasm Encoding failed', error: e) return end diff --git a/modules/exploits/linux/local/udev_netlink.rb b/modules/exploits/linux/local/udev_netlink.rb index c68d25c29a3e3..1cbfcac30861c 100644 --- a/modules/exploits/linux/local/udev_netlink.rb +++ b/modules/exploits/linux/local/udev_netlink.rb @@ -216,10 +216,9 @@ def exploit begin elf = sc.encode_string - rescue - print_error "Metasm Encoding failed: #{$!}" - elog "Metasm Encoding failed: #{$!.class} : #{$!}" - elog "Call stack:\n#{$!.backtrace.join("\n")}" + rescue => e + print_error 'Metasm Encoding failed' + elog('Metasm Encoding failed', error: e) return end diff --git a/modules/exploits/linux/ssh/mercurial_ssh_exec.rb b/modules/exploits/linux/ssh/mercurial_ssh_exec.rb index 3c17c446b0619..426df38d49ba0 100644 --- a/modules/exploits/linux/ssh/mercurial_ssh_exec.rb +++ b/modules/exploits/linux/ssh/mercurial_ssh_exec.rb @@ -126,7 +126,7 @@ def exploit begin ssh.loop unless session_created? rescue Errno::EBADF => e - elog(e.message) + elog(e) end end end diff --git a/modules/exploits/linux/ssh/solarwinds_lem_exec.rb b/modules/exploits/linux/ssh/solarwinds_lem_exec.rb index 882efde143ab2..9915c2926ee38 100644 --- a/modules/exploits/linux/ssh/solarwinds_lem_exec.rb +++ b/modules/exploits/linux/ssh/solarwinds_lem_exec.rb @@ -162,7 +162,7 @@ def exploit begin ssh.loop unless session_created? rescue Errno::EBADF => e - elog(e.message) + elog(e) end end end diff --git a/modules/exploits/multi/misc/legend_bot_exec.rb b/modules/exploits/multi/misc/legend_bot_exec.rb index ecbd3d90c5d2c..6214059b659d4 100644 --- a/modules/exploits/multi/misc/legend_bot_exec.rb +++ b/modules/exploits/multi/misc/legend_bot_exec.rb @@ -101,7 +101,7 @@ def send_msg(sock, data) read_data = sock.get_once(-1, 1) end rescue ::EOFError, ::Timeout::Error, ::Errno::ETIMEDOUT => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end data diff --git a/modules/exploits/multi/misc/w3tw0rk_exec.rb b/modules/exploits/multi/misc/w3tw0rk_exec.rb index 8cfa5760e6b0d..13823f75f8f2a 100644 --- a/modules/exploits/multi/misc/w3tw0rk_exec.rb +++ b/modules/exploits/multi/misc/w3tw0rk_exec.rb @@ -91,7 +91,7 @@ def send_msg(sock, data) read_data = sock.get_once(-1, 1) end rescue ::EOFError, ::Timeout::Error, ::Errno::ETIMEDOUT => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end data diff --git a/modules/exploits/multi/misc/xdh_x_exec.rb b/modules/exploits/multi/misc/xdh_x_exec.rb index bfb09bc05c6d2..479caab84b4c5 100644 --- a/modules/exploits/multi/misc/xdh_x_exec.rb +++ b/modules/exploits/multi/misc/xdh_x_exec.rb @@ -103,7 +103,7 @@ def send_msg(sock, data) read_data = sock.get_once(-1, 1) end rescue ::EOFError, ::Timeout::Error, ::Errno::ETIMEDOUT => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end data diff --git a/modules/exploits/windows/fileformat/adobe_pdf_embedded_exe.rb b/modules/exploits/windows/fileformat/adobe_pdf_embedded_exe.rb index 2c5bb0929c5f3..14cb410a40b23 100644 --- a/modules/exploits/windows/fileformat/adobe_pdf_embedded_exe.rb +++ b/modules/exploits/windows/fileformat/adobe_pdf_embedded_exe.rb @@ -88,15 +88,17 @@ def exploit # Lazy fix: # Similar to the problem with NoMethod -- something we need is missing in the PDF. # But really what happens is the module trusts the PDF too much. - print_error("Sorry, I'm picky. Incompatible PDF structure: #{e.message}. Please try a different PDF template.") - elog("Call stack:\n#{$!.backtrace.join("\n")}") + + # Don't be sorry, you're a beautiful human we all appreciate greatly + print_error("Sorry, I'm picky. Incompatible PDF structure. Please try a different PDF template.") + elog('Sorry, I\'m picky. Incompatible PDF structure', error: e) rescue NoMethodError => e # Lazy fix: # When a NoMethod error is hit, that means that something in the PDF is actually missing, # so we can't parse it. If we can't parse it properly, then we can't garantee the exploit # will work, either. So we might as well just reject it. print_error("Sorry, I'm picky. Incompatible PDF structure, please try a different PDF template.") - elog("Call stack:\n#{$!.backtrace.join("\n")}") + elog('Sorry, I\'m picky. Incompatible PDF structure', error: e) end end diff --git a/modules/exploits/windows/http/geutebrueck_gcore_x64_rce_bo.rb b/modules/exploits/windows/http/geutebrueck_gcore_x64_rce_bo.rb index 5c342e9bed3b5..b2791f9b70382 100644 --- a/modules/exploits/windows/http/geutebrueck_gcore_x64_rce_bo.rb +++ b/modules/exploits/windows/http/geutebrueck_gcore_x64_rce_bo.rb @@ -251,7 +251,7 @@ def exploit print_status('Exploit sent!') buf = sock.get_once || '' rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}\n#{e.fail_with}") + elog('Exception encountered in \'exploit\'', error: e) ensure print_status('Closing socket.') disconnect diff --git a/modules/exploits/windows/local/alpc_taskscheduler.rb b/modules/exploits/windows/local/alpc_taskscheduler.rb index f5ad117494183..3443c8e4e9cc2 100644 --- a/modules/exploits/windows/local/alpc_taskscheduler.rb +++ b/modules/exploits/windows/local/alpc_taskscheduler.rb @@ -105,7 +105,7 @@ def validate_active_host sysinfo['Computer'] true rescue Rex::Post::Meterpreter::RequestError, Rex::TimeoutError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) false end @@ -142,7 +142,7 @@ def exploit inject_magic(process, payload_dll) print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.') rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) print_error(e.message) end end diff --git a/modules/exploits/windows/local/comahawk.rb b/modules/exploits/windows/local/comahawk.rb index d6d6dc6c05c8d..ad997c43de055 100644 --- a/modules/exploits/windows/local/comahawk.rb +++ b/modules/exploits/windows/local/comahawk.rb @@ -107,7 +107,7 @@ def exploit begin cmd_exec('cmd.exe', "/c #{exploit_path} #{payload_path}", 60) rescue Rex::TimeoutError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog('Caught timeout. Exploit may be taking longer or it may have failed.', error: e) print_error("Caught timeout. Exploit may be taking longer or it may have failed.") end vprint_status("Cleaning up #{exploit_path}") @@ -118,7 +118,7 @@ def validate_active_host begin print_status("Attempting to PrivEsc on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}") rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog('Could not connect to session', error: e) raise Msf::Exploit::Failed, 'Could not connect to session' end end @@ -142,7 +142,7 @@ def ensure_clean_destination(path) file_rm(path) print_status("Deleted #{path}") rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) print_error("Unable to delete #{path}") end end diff --git a/modules/exploits/windows/local/cve_2018_8453_win32k_priv_esc.rb b/modules/exploits/windows/local/cve_2018_8453_win32k_priv_esc.rb index 7ba315a8c16cc..c7d4a601455ec 100644 --- a/modules/exploits/windows/local/cve_2018_8453_win32k_priv_esc.rb +++ b/modules/exploits/windows/local/cve_2018_8453_win32k_priv_esc.rb @@ -76,7 +76,7 @@ def write_file_to_target(fname, data) vprint_good("#{fname} written") file_loc rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog('Unable to write file to target', error: e) fail_with(Failure::Unknown, "Writing #{fname} to disk was unsuccessful") end diff --git a/modules/exploits/windows/local/cve_2020_0668_service_tracing.rb b/modules/exploits/windows/local/cve_2020_0668_service_tracing.rb index 9282185d22936..d1d7850d812a8 100644 --- a/modules/exploits/windows/local/cve_2020_0668_service_tracing.rb +++ b/modules/exploits/windows/local/cve_2020_0668_service_tracing.rb @@ -196,7 +196,7 @@ def launch_dll_trigger inject_magic(process) print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.') rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) print_error(e.message) end end @@ -312,7 +312,7 @@ def validate_active_host begin print_status("Attempting to PrivEsc on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}") rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) raise Msf::Exploit::Failed, 'Could not connect to session' end end @@ -362,7 +362,7 @@ def ensure_clean_destination(path) file_rm(path) print_status("Deleted #{path}") rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) print_error("Unable to delete #{path}") end end diff --git a/modules/exploits/windows/local/mov_ss.rb b/modules/exploits/windows/local/mov_ss.rb index 828821a75fdb0..14e6781490222 100644 --- a/modules/exploits/windows/local/mov_ss.rb +++ b/modules/exploits/windows/local/mov_ss.rb @@ -124,7 +124,7 @@ def validate_active_host begin print_status("Attempting to PrivEsc on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}") rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) raise Msf::Exploit::Failed, 'Could not connect to session' end end @@ -151,7 +151,7 @@ def ensure_clean_destination(path) file_rm(path) print_status("Deleted #{path}") rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) print_error("Unable to delete #{path}") end end @@ -193,7 +193,7 @@ def exploit_dll inject_magic(process) print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.') rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) print_error(e.message) end end @@ -208,7 +208,7 @@ def exploit_exe execute_exploit print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.') rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) print_error(e.message) ensure_clean_exploit_destination ensure_clean_payload_destination diff --git a/modules/exploits/windows/local/ms18_8120_win32k_privesc.rb b/modules/exploits/windows/local/ms18_8120_win32k_privesc.rb index d571720ef120f..9607e49006298 100644 --- a/modules/exploits/windows/local/ms18_8120_win32k_privesc.rb +++ b/modules/exploits/windows/local/ms18_8120_win32k_privesc.rb @@ -88,7 +88,7 @@ def write_file_to_target(fname, data) vprint_good("#{fname} written") file_loc rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) fail_with(Failure::Unknown, "Writing #{fname} to disk was unsuccessful") end diff --git a/modules/exploits/windows/local/ntapphelpcachecontrol.rb b/modules/exploits/windows/local/ntapphelpcachecontrol.rb index a49344d35e973..79311f8101a0d 100644 --- a/modules/exploits/windows/local/ntapphelpcachecontrol.rb +++ b/modules/exploits/windows/local/ntapphelpcachecontrol.rb @@ -113,7 +113,7 @@ def prep_exploit_host rescue Rex::Post::Meterpreter::RequestError process = client.sys.process.open rescue ::Exception => e - elog("#{e.message}\nCall stack:\n#{e.backtrace.join("\n")}") + elog(e) end process end diff --git a/modules/exploits/windows/local/persistence_image_exec_options.rb b/modules/exploits/windows/local/persistence_image_exec_options.rb index e8465b7878c54..97b082cf71cda 100644 --- a/modules/exploits/windows/local/persistence_image_exec_options.rb +++ b/modules/exploits/windows/local/persistence_image_exec_options.rb @@ -69,7 +69,7 @@ def validate_active_host begin print_status("Attempting Persistence on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}") rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) raise Msf::Exploit::Failed, 'Could not connect to session' end end diff --git a/modules/exploits/windows/local/ps_wmi_exec.rb b/modules/exploits/windows/local/ps_wmi_exec.rb index 01cf99262f48f..40e39d63b5fd5 100644 --- a/modules/exploits/windows/local/ps_wmi_exec.rb +++ b/modules/exploits/windows/local/ps_wmi_exec.rb @@ -133,7 +133,7 @@ def exploit psh_output = datastore["RHOSTS"] ? psh_exec(script) : psh_exec(script,true,false) print_good(psh_output) rescue Rex::TimeoutError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end vprint_good('PSH WMI exec is complete.') diff --git a/modules/exploits/windows/misc/hp_dataprotector_encrypted_comms.rb b/modules/exploits/windows/misc/hp_dataprotector_encrypted_comms.rb index eb9ad8020ea0c..d62d8021779fe 100644 --- a/modules/exploits/windows/misc/hp_dataprotector_encrypted_comms.rb +++ b/modules/exploits/windows/misc/hp_dataprotector_encrypted_comms.rb @@ -114,7 +114,7 @@ def exploit begin buf = sock.get_once rescue ::EOFError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end print_status("Establishing encrypted channel") diff --git a/modules/post/multi/manage/zip.rb b/modules/post/multi/manage/zip.rb index 94992f57252c6..78ed0208c7548 100644 --- a/modules/post/multi/manage/zip.rb +++ b/modules/post/multi/manage/zip.rb @@ -70,7 +70,7 @@ def steal_token rescue Rex::Post::Meterpreter::RequestError => e # It could raise an exception even when the token is successfully stolen, # so we will just log the exception and move on. - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) end @token_stolen = true diff --git a/modules/post/multi/recon/local_exploit_suggester.rb b/modules/post/multi/recon/local_exploit_suggester.rb index ac2a88bd49615..e30f2321805bf 100644 --- a/modules/post/multi/recon/local_exploit_suggester.rb +++ b/modules/post/multi/recon/local_exploit_suggester.rb @@ -54,7 +54,7 @@ def is_module_platform?(mod) module_platforms.include? platform_obj rescue ArgumentError => e # When not found, find_platform raises an ArgumentError - elog "#{e.class} #{e.message}\n#{e.backtrace * "\n"}" + elog('Could not find a platform', error: e) return false end @@ -144,7 +144,7 @@ def run end rescue Rex::Post::Meterpreter::RequestError => e # Creates a log record in framework.log - elog "#{e.class} #{e.message}\n#{e.backtrace * "\n"}" + elog("#{m.shortname} failed to run", error: e) vprint_error "#{e.class} #{m.shortname} failed to run: #{e.message}" end end diff --git a/modules/post/windows/escalate/unmarshal_cmd_exec.rb b/modules/post/windows/escalate/unmarshal_cmd_exec.rb index 9f08595a6f289..8d39c005badf2 100644 --- a/modules/post/windows/escalate/unmarshal_cmd_exec.rb +++ b/modules/post/windows/escalate/unmarshal_cmd_exec.rb @@ -76,7 +76,7 @@ def validate_active_host begin print_status("Attempting to Run on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}") rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) raise Msf::Exploit::Failed, 'Could not connect to session' end end @@ -103,7 +103,7 @@ def ensure_clean_destination(path) file_rm(path) print_status("Deleted #{path}") rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) print_error("Unable to delete #{path}") end end @@ -157,7 +157,7 @@ def run ensure_clean_destination(exploit_path) ensure_clean_destination(script_path) rescue Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog('Command failed, cleaning up', error: e) print_good('Command failed, cleaning up') print_error(e.message) ensure_clean_destination(exploit_path) diff --git a/modules/post/windows/gather/credentials/heidisql.rb b/modules/post/windows/gather/credentials/heidisql.rb index 841c34ff21ed2..0f24e1fe8e642 100644 --- a/modules/post/windows/gather/credentials/heidisql.rb +++ b/modules/post/windows/gather/credentials/heidisql.rb @@ -153,7 +153,7 @@ def run end end rescue ::Rex::Post::Meterpreter::RequestError => e - elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}") + elog(e) print_error("Cannot Access User SID: #{hive['HKU']} : #{e.message}") end end diff --git a/modules/post/windows/gather/credentials/smartermail.rb b/modules/post/windows/gather/credentials/smartermail.rb index 4a1ba2b2a5f90..2bf5b2f4efd4b 100644 --- a/modules/post/windows/gather/credentials/smartermail.rb +++ b/modules/post/windows/gather/credentials/smartermail.rb @@ -55,7 +55,7 @@ def get_bound_port(data) begin port = JSON.parse(data)['BoundPort'] rescue JSON::ParserError => e - elog("#{e.class} - Unable to parse BoundPort (#{e.message}) #{e.backtrace * "\n"}") + elog('Unable to parse BoundPort', error: e) return nil end diff --git a/plugins/msfd.rb b/plugins/msfd.rb index 653ec6f6724e5..77b17a7e16814 100644 --- a/plugins/msfd.rb +++ b/plugins/msfd.rb @@ -128,8 +128,8 @@ def run(opts={}) 'LocalOutput' => Rex::Ui::Text::Output::Socket.new(cli), 'AllowCommandPassthru' => false, 'DisableBanner' => opts['DisableBanner'] ? true : false).run - rescue - elog("Msfd: Client error: #{$!}\n\n#{$@.join("\n")}", 'core') + rescue => e + elog('Msfd client error', error: e) ensure msg = "Msfd: Closing client connection with #{cli.peerhost}" ilog(msg, 'core') @@ -162,4 +162,3 @@ def cleanup end end - diff --git a/tools/exploit/egghunter.rb b/tools/exploit/egghunter.rb index eb8c2ad2415f3..f5199d3f337a5 100755 --- a/tools/exploit/egghunter.rb +++ b/tools/exploit/egghunter.rb @@ -154,7 +154,7 @@ def list_formats begin driver.run rescue ::Exception => e - elog("#{e.class}: #{e.message}\n#{e.backtrace * "\n"}") + elog(e) $stderr.puts "[x] #{e.class}: #{e.message}" $stderr.puts "[*] If necessary, please refer to framework.log for more details." end diff --git a/tools/payloads/ysoserial/dot_net.rb b/tools/payloads/ysoserial/dot_net.rb index 5871e9a19e4b1..cd6cb5e24d810 100755 --- a/tools/payloads/ysoserial/dot_net.rb +++ b/tools/payloads/ysoserial/dot_net.rb @@ -125,7 +125,7 @@ def run begin driver.run rescue ::Exception => e - elog("#{e.class}: #{e.message}\n#{e.backtrace * "\n"}") + elog(e) $stderr.puts "[x] #{e.class}: #{e.message}" $stderr.puts "[*] If necessary, please refer to framework.log for more details." end