Skip to content

Commit 60d331f

Browse files
committed
Add support for a "sleep" command
This makes meterpeter shut down it's comms and sleep for a while before it attempts to open communications again. This is effectively the same as doing a transport change back to the same transport, but with a timeout.
1 parent 237827b commit 60d331f

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

lib/rex/post/meterpreter/client_core.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,18 @@ def transport_change(opts={})
340340
return true
341341
end
342342

343+
def transport_sleep(seconds)
344+
return false if seconds == 0
345+
346+
request = Packet.create_request('core_transport_sleep')
347+
348+
# we're reusing the comms timeout setting here instead of
349+
# creating a whole new TLV value
350+
request.add_tlv(TLV_TYPE_TRANS_COMM_TIMEOUT, seconds)
351+
client.send_request(request)
352+
return true
353+
end
354+
343355
def transport_next
344356
request = Packet.create_request('core_transport_next')
345357
client.send_request(request)

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

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def commands
8686
# Yet to implement transport hopping for other meterpreters.
8787
# Works for posix and native windows though.
8888
c["transport"] = "Change the current transport mechanism"
89+
90+
# sleep functionality relies on the transport features, so only
91+
# wire that in with the transport stuff.
92+
c["sleep"] = "Force Meterpreter to go quiet, then re-establish session."
8993
end
9094

9195
if (msf_loaded?)
@@ -494,6 +498,45 @@ def cmd_ssl_verify(*args)
494498

495499
end
496500

501+
#
502+
# Display help for the sleep.
503+
#
504+
def cmd_sleep_help
505+
print_line('Usage: sleep <time>')
506+
print_line
507+
print_line(' time: Number of seconds to wait (positive integer)')
508+
print_line
509+
print_line(' This command tells Meterpreter to go to sleep for the specified')
510+
print_line(' number of seconds. Sleeping will result in the transport being')
511+
print_line(' shut down and restarted after the designated timeout.')
512+
end
513+
514+
#
515+
# Handle the sleep command.
516+
#
517+
def cmd_sleep(*args)
518+
if args.length == 0
519+
cmd_sleep_help
520+
return
521+
end
522+
523+
seconds = args.shift.to_i
524+
525+
if seconds <= 0
526+
cmd_sleep_help
527+
return
528+
end
529+
530+
print_status("Telling the target instance to sleep for #{seconds} seconds ...")
531+
if client.core.transport_sleep(seconds)
532+
print_good("Target instance has gone to sleep, terminating current session.")
533+
client.shutdown_passive_dispatcher
534+
shell.stop
535+
else
536+
print_error("Target instance failed to go to sleep.")
537+
end
538+
end
539+
497540
#
498541
# Arguments for transport switching
499542
#
@@ -634,8 +677,9 @@ def cmd_transport(*args)
634677

635678
# next draw up a table of transport entries
636679
tbl = Rex::Ui::Text::Table.new(
637-
'Indent' => 4,
638-
'Columns' => columns)
680+
'SortIndex' => -1, # disable any sorting
681+
'Indent' => 4,
682+
'Columns' => columns)
639683

640684
first = true
641685
result[:transports].each do |t|

0 commit comments

Comments
 (0)