Skip to content

Commit 7b32b8b

Browse files
committed
Land rapid7#4810, support for job renaming in msfconsole
2 parents cf913e5 + 9cbb8c2 commit 7b32b8b

File tree

2 files changed

+86
-40
lines changed

2 files changed

+86
-40
lines changed

features/commands/help.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Feature: Help command
3636
pushm Pushes the active or list of modules onto the module stack
3737
quit Exit the console
3838
reload_all Reloads all modules from all defined module paths
39+
rename_job Rename a job
3940
resource Run the commands stored in a file
4041
route Route traffic through a session
4142
save Saves the active datastores

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

Lines changed: 85 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -107,47 +107,48 @@ class Core
107107
# Returns the list of commands supported by this command dispatcher
108108
def commands
109109
{
110-
"?" => "Help menu",
111-
"back" => "Move back from the current context",
112-
"banner" => "Display an awesome metasploit banner",
113-
"cd" => "Change the current working directory",
114-
"connect" => "Communicate with a host",
115-
"color" => "Toggle color",
116-
"exit" => "Exit the console",
117-
"edit" => "Edit the current module with $VISUAL or $EDITOR",
118-
"get" => "Gets the value of a context-specific variable",
119-
"getg" => "Gets the value of a global variable",
120-
"go_pro" => "Launch Metasploit web GUI",
121-
"grep" => "Grep the output of another command",
122-
"help" => "Help menu",
123-
"info" => "Displays information about one or more module",
124-
"irb" => "Drop into irb scripting mode",
125-
"jobs" => "Displays and manages jobs",
126-
"kill" => "Kill a job",
127-
"load" => "Load a framework plugin",
128-
"loadpath" => "Searches for and loads modules from a path",
129-
"popm" => "Pops the latest module off the stack and makes it active",
130-
"pushm" => "Pushes the active or list of modules onto the module stack",
131-
"previous" => "Sets the previously loaded module as the current module",
132-
"quit" => "Exit the console",
133-
"resource" => "Run the commands stored in a file",
134-
"makerc" => "Save commands entered since start to a file",
110+
"?" => "Help menu",
111+
"back" => "Move back from the current context",
112+
"banner" => "Display an awesome metasploit banner",
113+
"cd" => "Change the current working directory",
114+
"connect" => "Communicate with a host",
115+
"color" => "Toggle color",
116+
"exit" => "Exit the console",
117+
"edit" => "Edit the current module with $VISUAL or $EDITOR",
118+
"get" => "Gets the value of a context-specific variable",
119+
"getg" => "Gets the value of a global variable",
120+
"go_pro" => "Launch Metasploit web GUI",
121+
"grep" => "Grep the output of another command",
122+
"help" => "Help menu",
123+
"info" => "Displays information about one or more module",
124+
"irb" => "Drop into irb scripting mode",
125+
"jobs" => "Displays and manages jobs",
126+
"rename_job" => "Rename a job",
127+
"kill" => "Kill a job",
128+
"load" => "Load a framework plugin",
129+
"loadpath" => "Searches for and loads modules from a path",
130+
"popm" => "Pops the latest module off the stack and makes it active",
131+
"pushm" => "Pushes the active or list of modules onto the module stack",
132+
"previous" => "Sets the previously loaded module as the current module",
133+
"quit" => "Exit the console",
134+
"resource" => "Run the commands stored in a file",
135+
"makerc" => "Save commands entered since start to a file",
135136
"reload_all" => "Reloads all modules from all defined module paths",
136-
"route" => "Route traffic through a session",
137-
"save" => "Saves the active datastores",
138-
"search" => "Searches module names and descriptions",
139-
"sessions" => "Dump session listings and display information about sessions",
140-
"set" => "Sets a context-specific variable to a value",
141-
"setg" => "Sets a global variable to a value",
142-
"show" => "Displays modules of a given type, or all modules",
143-
"sleep" => "Do nothing for the specified number of seconds",
144-
"threads" => "View and manipulate background threads",
145-
"unload" => "Unload a framework plugin",
146-
"unset" => "Unsets one or more context-specific variables",
147-
"unsetg" => "Unsets one or more global variables",
148-
"use" => "Selects a module by name",
149-
"version" => "Show the framework and console library version numbers",
150-
"spool" => "Write console output into a file as well the screen"
137+
"route" => "Route traffic through a session",
138+
"save" => "Saves the active datastores",
139+
"search" => "Searches module names and descriptions",
140+
"sessions" => "Dump session listings and display information about sessions",
141+
"set" => "Sets a context-specific variable to a value",
142+
"setg" => "Sets a global variable to a value",
143+
"show" => "Displays modules of a given type, or all modules",
144+
"sleep" => "Do nothing for the specified number of seconds",
145+
"threads" => "View and manipulate background threads",
146+
"unload" => "Unload a framework plugin",
147+
"unset" => "Unsets one or more context-specific variables",
148+
"unsetg" => "Unsets one or more global variables",
149+
"use" => "Selects a module by name",
150+
"version" => "Show the framework and console library version numbers",
151+
"spool" => "Write console output into a file as well the screen"
151152
}
152153
end
153154

@@ -780,6 +781,50 @@ def cmd_irb(*args)
780781
end
781782
end
782783

784+
def cmd_rename_job_help
785+
print_line "Usage: rename_job [ID] [Name]"
786+
print_line
787+
print_line "Example: rename_job 0 \"meterpreter HTTPS special\""
788+
print_line
789+
print_line "Rename a job that's currently active."
790+
print_line "You may use the jobs command to see what jobs are available."
791+
print_line
792+
end
793+
794+
def cmd_rename_job(*args)
795+
if args.include?('-h') || args.length != 2 || args[0] !~ /^\d+$/
796+
cmd_rename_job_help
797+
return false
798+
end
799+
800+
job_id = args[0].to_s
801+
job_name = args[1].to_s
802+
803+
unless framework.jobs[job_id]
804+
print_error("Job #{job_id} does not exist.")
805+
return false
806+
end
807+
808+
# This is not respecting the Protected access control, but this seems to be the only way
809+
# to rename a job. If you know a more appropriate way, patches accepted.
810+
framework.jobs[job_id].send(:name=, job_name)
811+
print_status("Job #{job_id} updated")
812+
813+
true
814+
end
815+
816+
#
817+
# Tab completion for the rename_job command
818+
#
819+
# @param str [String] the string currently being typed before tab was hit
820+
# @param words [Array<String>] the previously completed words on the command line. words is always
821+
# at least 1 when tab completion has reached this stage since the command itself has been completed
822+
823+
def cmd_rename_job_tabs(str, words)
824+
return [] if words.length > 1
825+
framework.jobs.keys
826+
end
827+
783828
def cmd_jobs_help
784829
print_line "Usage: jobs [options]"
785830
print_line

0 commit comments

Comments
 (0)