From 21604f33e67b341899cdb805ee95e49235239b07 Mon Sep 17 00:00:00 2001 From: James Lee Date: Wed, 24 Aug 2011 21:41:03 +0000 Subject: [PATCH] add a pry command to modules, move the ModuleCommandDispatcher into its own file git-svn-id: file:///home/svn/framework3/trunk@13630 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/ui/console/command_dispatcher.rb | 81 +------------ .../ui/console/command_dispatcher/encoder.rb | 2 +- .../ui/console/module_command_dispatcher.rb | 107 ++++++++++++++++++ 3 files changed, 111 insertions(+), 79 deletions(-) create mode 100644 lib/msf/ui/console/module_command_dispatcher.rb diff --git a/lib/msf/ui/console/command_dispatcher.rb b/lib/msf/ui/console/command_dispatcher.rb index 01541c7a89..ef9fd3ded5 100644 --- a/lib/msf/ui/console/command_dispatcher.rb +++ b/lib/msf/ui/console/command_dispatcher.rb @@ -1,3 +1,4 @@ + module Msf module Ui module Console @@ -84,84 +85,8 @@ module CommandDispatcher attr_accessor :driver end - -### -# -# Module-specific command dispatcher. -# -### -module ModuleCommandDispatcher - - include Msf::Ui::Console::CommandDispatcher - - def commands - { "reload" => "Reload the current module from disk" } - end - - # - # The active driver module, if any. - # - def mod - return driver.active_module - end - - # - # Sets the active driver module. - # - def mod=(m) - self.driver.active_module = m - end - - # - # Reloads the active module - # - def cmd_reload(*args) - begin - reload - rescue - log_error("Failed to reload: #{$!}") - end - end - - @@reload_opts = Rex::Parser::Arguments.new( - '-k' => [ false, 'Stop the current job before reloading.' ], - '-h' => [ false, 'Help banner.' ]) - - def cmd_reload_help - print_line "Usage: reload [-k]" - print_line - print_line "Reloads the current module." - print @@reload_opts.usage - end - - # - # Reload the current module, optionally stopping existing job - # - def reload(should_stop_job=false) - if should_stop_job and mod.job_id - print_status('Stopping existing job...') - - framework.jobs.stop_job(mod.job_id) - mod.job_id = nil - end - - print_status('Reloading module...') - - omod = self.mod - self.mod = framework.modules.reload_module(mod) - - if(not self.mod) - print_error("Failed to reload module: #{framework.modules.failed[omod.file_path]}") - self.mod = omod - return - end - - self.mod.init_ui(driver.input, driver.output) - mod - end - -end - end end end +require 'msf/ui/console/module_command_dispatcher' require 'msf/ui/console/command_dispatcher/core' + diff --git a/lib/msf/ui/console/command_dispatcher/encoder.rb b/lib/msf/ui/console/command_dispatcher/encoder.rb index 56481794ca..7bf4e68090 100644 --- a/lib/msf/ui/console/command_dispatcher/encoder.rb +++ b/lib/msf/ui/console/command_dispatcher/encoder.rb @@ -28,4 +28,4 @@ class Encoder end -end end end end \ No newline at end of file +end end end end diff --git a/lib/msf/ui/console/module_command_dispatcher.rb b/lib/msf/ui/console/module_command_dispatcher.rb new file mode 100644 index 0000000000..95250e823d --- /dev/null +++ b/lib/msf/ui/console/module_command_dispatcher.rb @@ -0,0 +1,107 @@ +require 'msf/ui/console/command_dispatcher' + +module Msf +module Ui +module Console + +### +# +# Module-specific command dispatcher. +# +### +module ModuleCommandDispatcher + + include Msf::Ui::Console::CommandDispatcher + + def commands + { + "pry" => "Open a Pry session on the current module", + "reload" => "Reload the current module from disk" + } + end + + # + # The active driver module, if any. + # + def mod + return driver.active_module + end + + # + # Sets the active driver module. + # + def mod=(m) + self.driver.active_module = m + end + + def cmd_pry_help + print_line "Usage: pry" + print_line + print_line "Open a pry session on the current module. Be careful, you" + print_line "can break things." + print_line + end + + def cmd_pry(*args) + begin + require 'pry' + rescue LoadError + print_error("Failed to load pry, try 'gem install pry'") + return + end + mod.pry + end + + # + # Reloads the active module + # + def cmd_reload(*args) + begin + reload + rescue + log_error("Failed to reload: #{$!}") + end + end + + @@reload_opts = Rex::Parser::Arguments.new( + '-k' => [ false, 'Stop the current job before reloading.' ], + '-h' => [ false, 'Help banner.' ]) + + def cmd_reload_help + print_line "Usage: reload [-k]" + print_line + print_line "Reloads the current module." + print @@reload_opts.usage + end + + # + # Reload the current module, optionally stopping existing job + # + def reload(should_stop_job=false) + if should_stop_job and mod.job_id + print_status('Stopping existing job...') + + framework.jobs.stop_job(mod.job_id) + mod.job_id = nil + end + + print_status('Reloading module...') + + omod = self.mod + self.mod = framework.modules.reload_module(mod) + + if(not self.mod) + print_error("Failed to reload module: #{framework.modules.failed[omod.file_path]}") + self.mod = omod + return + end + + self.mod.init_ui(driver.input, driver.output) + mod + end + +end + + +end end end +