Skip to content

Commit 1c5de59

Browse files
committed
Add support for the set of timeout values
This removes the need for a separate get call behind the scenes as meterpreter does get and set in a single call.
1 parent ec7fab7 commit 1c5de59

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

lib/rex/post/meterpreter/client_core.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,22 @@ def get_loaded_extension_commands(extension_name)
100100
commands
101101
end
102102

103-
def get_transport_timeouts
104-
request = Packet.create_request('core_transport_get_timeouts')
103+
def set_transport_timeouts(opts={})
104+
request = Packet.create_request('core_transport_set_timeouts')
105+
106+
if opts[:session_exp]
107+
request.add_tlv(TLV_TYPE_TRANS_SESSION_EXP, opts[:session_exp])
108+
end
109+
if opts[:comm_timeout]
110+
request.add_tlv(TLV_TYPE_TRANS_COMM_TIMEOUT, opts[:comm_timeout])
111+
end
112+
if opts[:retry_total]
113+
request.add_tlv(TLV_TYPE_TRANS_RETRY_TOTAL, opts[:retry_total])
114+
end
115+
if opts[:retry_wait]
116+
request.add_tlv(TLV_TYPE_TRANS_RETRY_WAIT, opts[:retry_wait])
117+
end
118+
105119
response = client.send_request(request)
106120

107121
{

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

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: binary -*-
22
require 'set'
3-
require 'dotiw'
43
require 'rex/post/meterpreter'
54
require 'rex/parser/arguments'
65

@@ -59,7 +58,8 @@ def commands
5958
"run" => "Executes a meterpreter script or Post module",
6059
"bgrun" => "Executes a meterpreter script as a background thread",
6160
"bgkill" => "Kills a background meterpreter script",
62-
"get_timeouts" => "Kills a background meterpreter script",
61+
"get_timeouts" => "Get the current session timeout values",
62+
"set_timeouts" => "Set the current session timeout values",
6363
"bglist" => "Lists running background scripts",
6464
"write" => "Writes data to a channel",
6565
"enable_unicode_encoding" => "Enables encoding of unicode strings",
@@ -69,6 +69,7 @@ def commands
6969
if client.passive_service
7070
c["detach"] = "Detach the meterpreter session (for http/https)"
7171
end
72+
7273
# The only meterp that implements this right now is native Windows and for
7374
# whatever reason it is not adding core_migrate to its list of commands.
7475
# Use a dumb platform til it gets sorted.
@@ -324,8 +325,50 @@ def cmd_irb(*args)
324325
Rex::Ui::Text::IrbShell.new(binding).run
325326
end
326327

328+
@@set_timeouts_opts = Rex::Parser::Arguments.new(
329+
'-c' => [ true, 'Comms timeout (seconds)' ],
330+
'-x' => [ true, 'Expiration timout (seconds)' ],
331+
'-t' => [ true, 'Retry total time (seconds)' ],
332+
'-w' => [ true, 'Retry wait time (seconds)' ],
333+
'-h' => [ false, 'Help menu' ])
334+
335+
def cmd_set_timeouts(*args)
336+
if ( args.length == 0 or args.include?("-h") )
337+
cmd_transport_help
338+
return
339+
end
340+
341+
opts = {}
342+
343+
@@set_timeouts_opts.parse(args) do |opt, idx, val|
344+
case opt
345+
when '-c'
346+
opts[:comm_timeout] = val.to_i if val
347+
when '-x'
348+
opts[:session_exp] = val.to_i if val
349+
when '-t'
350+
opts[:retry_total] = val.to_i if val
351+
when '-w'
352+
opts[:retry_wait] = val.to_i if val
353+
end
354+
end
355+
356+
if opts.keys.length == 0
357+
print_error("No options set")
358+
else
359+
timeouts = client.core.set_transport_timeouts(opts)
360+
print_timeouts(timeouts)
361+
end
362+
end
363+
327364
def cmd_get_timeouts(*args)
328-
timeouts = client.core.get_transport_timeouts
365+
# Calling set without passing values is the same as
366+
# getting all the current timeouts
367+
timeouts = client.core.set_transport_timeouts
368+
print_timeouts(timeouts)
369+
end
370+
371+
def print_timeouts(timeouts)
329372
print_line("Session Expiry : @ #{(Time.now + timeouts[:session_exp]).strftime('%Y-%m-%d %H:%M:%S')}")
330373
print_line("Comm Timeout : #{timeouts[:comm_timeout]} seconds")
331374
print_line("Retry Total Time: #{timeouts[:retry_total]} seconds")

0 commit comments

Comments
 (0)