From b61cd79b4b80097104660bdd1aa8a485f6f10cec Mon Sep 17 00:00:00 2001 From: sjanusz-r7 Date: Wed, 27 Sep 2023 11:20:17 +0100 Subject: [PATCH] Show errors on inaccessible payload files --- lib/msf/core/payload/stager.rb | 9 ++++----- lib/msf/ui/console/driver.rb | 12 +++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/msf/core/payload/stager.rb b/lib/msf/core/payload/stager.rb index 01840c6cf8368..955b32841d302 100644 --- a/lib/msf/core/payload/stager.rb +++ b/lib/msf/core/payload/stager.rb @@ -188,15 +188,14 @@ def handle_connection(conn, opts={}) end end - p = generate_stage(opts) - - # Encode the stage if stage encoding is enabled + # Generate and encode the stage if stage encoding is enabled begin + p = generate_stage(opts) p = encode_stage(p) - rescue ::RuntimeError + rescue ::RuntimeError => e warning_msg = "Failed to stage" warning_msg << " (#{conn.peerhost})" if conn.respond_to? :peerhost - warning_msg << ": #{$!}" + warning_msg << ": #{e}" print_warning warning_msg if conn.respond_to? :close && !conn.closed? conn.close diff --git a/lib/msf/ui/console/driver.rb b/lib/msf/ui/console/driver.rb index fd3ec84f4daeb..7289906b996f6 100644 --- a/lib/msf/ui/console/driver.rb +++ b/lib/msf/ui/console/driver.rb @@ -364,7 +364,17 @@ def on_startup(opts = {}) run_single("banner") unless opts['DisableBanner'] - av_warning_message if framework.eicar_corrupted? + payloads_manifest_errors = ::MetasploitPayloads.manifest_errors + + av_warning_message if (framework.eicar_corrupted? || payloads_manifest_errors.any?) + + if payloads_manifest_errors.any? + warn_msg = "Metasploit Payloads manifest errors:\n" + payloads_manifest_errors.each do |file| + warn_msg << "\t#{file[:path]} : #{file[:error]}\n" + end + $stderr.print(warn_msg) + end opts["Plugins"].each do |plug| run_single("load '#{plug}'")