Skip to content

Commit a0c806c

Browse files
author
Brent Cook
committed
Update java meterpreter and payload references to use metasploit-payloads
1 parent 013781f commit a0c806c

File tree

7 files changed

+11
-16
lines changed

7 files changed

+11
-16
lines changed

lib/msf/core/payload/java.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ module Msf::Payload::Java
1717
def generate_stage
1818
stage = ''
1919
@stage_class_files.each do |path|
20-
fd = File.open(File.join( Msf::Config.data_directory, "java", path ), "rb")
21-
data = fd.read(fd.stat.size)
22-
fd.close
20+
data = MetasploitPayloads.read("java", path)
2321
stage << ([data.length].pack("N") + data)
2422
end
2523
stage << [0].pack("N")
@@ -36,8 +34,8 @@ def generate
3634

3735
#
3836
# Used by stagers to create a jar file as a {Rex::Zip::Jar}. Stagers
39-
# define a list of class files in @class_files which are pulled from
40-
# {Msf::Config.data_directory}. The configuration file is created by
37+
# define a list of class files in @class_files which are pulled from the
38+
# MetasploitPayloads gem. The configuration file is created by
4139
# the payload's #config method.
4240
#
4341
# @option opts :main_class [String] the name of the Main-Class
@@ -58,7 +56,7 @@ def generate_jar(opts={})
5856
jar = Rex::Zip::Jar.new
5957
jar.add_sub("metasploit") if opts[:random]
6058
jar.add_file("metasploit.dat", config)
61-
jar.add_files(paths, File.join(Msf::Config.data_directory, "java"))
59+
jar.add_files(paths, MetasploitPayloads.path('java'))
6260
jar.build_manifest(:main_class => main_class)
6361

6462
jar
@@ -103,7 +101,7 @@ def generate_war(opts={})
103101
zip.add_file('WEB-INF/', '')
104102
zip.add_file('WEB-INF/web.xml', web_xml)
105103
zip.add_file("WEB-INF/classes/", "")
106-
zip.add_files(paths, File.join(Msf::Config.data_directory, "java"), "WEB-INF/classes/")
104+
zip.add_files(paths, MetasploitPayloads.path('java'), 'WEB-INF/classes/')
107105
zip.add_file("WEB-INF/classes/metasploit.dat", config)
108106

109107
zip

lib/msf/util/exe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ def self.to_jar(exe, opts = {})
11391139
paths = [
11401140
[ "metasploit", "Payload.class" ],
11411141
]
1142-
zip.add_files(paths, File.join(Msf::Config.data_directory, "java"))
1142+
zip.add_files(paths, MetasploitPayloads.path('java'))
11431143
zip.build_manifest :main_class => "metasploit.Payload"
11441144
config = "Spawn=#{spawn}\r\nExecutable=#{exe_name}\r\n"
11451145
zip.add_file("metasploit.dat", config)

modules/exploits/multi/http/axis2_deployer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def upload_exec(session,rpath)
9898

9999
# We need this class as a wrapper to run in a thread. For some reason
100100
# the Payload class is giving illegal access exceptions without it.
101-
path = File.join(Msf::Config.data_directory, "java", "metasploit", "PayloadServlet.class")
101+
path = MetasploitPayloads.path("java", "metasploit", "PayloadServlet.class")
102102
fd = File.open(path, "rb")
103103
servlet = fd.read(fd.stat.size)
104104
fd.close

modules/exploits/multi/misc/java_jmx_server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def on_request_uri(cli, request)
8080
["metasploit", "JMXPayloadMBean.class"],
8181
["metasploit", "JMXPayload.class"],
8282
]
83-
jar.add_files(paths, [ Msf::Config.data_directory, "java" ])
83+
jar.add_files(paths, MetasploitPayloads.path('java'))
8484

8585
send_response(cli, jar.pack,
8686
{

modules/exploits/multi/misc/java_rmi_server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def on_request_uri(cli, request)
179179
[ "metasploit", "RMILoader.class" ],
180180
[ "metasploit", "RMIPayload.class" ],
181181
]
182-
jar.add_files(paths, [ Msf::Config.data_directory, "java" ])
182+
jar.add_files(paths, MetasploitPayloads.path('java'))
183183

184184
send_response(cli, jar.pack,
185185
{

modules/payloads/singles/java/shell_reverse_tcp.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ def generate_jar(opts={})
5353
jar.add_file(full, '')
5454
end
5555
end
56-
fd = File.open(File.join( Msf::Config.data_directory, "java", path ), "rb")
57-
data = fd.read(fd.stat.size)
56+
data = MetasploitPayloads.read('java', path)
5857
jar.add_file(path.join("/"), data)
59-
fd.close
6058
end
6159
jar.build_manifest(:main_class => "metasploit.Payload")
6260
jar.add_file("metasploit.dat", config)

modules/payloads/stages/java/meterpreter.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def initialize(info = {})
5454
# used as the final stage; calls super to get the intermediate stager.
5555
#
5656
def generate_stage
57-
file = File.join(Msf::Config.data_directory, "meterpreter", "meterpreter.jar")
58-
met = File.open(file, "rb") {|f| f.read(f.stat.size) }
57+
met = MetasploitPayloads.read('meterpreter', 'meterpreter.jar')
5958

6059
# All of the dendencies to create a jar loader, followed by the length
6160
# of the jar and the jar itself.

0 commit comments

Comments
 (0)