@@ -41,7 +41,7 @@ class Core
41
41
"-c" => [ true , "Run a command on the session given with -i, or all" ] ,
42
42
"-C" => [ true , "Run a Meterpreter Command on the session given with -i, or all" ] ,
43
43
"-h" => [ false , "Help banner" ] ,
44
- "-i" => [ true , "Interact with the supplied session ID " ] ,
44
+ "-i" => [ true , "Interact with the supplied session ID" ] ,
45
45
"-l" => [ false , "List all active sessions" ] ,
46
46
"-v" => [ false , "List sessions in verbose mode" ] ,
47
47
"-q" => [ false , "Quiet mode" ] ,
@@ -51,8 +51,9 @@ class Core
51
51
"-r" => [ false , "Reset the ring buffer for the session given with -i, or all" ] ,
52
52
"-u" => [ true , "Upgrade a shell to a meterpreter session on many platforms" ] ,
53
53
"-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" ] )
56
57
57
58
@@threads_opts = Rex ::Parser ::Arguments . new (
58
59
"-h" => [ false , "Help banner." ] ,
@@ -1142,6 +1143,7 @@ def cmd_sessions(*args)
1142
1143
reset_ring = false
1143
1144
response_timeout = 15
1144
1145
search_term = nil
1146
+ session_name = nil
1145
1147
1146
1148
# any arguments that don't correspond to an option or option arg will
1147
1149
# be put in here
@@ -1204,8 +1206,9 @@ def cmd_sessions(*args)
1204
1206
if val . to_s =~ /^\d +$/
1205
1207
response_timeout = val . to_i
1206
1208
end
1207
- when "-S" , "--search"
1208
- search_term = val
1209
+ when "-n" , "--name"
1210
+ method = 'name'
1211
+ session_name = val
1209
1212
else
1210
1213
extra << val
1211
1214
end
@@ -1473,6 +1476,27 @@ def cmd_sessions(*args)
1473
1476
print_line
1474
1477
print ( Serializer ::ReadableText . dump_sessions ( framework , :show_extended => show_extended , :verbose => verbose , :search_term => search_term ) )
1475
1478
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
1476
1500
end
1477
1501
1478
1502
rescue IOError , EOFError , Rex ::StreamClosedError
0 commit comments