Land #10433, pry and irb in developer dispatcher
parent
abaf059cdb
commit
e2b91bdfc1
|
@ -90,10 +90,6 @@ class Core
|
|||
"-n" => [ true, "Show the last n commands." ],
|
||||
"-c" => [ false, "Clear command history and history file." ])
|
||||
|
||||
@@irb_opts = Rex::Parser::Arguments.new(
|
||||
"-h" => [ false, "Help banner." ],
|
||||
"-e" => [ true, "Expression to evaluate." ])
|
||||
|
||||
# Returns the list of commands supported by this command dispatcher
|
||||
def commands
|
||||
{
|
||||
|
@ -108,7 +104,6 @@ class Core
|
|||
"grep" => "Grep the output of another command",
|
||||
"help" => "Help menu",
|
||||
"history" => "Show command history",
|
||||
"irb" => "Drop into irb scripting mode",
|
||||
"load" => "Load a framework plugin",
|
||||
"quit" => "Exit the console",
|
||||
"route" => "Route traffic through a session",
|
||||
|
@ -551,48 +546,6 @@ class Core
|
|||
Rex::ThreadSafe.sleep(args[0].to_f)
|
||||
end
|
||||
|
||||
def cmd_irb_help
|
||||
print_line "Usage: irb"
|
||||
print_line
|
||||
print_line "Execute commands in a Ruby environment"
|
||||
print @@irb_opts.usage
|
||||
end
|
||||
|
||||
#
|
||||
# Goes into IRB scripting mode
|
||||
#
|
||||
def cmd_irb(*args)
|
||||
expressions = []
|
||||
|
||||
# Parse the command options
|
||||
@@irb_opts.parse(args) do |opt, idx, val|
|
||||
case opt
|
||||
when '-e'
|
||||
expressions << val
|
||||
when '-h'
|
||||
cmd_irb_help
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if expressions.empty?
|
||||
print_status("Starting IRB shell...\n")
|
||||
|
||||
begin
|
||||
Rex::Ui::Text::IrbShell.new(binding).run
|
||||
rescue
|
||||
print_error("Error during IRB: #{$!}\n\n#{$@.join("\n")}")
|
||||
end
|
||||
|
||||
# Reset tab completion
|
||||
if (driver.input.supports_readline)
|
||||
driver.input.reset_tab_completion
|
||||
end
|
||||
else
|
||||
expressions.each { |expression| eval(expression, binding) }
|
||||
end
|
||||
end
|
||||
|
||||
def cmd_threads_help
|
||||
print_line "Usage: threads [options]"
|
||||
print_line
|
||||
|
|
|
@ -4,6 +4,10 @@ class Msf::Ui::Console::CommandDispatcher::Developer
|
|||
|
||||
include Msf::Ui::Console::CommandDispatcher
|
||||
|
||||
@@irb_opts = Rex::Parser::Arguments.new(
|
||||
"-h" => [ false, "Help banner." ],
|
||||
"-e" => [ true, "Expression to evaluate." ])
|
||||
|
||||
def initialize(driver)
|
||||
super
|
||||
end
|
||||
|
@ -14,6 +18,8 @@ class Msf::Ui::Console::CommandDispatcher::Developer
|
|||
|
||||
def commands
|
||||
{
|
||||
'irb' => 'Drop into irb scripting mode',
|
||||
'pry' => 'Open a Pry session on the current module or Framework',
|
||||
'edit' => 'Edit the current module or a file with the preferred editor',
|
||||
'reload_lib' => 'Reload one or more library files from specified paths',
|
||||
'log' => 'Displays framework.log starting at the bottom if possible'
|
||||
|
@ -37,7 +43,7 @@ class Msf::Ui::Console::CommandDispatcher::Developer
|
|||
|
||||
# The file must exist to reach this, so we try our best here
|
||||
if path =~ %r{^(?:\./)?modules/}
|
||||
print_error('Reloading Metasploit modules is not supported (try "reload")')
|
||||
print_error("Reloading Metasploit modules is not supported (try 'reload')")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -45,6 +51,69 @@ class Msf::Ui::Console::CommandDispatcher::Developer
|
|||
load path
|
||||
end
|
||||
|
||||
def cmd_irb_help
|
||||
print_line "Usage: irb"
|
||||
print_line
|
||||
print_line "Execute commands in a Ruby environment"
|
||||
print @@irb_opts.usage
|
||||
end
|
||||
|
||||
#
|
||||
# Goes into IRB scripting mode
|
||||
#
|
||||
def cmd_irb(*args)
|
||||
expressions = []
|
||||
|
||||
# Parse the command options
|
||||
@@irb_opts.parse(args) do |opt, idx, val|
|
||||
case opt
|
||||
when '-e'
|
||||
expressions << val
|
||||
when '-h'
|
||||
cmd_irb_help
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if expressions.empty?
|
||||
print_status("Starting IRB shell...\n")
|
||||
|
||||
begin
|
||||
Rex::Ui::Text::IrbShell.new(binding).run
|
||||
rescue
|
||||
print_error("Error during IRB: #{$!}\n\n#{$@.join("\n")}")
|
||||
end
|
||||
|
||||
# Reset tab completion
|
||||
if (driver.input.supports_readline)
|
||||
driver.input.reset_tab_completion
|
||||
end
|
||||
else
|
||||
expressions.each { |expression| eval(expression, binding) }
|
||||
end
|
||||
end
|
||||
|
||||
def cmd_pry_help
|
||||
print_line 'Usage: pry'
|
||||
print_line
|
||||
print_line 'Open a Pry session on the current module or Framework.'
|
||||
print_line
|
||||
end
|
||||
|
||||
#
|
||||
# Open a Pry session on the current module or Framework
|
||||
#
|
||||
def cmd_pry(*args)
|
||||
begin
|
||||
require 'pry'
|
||||
rescue LoadError
|
||||
print_error("Failed to load Pry, try 'gem install pry'")
|
||||
return
|
||||
end
|
||||
|
||||
active_module ? active_module.pry : framework.pry
|
||||
end
|
||||
|
||||
def cmd_edit_help
|
||||
print_line 'Usage: edit [file/to/edit]'
|
||||
print_line
|
||||
|
|
|
@ -16,7 +16,6 @@ module ModuleCommandDispatcher
|
|||
|
||||
def commands
|
||||
{
|
||||
"pry" => "Open a Pry session on the current module",
|
||||
"reload" => "Reload the current module from disk",
|
||||
"check" => "Check to see if a target is vulnerable"
|
||||
}
|
||||
|
@ -268,24 +267,6 @@ module ModuleCommandDispatcher
|
|||
end
|
||||
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
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue