@@ -114,7 +114,6 @@ def commands
114114 "set" => "Sets a context-specific variable to a value" ,
115115 "setg" => "Sets a global variable to a value" ,
116116 "sleep" => "Do nothing for the specified number of seconds" ,
117- "terminal" => "Interact with a given session" ,
118117 "threads" => "View and manipulate background threads" ,
119118 "unload" => "Unload a framework plugin" ,
120119 "unset" => "Unsets one or more context-specific variables" ,
@@ -988,33 +987,14 @@ def cmd_spool(*args)
988987 return
989988 end
990989
991- def cmd_terminal_help
992- print_line ( 'Usage: terminal <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_terminal ( *args )
1003- if args . length == 0 || args [ 0 ] . to_i == 0
1004- cmd_terminal_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
0 commit comments