diff --git a/lib/msf/base/sessions/meterpreter.rb b/lib/msf/base/sessions/meterpreter.rb index f75c9e8d53..5368d25003 100644 --- a/lib/msf/base/sessions/meterpreter.rb +++ b/lib/msf/base/sessions/meterpreter.rb @@ -302,11 +302,15 @@ class Meterpreter < Rex::Post::Meterpreter::Client ## # :category: Msf::Session::Scriptable implementors # - # Runs the meterpreter script in the context of a script container + # Runs the Meterpreter script or resource file # def execute_file(full_path, args) - o = Rex::Script::Meterpreter.new(self, full_path) - o.run(args) + # Infer a Meterpreter script by it having an .rb extension + if File.extname(full_path) == ".rb" + Rex::Script::Meterpreter.new(self, full_path).run(args) + else + console.load_resource(full_path) + end end diff --git a/lib/msf/base/sessions/scriptable.rb b/lib/msf/base/sessions/scriptable.rb index 87a44c031f..7c0b1e3798 100644 --- a/lib/msf/base/sessions/scriptable.rb +++ b/lib/msf/base/sessions/scriptable.rb @@ -164,13 +164,17 @@ module Scriptable else full_path = self.class.find_script_path(script_name) - # No path found? Weak. if full_path.nil? print_error("The specified script could not be found: #{script_name}") - return true + return + end + + begin + execute_file(full_path, args) + framework.events.on_session_script_run(self, full_path) + rescue StandardError => e + print_error("Could not execute #{script_name}: #{e.class} #{e}") end - framework.events.on_session_script_run(self, full_path) - execute_file(full_path, args) end end diff --git a/lib/msf/ui/console/driver.rb b/lib/msf/ui/console/driver.rb index fd53c3278b..46c5caad95 100644 --- a/lib/msf/ui/console/driver.rb +++ b/lib/msf/ui/console/driver.rb @@ -313,8 +313,6 @@ class Driver < Msf::Ui::Driver return end - self.active_resource = resource_file - # Process ERB directives first print_status "Processing #{path} for ERB directives." erb = ERB.new(resource_file) @@ -362,8 +360,6 @@ class Driver < Msf::Ui::Driver run_single(line) end end - - self.active_resource = nil end # @@ -507,10 +503,6 @@ class Driver < Msf::Ui::Driver # The active session associated with the driver. # attr_accessor :active_session - # - # The active resource file being processed by the driver - # - attr_accessor :active_resource def stop framework.events.on_ui_stop()