Skip to content

Commit a8e3ee0

Browse files
committed
Fix rapid7#4431 - Support arbitrary session response timeout
Fix rapid7#4431
1 parent 067bda4 commit a8e3ee0

File tree

1 file changed

+18
-3
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class Core
4545
"-K" => [ false, "Terminate all sessions" ],
4646
"-s" => [ true, "Run a script on the session given with -i, or all"],
4747
"-r" => [ false, "Reset the ring buffer for the session given with -i, or all"],
48-
"-u" => [ true, "Upgrade a shell to a meterpreter session on many platforms" ])
48+
"-u" => [ true, "Upgrade a shell to a meterpreter session on many platforms" ],
49+
"-t" => [ true, "Set a response timeout (default: 15)"])
4950

5051
@@jobs_opts = Rex::Parser::Arguments.new(
5152
"-h" => [ false, "Help banner." ],
@@ -1222,7 +1223,7 @@ def cmd_route(*args)
12221223
Rex::Socket::SwitchBoard.flush_routes
12231224

12241225
when "print"
1225-
tbl = Table.new(
1226+
tbl = Table.new(
12261227
Table::Style::Default,
12271228
'Header' => "Active Routing Table",
12281229
'Prefix' => "\n",
@@ -1597,6 +1598,7 @@ def cmd_sessions(*args)
15971598
cmds = []
15981599
script = nil
15991600
reset_ring = false
1601+
response_timeout = 15
16001602

16011603
# any arguments that don't correspond to an option or option arg will
16021604
# be put in here
@@ -1646,6 +1648,10 @@ def cmd_sessions(*args)
16461648
when "-h"
16471649
cmd_sessions_help
16481650
return false
1651+
when "-t"
1652+
if val.to_s =~ /^\d+$/
1653+
response_timeout = val.to_i
1654+
end
16491655
else
16501656
extra << val
16511657
end
@@ -1684,6 +1690,7 @@ def cmd_sessions(*args)
16841690
session = verify_session(s)
16851691
next unless session
16861692
print_status("Running '#{cmd}' on #{session.type} session #{s} (#{session.session_host})")
1693+
session.response_timeout = response_timeout
16871694

16881695
if session.type == 'meterpreter'
16891696
# If session.sys is nil, dont even try..
@@ -1720,6 +1727,7 @@ def cmd_sessions(*args)
17201727
session_list.each do |sess_id|
17211728
session = framework.sessions.get(sess_id)
17221729
if session
1730+
session.response_timeout = response_timeout
17231731
print_status("Killing session #{sess_id}")
17241732
session.kill
17251733
else
@@ -1730,21 +1738,26 @@ def cmd_sessions(*args)
17301738
print_status("Killing all sessions...")
17311739
framework.sessions.each_sorted do |s|
17321740
session = framework.sessions.get(s)
1733-
session.kill if session
1741+
if session
1742+
session.response_timeout = response_timeout
1743+
session.kill
1744+
end
17341745
end
17351746
when 'detach'
17361747
print_status("Detaching the following session(s): #{session_list.join(', ')}")
17371748
session_list.each do |sess_id|
17381749
session = verify_session(sess_id)
17391750
# if session is interactive, it's detachable
17401751
if session
1752+
session.response_timeout = response_timeout
17411753
print_status("Detaching session #{sess_id}")
17421754
session.detach
17431755
end
17441756
end
17451757
when 'interact'
17461758
session = verify_session(sid)
17471759
if session
1760+
session.response_timeout = response_timeout
17481761
print_status("Starting interaction with #{session.name}...\n") unless quiet
17491762
self.active_session = session
17501763
session.interact(driver.input.dup, driver.output)
@@ -1770,6 +1783,7 @@ def cmd_sessions(*args)
17701783
session = framework.sessions.get(sess_id)
17711784
end
17721785
if session
1786+
session.response_timeout = response_timeout
17731787
if script_paths[session.type]
17741788
print_status("Session #{sess_id} (#{session.session_host}):")
17751789
print_status("Running script #{script} on #{session.type} session" +
@@ -1790,6 +1804,7 @@ def cmd_sessions(*args)
17901804
session_list.each do |sess_id|
17911805
session = verify_session(sess_id)
17921806
if session
1807+
session.response_timeout = response_timeout
17931808
if session.type == 'shell'
17941809
session.init_ui(driver.input, driver.output)
17951810
session.execute_script('post/multi/manage/shell_to_meterpreter')

0 commit comments

Comments
 (0)