Land #2504, @todb-r7's edit command for msfconsole

bug/bundler_fix
William Vu 2013-10-30 15:38:07 -05:00
commit 3e1ae4c9b3
No known key found for this signature in database
GPG Key ID: E761DCB4C1629024
2 changed files with 32 additions and 87 deletions

View File

@ -107,6 +107,7 @@ class Core
"connect" => "Communicate with a host",
"color" => "Toggle color",
"exit" => "Exit the console",
"edit" => "Edit the current module with $VISUAL or $EDITOR",
"go_pro" => "Launch Metasploit web GUI",
"grep" => "Grep the output of another command",
"help" => "Help menu",
@ -627,6 +628,37 @@ class Core
true
end
def local_editor
Rex::Compat.getenv('VISUAL') || Rex::Compat.getenv('EDITOR') || '/usr/bin/vim'
end
def cmd_edit_help
msg = "Edit the currently active module"
msg = "#{msg} #{local_editor ? "with #{local_editor}" : "($VISUAL or $EDITOR must be set first)"}."
print_line "Usage: edit"
print_line
print_line msg
print_line "When done editing, you must reload the module with 'reload' or 'rexploit'."
print_line
end
#
# Edit the currently active module
#
def cmd_edit
unless local_editor
print_error "$VISUAL or $EDITOR must be set first. Try 'export EDITOR=/usr/bin/vim'"
return
end
if active_module
path = active_module.file_path
print_status "Launching #{local_editor} #{path}"
system(local_editor,path)
else
print_error "Nothing to edit -- try using a module first."
end
end
#
# Instructs the driver to stop executing.
#

View File

@ -1,87 +0,0 @@
#
# $Id$
# $Revision$
#
module Msf
###
#
# This plugin is a simple editor command, designed to make it easy to edit modules in the console.
#
###
class Plugin::Editor < Msf::Plugin
###
#
# This class implements a single edit command.
#
###
class EditorCommandDispatcher
include Msf::Ui::Console::ModuleCommandDispatcher
#
# The dispatcher's name.
#
def name
"Editor"
end
#
# Returns the hash of commands supported by this dispatcher.
#
def commands
# Don't update super here since we don't want the commands from
# super, just the methods
{
"edit" => "A handy editor commmand"
}
end
#
# This method handles the edit command.
#
def cmd_edit(*args)
print_line("Launching editor...")
e = Rex::Compat.getenv("EDITOR") || "vi"
if (not mod) or (not (path = mod.file_path))
print_line("Error: No active module selected")
return nil
end
ret = system(e, path)
if not ret
print_line("Failed to execute your editor (#{e})")
return
end
reload
ret
end
end
def initialize(framework, opts)
super
# console dispatcher commands.
add_console_dispatcher(EditorCommandDispatcher)
end
def cleanup
remove_console_dispatcher('Editor')
end
def name
"editor"
end
def desc
"Simple Editor Plugin"
end
protected
end
end