@@ -107,6 +107,7 @@ def commands
107
107
"connect" => "Communicate with a host" ,
108
108
"color" => "Toggle color" ,
109
109
"exit" => "Exit the console" ,
110
+ "edit" => "Edit the current module with $VISUAL or $EDITOR" ,
110
111
"go_pro" => "Launch Metasploit web GUI" ,
111
112
"grep" => "Grep the output of another command" ,
112
113
"help" => "Help menu" ,
@@ -627,6 +628,37 @@ def cmd_connect(*args)
627
628
true
628
629
end
629
630
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
+
630
662
#
631
663
# Instructs the driver to stop executing.
632
664
#
0 commit comments