Skip to content

Commit e0fee9e

Browse files
committed
Land rapid7#8821, Expose session naming
2 parents 32104eb + b797e96 commit e0fee9e

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

lib/msf/base/serializer/readable_text.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ def self.dump_sessions(framework, opts={})
539539

540540
columns = []
541541
columns << 'Id'
542+
columns << 'Name'
542543
columns << 'Type'
543544
columns << 'Checkin?' if show_extended
544545
columns << 'Enc?' if show_extended
@@ -562,6 +563,7 @@ def self.dump_sessions(framework, opts={})
562563

563564
row = []
564565
row << session.sid.to_s
566+
row << session.sname.to_s
565567
row << session.type.to_s
566568
if session.respond_to?(:session_type)
567569
row[-1] << (" " + session.session_type)
@@ -617,6 +619,7 @@ def self.dump_sessions_verbose(framework, opts={})
617619

618620
sess_info = session.info.to_s
619621
sess_id = session.sid.to_s
622+
sess_name = session.sname.to_s
620623
sess_tunnel = session.tunnel_to_s + " (#{session.session_host})"
621624
sess_via = session.via_exploit.to_s
622625
sess_type = session.type.to_s
@@ -647,6 +650,7 @@ def self.dump_sessions_verbose(framework, opts={})
647650
end
648651

649652
out << " Session ID: #{sess_id}\n"
653+
out << " Name: #{sess_name}\n"
650654
out << " Type: #{sess_type}\n"
651655
out << " Info: #{sess_info}\n"
652656
out << " Tunnel: #{sess_tunnel}\n"

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.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)