@@ -110,7 +110,6 @@ def commands
110
110
"quit" => "Exit the console" ,
111
111
"route" => "Route traffic through a session" ,
112
112
"save" => "Saves the active datastores" ,
113
- "sess" => "Interact with a given session" ,
114
113
"sessions" => "Dump session listings and display information about sessions" ,
115
114
"set" => "Sets a context-specific variable to a value" ,
116
115
"setg" => "Sets a global variable to a value" ,
@@ -988,33 +987,14 @@ def cmd_spool(*args)
988
987
return
989
988
end
990
989
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
-
1010
990
def cmd_sessions_help
1011
- print_line " Usage: sessions [options]"
991
+ print_line ( ' Usage: sessions [options] or sessions [id]' )
1012
992
print_line
1013
- print_line " Active session manipulation and interaction."
993
+ print_line ( ' Active session manipulation and interaction.' )
1014
994
print ( @@sessions_opts . usage )
1015
995
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' )
1018
998
print_line
1019
999
end
1020
1000
@@ -1037,58 +1017,63 @@ def cmd_sessions(*args)
1037
1017
# be put in here
1038
1018
extra = [ ]
1039
1019
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'
1051
1032
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
1089
1076
end
1090
- else
1091
- extra << val
1092
1077
end
1093
1078
end
1094
1079
0 commit comments