Skip to content

Commit f734031

Browse files
author
Brent Cook
committed
Land rapid7#7655, Refactor/cleanup core command dispatcher
2 parents 66363f1 + d091a32 commit f734031

File tree

10 files changed

+1794
-1611
lines changed

10 files changed

+1794
-1611
lines changed

features/commands/help.feature

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: Help command
22

33
Background:
4-
Given I run `msfconsole --defer-module-loads -x help -x exit`
4+
Given I run `msfconsole --defer-module-loads -q -x help -x exit`
55

66
Scenario: The 'help' command's output
77
Then the output should contain:
@@ -12,51 +12,72 @@ Feature: Help command
1212
Command Description
1313
------- -----------
1414
? Help menu
15-
advanced Displays advanced options for one or more modules
16-
back Move back from the current context
1715
banner Display an awesome metasploit banner
1816
cd Change the current working directory
1917
color Toggle color
2018
connect Communicate with a host
21-
edit Edit the current module with $VISUAL or $EDITOR
2219
exit Exit the console
2320
get Gets the value of a context-specific variable
2421
getg Gets the value of a global variable
2522
grep Grep the output of another command
2623
help Help menu
27-
info Displays information about one or more modules
2824
irb Drop into irb scripting mode
29-
jobs Displays and manages jobs
30-
kill Kill a job
3125
load Load a framework plugin
32-
loadpath Searches for and loads modules from a path
33-
makerc Save commands entered since start to a file
34-
options Displays global options or for one or more modules
35-
popm Pops the latest module off the stack and makes it active
36-
previous Sets the previously loaded module as the current module
37-
pushm Pushes the active or list of modules onto the module stack
3826
quit Exit the console
39-
reload_all Reloads all modules from all defined module paths
40-
rename_job Rename a job
41-
resource Run the commands stored in a file
4227
route Route traffic through a session
4328
save Saves the active datastores
44-
search Searches module names and descriptions
4529
sess Interact with a given session
4630
sessions Dump session listings and display information about sessions
4731
set Sets a context-specific variable to a value
4832
setg Sets a global variable to a value
49-
show Displays modules of a given type, or all modules
5033
sleep Do nothing for the specified number of seconds
5134
spool Write console output into a file as well the screen
5235
threads View and manipulate background threads
5336
unload Unload a framework plugin
5437
unset Unsets one or more context-specific variables
5538
unsetg Unsets one or more global variables
56-
use Selects a module by name
5739
version Show the framework and console library version numbers
5840
5941
42+
Module Commands
43+
===============
44+
45+
Command Description
46+
------- -----------
47+
advanced Displays advanced options for one or more modules
48+
back Move back from the current context
49+
edit Edit the current module with $VISUAL or $EDITOR
50+
info Displays information about one or more modules
51+
loadpath Searches for and loads modules from a path
52+
options Displays global options or for one or more modules
53+
popm Pops the latest module off the stack and makes it active
54+
previous Sets the previously loaded module as the current module
55+
pushm Pushes the active or list of modules onto the module stack
56+
reload_all Reloads all modules from all defined module paths
57+
search Searches module names and descriptions
58+
show Displays modules of a given type, or all modules
59+
use Selects a module by name
60+
61+
62+
Job Commands
63+
============
64+
65+
Command Description
66+
------- -----------
67+
jobs Displays and manages jobs
68+
kill Kill a job
69+
rename_job Rename a job
70+
71+
72+
Resource Script Commands
73+
========================
74+
75+
Command Description
76+
------- -----------
77+
makerc Save commands entered since start to a file
78+
resource Run the commands stored in a file
79+
80+
6081
Database Backend Commands
6182
=========================
6283

lib/msf/ui/console/command_dispatcher.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,36 @@ def log_error(err)
7474
dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_1)
7575
end
7676

77+
#
78+
# Generate an array of job or session IDs from a given range String.
79+
# Always returns an Array.
80+
#
81+
# @param id_list [String] Range or list description such as 1-5 or 1,3,5 etc
82+
# @return [Array<String>] Representing the range
83+
def build_range_array(id_list)
84+
item_list = []
85+
unless id_list.blank?
86+
temp_list = id_list.split(',')
87+
temp_list.each do |ele|
88+
return if ele.count('-') > 1
89+
return if ele.first == '-' || ele[-1] == '-'
90+
return if ele.first == '.' || ele[-1] == '.'
91+
92+
if ele.include? '-'
93+
temp_array = (ele.split("-").inject { |s, e| s.to_i..e.to_i }).to_a
94+
item_list.concat(temp_array)
95+
elsif ele.include? '..'
96+
temp_array = (ele.split("..").inject { |s, e| s.to_i..e.to_i }).to_a
97+
item_list.concat(temp_array)
98+
else
99+
item_list.push(ele.to_i)
100+
end
101+
end
102+
end
103+
104+
item_list.uniq.sort
105+
end
106+
77107
#
78108
# The driver that this command dispatcher is associated with.
79109
#

0 commit comments

Comments
 (0)