Files
metasploit-gs/lib/msf/ui/console/module_command_dispatcher.rb
T
Luke Imhoff df9db42c32 Fix module reloading
[#36737359]

The merging of reload_module and the various load_module methods
resulted in the module loading from disk, but because the Hash entry in
the module manager was not deleted before on_module_load was called, the
newly reloaded module was logged as an ambiguous module name instead of
a reload.  In order to report the reload errors correctly, I determined
that module_load_error_by_reference_name should really be
module_load_error_by_path.  I eliminated faild in favor of this new name
since failed was just calling the attribute and the attribute's name is
clearer about the format of the data.

Tested by run rexploit and then exiting over and over with
ms08_067_netapi.  When I messed up the file so it couldn't load, by
adding `inclde Exploit` (note mispelling of `include`), it reported the
error to msfconsole.  When I removed the bad line and added a puts
"RELOADING <n>", where I kept incrementing n and saving the file, the
new number appeared during each rexploit.
2012-10-04 16:32:12 -05:00

114 lines
2.0 KiB
Ruby

# -*- coding: binary -*-
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...')
original_mod = self.mod
reloaded_mod = framework.modules.reload_module(original_mod)
unless reloaded_mod
error = framework.modules.module_load_error_by_path[original_mod.file_path]
print_error("Failed to reload module: #{error}")
self.mod = original_mod
else
self.mod = reloaded_mod
self.mod.init_ui(driver.input, driver.output)
end
reloaded_mod
end
end
end end end