Skip to content

Commit f06bdad

Browse files
committed
Land rapid7#8108, load -l to list available plugins
2 parents 01ea526 + 18cdb2f commit f06bdad

File tree

1 file changed

+36
-15
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+36
-15
lines changed

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

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -715,27 +715,34 @@ def cmd_threads_tabs(str, words)
715715
end
716716

717717
def cmd_load_help
718-
print_line "Usage: load <path> [var=val var=val ...]"
718+
print_line "Usage: load <option> [var=val var=val ...]"
719719
print_line
720-
print_line "Loads a plugin from the supplied path. If path is not absolute, first looks"
721-
print_line "in the user's plugin directory (#{Msf::Config.user_plugin_directory}) then"
722-
print_line "in the framework root plugin directory (#{Msf::Config.plugin_directory})."
720+
print_line "Loads a plugin from the supplied path."
721+
print_line "For a list of built-in plugins, do: load -l"
723722
print_line "The optional var=val options are custom parameters that can be passed to plugins."
724723
print_line
725724
end
726725

727-
#
728-
# Loads a plugin from the supplied path. If no absolute path is supplied,
729-
# the framework root plugin directory is used.
730-
#
731-
def cmd_load(*args)
732-
if (args.length == 0)
733-
cmd_load_help
734-
return false
726+
def list_plugins
727+
plugin_directories = {
728+
'Framework' => Msf::Config.plugin_directory,
729+
'User' => Msf::Config.user_plugin_directory
730+
}
731+
732+
plugin_directories.each do |type, plugin_directory|
733+
items = Dir.entries(plugin_directory).keep_if { |n| n.match(/^.+\.rb$/)}
734+
next if items.empty?
735+
print_status("Available #{type} plugins:")
736+
items.each do |item|
737+
print_line(" * #{item.split('.').first}")
738+
end
739+
print_line
735740
end
741+
end
742+
743+
def load_plugin(args)
744+
path = args[0]
736745

737-
# Default to the supplied argument path.
738-
path = args.shift
739746
opts = {
740747
'LocalInput' => driver.input,
741748
'LocalOutput' => driver.output,
@@ -759,7 +766,6 @@ def cmd_load(*args)
759766
# If the following "path" doesn't exist it will be caught when we attempt to load
760767
path = Msf::Config.plugin_directory + File::SEPARATOR + plugin_file_name
761768
end
762-
763769
end
764770

765771
# Load that plugin!
@@ -773,6 +779,21 @@ def cmd_load(*args)
773779
end
774780
end
775781

782+
#
783+
# Loads a plugin from the supplied path. If no absolute path is supplied,
784+
# the framework root plugin directory is used.
785+
#
786+
def cmd_load(*args)
787+
case args[0]
788+
when '-l'
789+
list_plugins
790+
when '-h', nil, ''
791+
cmd_load_help
792+
else
793+
load_plugin(args)
794+
end
795+
end
796+
776797
#
777798
# Tab completion for the load command
778799
#

0 commit comments

Comments
 (0)