Skip to content

Commit a7025fc

Browse files
author
Tod Beardsley
committed
msfconsole 'edit' command
Useful for quick editing a module during development / bug fixing. I don't really see a security issue with running a command defined in the user's VISUAL or EDITOR environment variables; if the user can run msfconsole to begin with, there are better ways to get into trouble.
1 parent 49c629b commit a7025fc

File tree

1 file changed

+34
-0
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+34
-0
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def commands
107107
"connect" => "Communicate with a host",
108108
"color" => "Toggle color",
109109
"exit" => "Exit the console",
110+
"edit" => "Edit the current module with $EDITOR",
110111
"go_pro" => "Launch Metasploit web GUI",
111112
"grep" => "Grep the output of another command",
112113
"help" => "Help menu",
@@ -627,6 +628,39 @@ def cmd_connect(*args)
627628
true
628629
end
629630

631+
def cmd_edit_help
632+
editor = ENV['VISUAL'] || ENV['EDITOR']
633+
msg = "Edit the currently active module"
634+
msg = "#{msg} #{editor ? "with #{editor}" : "($EDITOR must be set first)"}."
635+
print_line "Usage: edit"
636+
print_line
637+
print_line msg
638+
print_line "When done editing, you must reload the module with 'reload' or 'rexploit'."
639+
print_line
640+
end
641+
642+
#
643+
# Edit the currently active module
644+
#
645+
def cmd_edit
646+
editor = ENV['VISUAL'] || ENV['EDITOR']
647+
unless editor
648+
print_error "$EDITOR must be set first. Try 'export EDITOR=/usr/bin/vim'"
649+
return
650+
end
651+
unless ::File.executable_real? editor
652+
print_error "#{editor} doesn't seem to be executable by you."
653+
return
654+
end
655+
if active_module
656+
path = active_module.file_path
657+
print_status "Launching #{editor} #{path}"
658+
system(editor,path)
659+
else
660+
print_error "Nothing to edit -- try using a module first."
661+
end
662+
end
663+
630664
#
631665
# Instructs the driver to stop executing.
632666
#

0 commit comments

Comments
 (0)