Skip to content

Commit 5b77854

Browse files
committed
Add session naming support to CommandDispatcher
1 parent 6eae3b3 commit 5b77854

File tree

1 file changed

+29
-5
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+29
-5
lines changed

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Core
4141
"-c" => [ true, "Run a command on the session given with -i, or all" ],
4242
"-C" => [ true, "Run a Meterpreter Command on the session given with -i, or all" ],
4343
"-h" => [ false, "Help banner" ],
44-
"-i" => [ true, "Interact with the supplied session ID " ],
44+
"-i" => [ true, "Interact with the supplied session ID" ],
4545
"-l" => [ false, "List all active sessions" ],
4646
"-v" => [ false, "List sessions in verbose mode" ],
4747
"-q" => [ false, "Quiet mode" ],
@@ -51,8 +51,9 @@ class Core
5151
"-r" => [ false, "Reset the ring buffer for the session given with -i, or all" ],
5252
"-u" => [ true, "Upgrade a shell to a meterpreter session on many platforms" ],
5353
"-t" => [ true, "Set a response timeout (default: 15)" ],
54-
"-S" => [ true, "Row search filter." ],
55-
"-x" => [ false, "Show extended information in the session table" ])
54+
"-S" => [ true, "Row search filter." ],
55+
"-x" => [ false, "Show extended information in the session table" ],
56+
"-n" => [ true, "Name or rename a session by ID" ])
5657

5758
@@threads_opts = Rex::Parser::Arguments.new(
5859
"-h" => [ false, "Help banner." ],
@@ -1142,6 +1143,7 @@ def cmd_sessions(*args)
11421143
reset_ring = false
11431144
response_timeout = 15
11441145
search_term = nil
1146+
session_name = nil
11451147

11461148
# any arguments that don't correspond to an option or option arg will
11471149
# be put in here
@@ -1204,8 +1206,9 @@ def cmd_sessions(*args)
12041206
if val.to_s =~ /^\d+$/
12051207
response_timeout = val.to_i
12061208
end
1207-
when "-S", "--search"
1208-
search_term = val
1209+
when "-n", "--name"
1210+
method = 'name'
1211+
session_name = val
12091212
else
12101213
extra << val
12111214
end
@@ -1473,6 +1476,27 @@ def cmd_sessions(*args)
14731476
print_line
14741477
print(Serializer::ReadableText.dump_sessions(framework, :show_extended => show_extended, :verbose => verbose, :search_term => search_term))
14751478
print_line
1479+
when 'name'
1480+
if session_name.nil? || session_name.blank?
1481+
print_error('Please specify a valid session name')
1482+
return false
1483+
end
1484+
1485+
sessions = sid ? session_list : nil
1486+
1487+
if sessions.nil? || sessions.empty?
1488+
print_error("Please specify valid session identifier(s) using -i")
1489+
return false
1490+
end
1491+
1492+
sessions.each do |s|
1493+
if framework.sessions[s].respond_to?(:name=)
1494+
framework.sessions[s].name = session_name
1495+
print_status("Session #{s} named to #{session_name}")
1496+
else
1497+
print_error("Session #{s} cannot be named")
1498+
end
1499+
end
14761500
end
14771501

14781502
rescue IOError, EOFError, Rex::StreamClosedError

0 commit comments

Comments
 (0)