1
1
# -*- coding: binary -*-
2
2
require 'set'
3
- require 'dotiw'
4
3
require 'rex/post/meterpreter'
5
4
require 'rex/parser/arguments'
6
5
@@ -59,7 +58,8 @@ def commands
59
58
"run" => "Executes a meterpreter script or Post module" ,
60
59
"bgrun" => "Executes a meterpreter script as a background thread" ,
61
60
"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" ,
63
63
"bglist" => "Lists running background scripts" ,
64
64
"write" => "Writes data to a channel" ,
65
65
"enable_unicode_encoding" => "Enables encoding of unicode strings" ,
@@ -69,6 +69,7 @@ def commands
69
69
if client . passive_service
70
70
c [ "detach" ] = "Detach the meterpreter session (for http/https)"
71
71
end
72
+
72
73
# The only meterp that implements this right now is native Windows and for
73
74
# whatever reason it is not adding core_migrate to its list of commands.
74
75
# Use a dumb platform til it gets sorted.
@@ -324,8 +325,50 @@ def cmd_irb(*args)
324
325
Rex ::Ui ::Text ::IrbShell . new ( binding ) . run
325
326
end
326
327
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
+
327
364
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 )
329
372
print_line ( "Session Expiry : @ #{ ( Time . now + timeouts [ :session_exp ] ) . strftime ( '%Y-%m-%d %H:%M:%S' ) } " )
330
373
print_line ( "Comm Timeout : #{ timeouts [ :comm_timeout ] } seconds" )
331
374
print_line ( "Retry Total Time: #{ timeouts [ :retry_total ] } seconds" )
0 commit comments