Skip to content

Commit 3e1ae4c

Browse files
committed
Land rapid7#2504, @todb-r7's edit command for msfconsole
2 parents b76c13b + 900ccc7 commit 3e1ae4c

File tree

2 files changed

+32
-87
lines changed

2 files changed

+32
-87
lines changed

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

Lines changed: 32 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 $VISUAL or $EDITOR",
110111
"go_pro" => "Launch Metasploit web GUI",
111112
"grep" => "Grep the output of another command",
112113
"help" => "Help menu",
@@ -627,6 +628,37 @@ def cmd_connect(*args)
627628
true
628629
end
629630

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

plugins/editor.rb

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)