From 2685aef9ef0625e6ffc843d6b94f1d8b2a56329a Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Wed, 7 Dec 2005 03:06:31 +0000 Subject: [PATCH] command passthru support for msfconsole git-svn-id: file:///home/svn/incoming/trunk@3184 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/ui/console/driver.rb | 26 ++++++++++++++++++++++++++ plugins/msfd.rb | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/msf/ui/console/driver.rb b/lib/msf/ui/console/driver.rb index 9a77da24a1..031b7d8d5c 100644 --- a/lib/msf/ui/console/driver.rb +++ b/lib/msf/ui/console/driver.rb @@ -39,6 +39,13 @@ class Driver < Msf::Ui::Driver # prompt character. The optional hash can take extra values that will # serve to initialize the console driver. # + # The optional hash values can include: + # + # AllowCommandPassthru + # + # Whether or not unknown commands should be passed through and executed by + # the local system. + # def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {}) # Call the parent super(prompt, prompt_char) @@ -79,6 +86,8 @@ class Driver < Msf::Ui::Driver # Process the resource script process_rc_file + # Whether or not command passthru should be allowed + self.command_passthru = (opts['AllowCommandPassthru'] == false) ? false : true end # @@ -205,6 +214,10 @@ class Driver < Msf::Ui::Driver # attr_reader :framework # + # Whether or not commands can be passed through. + # + attr_reader :command_passthru + # # The active module associated with the driver. # attr_accessor :active_module @@ -212,6 +225,19 @@ class Driver < Msf::Ui::Driver protected attr_writer :framework # :nodoc: + attr_writer :command_passthru # :nodoc: + + # + # If an unknown command was passed, try to see if it's a valid local + # executable. This is only allowed if command passthru has been permitted + # + def unknown_command(method, line) + if (command_passthru == true and Rex::FileUtils.find_full_path(method)) + system(line) + else + super + end + end ## # diff --git a/plugins/msfd.rb b/plugins/msfd.rb index 1013c733ab..0a9a62f57d 100644 --- a/plugins/msfd.rb +++ b/plugins/msfd.rb @@ -92,7 +92,8 @@ class Plugin::Msfd < Msf::Plugin Msf::Ui::Console::Driver::DefaultPromptChar, 'Framework' => framework, 'LocalInput' => Rex::Ui::Text::Input::Socket.new(cli), - 'LocalOutput' => Rex::Ui::Text::Output::Socket.new(cli)).run + 'LocalOutput' => Rex::Ui::Text::Output::Socket.new(cli), + 'AllowCommandPassthru' => false).run begin cli.shutdown