Skip to content

Commit b1507f6

Browse files
author
Brent Cook
committed
Land rapid7#5339, support for 'sleep' with meterpreter sessions
2 parents 02994bc + f3c22e4 commit b1507f6

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PATH
99
json
1010
metasploit-concern (~> 1.0)
1111
metasploit-model (~> 1.0)
12-
metasploit-payloads (= 0.0.5)
12+
metasploit-payloads (= 0.0.6)
1313
msgpack
1414
nokogiri
1515
packetfu (= 1.1.9)
@@ -123,7 +123,7 @@ GEM
123123
activemodel (>= 4.0.9, < 4.1.0)
124124
activesupport (>= 4.0.9, < 4.1.0)
125125
railties (>= 4.0.9, < 4.1.0)
126-
metasploit-payloads (0.0.5)
126+
metasploit-payloads (0.0.6)
127127
metasploit_data_models (1.0.1)
128128
activerecord (>= 4.0.9, < 4.1.0)
129129
activesupport (>= 4.0.9, < 4.1.0)

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|

metasploit-framework.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Gem::Specification.new do |spec|
6464
# are needed when there's no database
6565
spec.add_runtime_dependency 'metasploit-model', '~> 1.0'
6666
# Needed for Meterpreter on Windows, soon others.
67-
spec.add_runtime_dependency 'metasploit-payloads', '0.0.5'
67+
spec.add_runtime_dependency 'metasploit-payloads', '0.0.6'
6868
# Needed by msfgui and other rpc components
6969
spec.add_runtime_dependency 'msgpack'
7070
# Needed by anemone crawler

0 commit comments

Comments
 (0)