Skip to content

Commit 8b02f42

Browse files
David Maloneypbarry-r7
authored andcommitted
add meterpreter cmd interaction to console
add the -C flag to the sessions command to trigger meterpreter commands on sessions without going full interactive
1 parent 4a1f881 commit 8b02f42

File tree

1 file changed

+51
-13
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+51
-13
lines changed

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

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@ class Core
3838

3939
# Session command options
4040
@@sessions_opts = Rex::Parser::Arguments.new(
41-
"-c" => [ true, "Run a command on the session given with -i, or all" ],
42-
"-h" => [ false, "Help banner" ],
43-
"-i" => [ true, "Interact with the supplied session ID " ],
44-
"-l" => [ false, "List all active sessions" ],
45-
"-v" => [ false, "List sessions in verbose mode" ],
46-
"-q" => [ false, "Quiet mode" ],
47-
"-k" => [ true, "Terminate sessions by session ID and/or range" ],
48-
"-K" => [ false, "Terminate all sessions" ],
49-
"-s" => [ true, "Run a script on the session given with -i, or all" ],
50-
"-r" => [ false, "Reset the ring buffer for the session given with -i, or all" ],
51-
"-u" => [ true, "Upgrade a shell to a meterpreter session on many platforms" ],
52-
"-t" => [ true, "Set a response timeout (default: 15)" ],
53-
"-x" => [ false, "Show extended information in the session table" ])
41+
"-c" => [ true, "Run a command on the session given with -i, or all" ],
42+
"-C" => [ true, "Run a Meterpreter Command on the session given with -i, or all" ],
43+
"-h" => [ false, "Help banner" ],
44+
"-i" => [ true, "Interact with the supplied session ID " ],
45+
"-l" => [ false, "List all active sessions" ],
46+
"-v" => [ false, "List sessions in verbose mode" ],
47+
"-q" => [ false, "Quiet mode" ],
48+
"-k" => [ true, "Terminate sessions by session ID and/or range" ],
49+
"-K" => [ false, "Terminate all sessions" ],
50+
"-s" => [ true, "Run a script on the session given with -i, or all" ],
51+
"-r" => [ false, "Reset the ring buffer for the session given with -i, or all" ],
52+
"-u" => [ true, "Upgrade a shell to a meterpreter session on many platforms" ],
53+
"-t" => [ true, "Set a response timeout (default: 15)" ],
54+
"-x" => [ false, "Show extended information in the session table" ])
5455

5556
@@threads_opts = Rex::Parser::Arguments.new(
5657
"-h" => [ false, "Help banner." ],
@@ -1045,6 +1046,9 @@ def cmd_sessions(*args)
10451046
when "-c"
10461047
method = 'cmd'
10471048
cmds << val if val
1049+
when "-C"
1050+
method = 'meterp-cmd'
1051+
cmds << val if val
10481052
when "-x"
10491053
show_extended = true
10501054
when "-v"
@@ -1167,6 +1171,40 @@ def cmd_sessions(*args)
11671171
# commands on), so don't bother.
11681172
end
11691173
end
1174+
when 'meterp-cmd'
1175+
if cmds.length < 1
1176+
print_error("No command specified!")
1177+
return false
1178+
end
1179+
1180+
if sid
1181+
sessions = session_list
1182+
else
1183+
sessions = framework.sessions.keys.sort
1184+
end
1185+
if sessions.blank?
1186+
print_error("Please specify valid session identifier(s) using -i")
1187+
return false
1188+
end
1189+
1190+
cmds.each do |cmd|
1191+
sessions.each do |session|
1192+
session = verify_session(session)
1193+
unless session.type == 'meterpreter'
1194+
print_error "Session ##{session.sid} is not a Meterpreter shell. Skipping..."
1195+
next
1196+
end
1197+
1198+
next unless session
1199+
print_status("Running '#{cmd}' on #{session.type} session #{session.sid} (#{session.session_host})")
1200+
if session.respond_to?(:response_timeout)
1201+
last_known_timeout = session.response_timeout
1202+
session.response_timeout = response_timeout
1203+
end
1204+
1205+
output = session.run_cmd cmd
1206+
end
1207+
end
11701208
when 'kill'
11711209
print_status("Killing the following session(s): #{session_list.join(', ')}")
11721210
session_list.each do |sess_id|

0 commit comments

Comments
 (0)