Skip to content

Commit 60d5cef

Browse files
committed
Land rapid7#7727, nuke sess from orbit
Replace with consolidated sessions command.
2 parents 6e830a8 + ee4caba commit 60d5cef

File tree

3 files changed

+64
-80
lines changed

3 files changed

+64
-80
lines changed

features/commands/help.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Feature: Help command
2626
quit Exit the console
2727
route Route traffic through a session
2828
save Saves the active datastores
29-
sess Interact with a given session
3029
sessions Dump session listings and display information about sessions
3130
set Sets a context-specific variable to a value
3231
setg Sets a global variable to a value

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

Lines changed: 59 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def commands
110110
"quit" => "Exit the console",
111111
"route" => "Route traffic through a session",
112112
"save" => "Saves the active datastores",
113-
"sess" => "Interact with a given session",
114113
"sessions" => "Dump session listings and display information about sessions",
115114
"set" => "Sets a context-specific variable to a value",
116115
"setg" => "Sets a global variable to a value",
@@ -988,33 +987,14 @@ def cmd_spool(*args)
988987
return
989988
end
990989

991-
def cmd_sess_help
992-
print_line('Usage: sess <session id>')
993-
print_line
994-
print_line('Interact with the given session ID.')
995-
print_line('This works the same as: sessions -i <session id>')
996-
print_line
997-
end
998-
999-
#
1000-
# Helper function to quickly select a session
1001-
#
1002-
def cmd_sess(*args)
1003-
if args.length == 0 || args[0].to_i == 0
1004-
cmd_sess_help
1005-
else
1006-
cmd_sessions('-i', args[0])
1007-
end
1008-
end
1009-
1010990
def cmd_sessions_help
1011-
print_line "Usage: sessions [options]"
991+
print_line('Usage: sessions [options] or sessions [id]')
1012992
print_line
1013-
print_line "Active session manipulation and interaction."
993+
print_line('Active session manipulation and interaction.')
1014994
print(@@sessions_opts.usage)
1015995
print_line
1016-
print_line "Many options allow specifying session ranges using commas and dashes."
1017-
print_line "For example: sessions -s checkvm -i 1,3-5 or sessions -k 1-2,5,6"
996+
print_line('Many options allow specifying session ranges using commas and dashes.')
997+
print_line('For example: sessions -s checkvm -i 1,3-5 or sessions -k 1-2,5,6')
1018998
print_line
1019999
end
10201000

@@ -1037,58 +1017,63 @@ def cmd_sessions(*args)
10371017
# be put in here
10381018
extra = []
10391019

1040-
# Parse the command options
1041-
@@sessions_opts.parse(args) do |opt, idx, val|
1042-
case opt
1043-
when "-q"
1044-
quiet = true
1045-
# Run a command on all sessions, or the session given with -i
1046-
when "-c"
1047-
method = 'cmd'
1048-
cmds << val if val
1049-
when "-C"
1050-
method = 'meterp-cmd'
1020+
if args.length == 1 && args[0] =~ /-?\d+/
1021+
method = 'interact'
1022+
sid = args[0].to_i
1023+
else
1024+
# Parse the command options
1025+
@@sessions_opts.parse(args) do |opt, idx, val|
1026+
case opt
1027+
when '-q'
1028+
quiet = true
1029+
# Run a command on all sessions, or the session given with -i
1030+
when '-c'
1031+
method = 'cmd'
10511032
cmds << val if val
1052-
when "-x"
1053-
show_extended = true
1054-
when "-v"
1055-
verbose = true
1056-
# Do something with the supplied session identifier instead of
1057-
# all sessions.
1058-
when "-i"
1059-
sid = val
1060-
# Display the list of active sessions
1061-
when "-l"
1062-
method = 'list'
1063-
when "-k"
1064-
method = 'kill'
1065-
sid = val || false
1066-
when "-K"
1067-
method = 'killall'
1068-
# Run a script on all meterpreter sessions
1069-
when "-s"
1070-
unless script
1071-
method = 'scriptall'
1072-
script = val
1073-
end
1074-
# Upload and exec to the specific command session
1075-
when "-u"
1076-
method = 'upexec'
1077-
sid = val || false
1078-
# Reset the ring buffer read pointer
1079-
when "-r"
1080-
reset_ring = true
1081-
method = 'reset_ring'
1082-
# Display help banner
1083-
when "-h"
1084-
cmd_sessions_help
1085-
return false
1086-
when "-t"
1087-
if val.to_s =~ /^\d+$/
1088-
response_timeout = val.to_i
1033+
when '-C'
1034+
method = 'meterp-cmd'
1035+
cmds << val if val
1036+
when '-x'
1037+
show_extended = true
1038+
when '-v'
1039+
verbose = true
1040+
# Do something with the supplied session identifier instead of
1041+
# all sessions.
1042+
when '-i'
1043+
sid = val
1044+
# Display the list of active sessions
1045+
when '-l'
1046+
method = 'list'
1047+
when '-k'
1048+
method = 'kill'
1049+
sid = val || false
1050+
when '-K'
1051+
method = 'killall'
1052+
# Run a script on all meterpreter sessions
1053+
when '-s'
1054+
unless script
1055+
method = 'scriptall'
1056+
script = val
1057+
end
1058+
# Upload and exec to the specific command session
1059+
when '-u'
1060+
method = 'upexec'
1061+
sid = val || false
1062+
# Reset the ring buffer read pointer
1063+
when '-r'
1064+
reset_ring = true
1065+
method = 'reset_ring'
1066+
# Display help banner
1067+
when '-h'
1068+
cmd_sessions_help
1069+
return false
1070+
when '-t'
1071+
if val.to_s =~ /^\d+$/
1072+
response_timeout = val.to_i
1073+
end
1074+
else
1075+
extra << val
10891076
end
1090-
else
1091-
extra << val
10921077
end
10931078
end
10941079

lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def commands
6565
"bgkill" => "Kills a background meterpreter script",
6666
"get_timeouts" => "Get the current session timeout values",
6767
"set_timeouts" => "Set the current session timeout values",
68-
"sess" => "Quickly switch to another session",
68+
"sessions" => "Quickly switch to another session",
6969
"bglist" => "Lists running background scripts",
7070
"write" => "Writes data to a channel",
7171
"enable_unicode_encoding" => "Enables encoding of unicode strings",
@@ -118,17 +118,17 @@ def name
118118
"Core"
119119
end
120120

121-
def cmd_sess_help
122-
print_line('Usage: sess <session id>')
121+
def cmd_sessions_help
122+
print_line('Usage: sessions <id>')
123123
print_line
124124
print_line('Interact with a different session Id.')
125125
print_line('This works the same as calling this from the MSF shell: sessions -i <session id>')
126126
print_line
127127
end
128128

129-
def cmd_sess(*args)
129+
def cmd_sessions(*args)
130130
if args.length == 0 || args[0].to_i == 0
131-
cmd_sess_help
131+
cmd_sessions_help
132132
elsif args[0].to_s == client.name.to_s
133133
print_status("Session #{client.name} is already interactive.")
134134
else

0 commit comments

Comments
 (0)