diff --git a/lib/msf/core/payload/java.rb b/lib/msf/core/payload/java.rb index 795d083374..2e554c1d51 100644 --- a/lib/msf/core/payload/java.rb +++ b/lib/msf/core/payload/java.rb @@ -16,8 +16,9 @@ module Msf::Payload::Java def generate_stage stage = '' @stage_class_files.each do |path| - fd = File.open(File.join( Msf::Config.install_root, "data", "java", path ), "rb") + fd = File.open(File.join( Msf::Config.data_directory, "java", path ), "rb") data = fd.read(fd.stat.size) + fd.close stage << ([data.length].pack("N") + data) end stage << [0].pack("N") @@ -33,7 +34,7 @@ module Msf::Payload::Java end # - # Returns a jar file as a +Rex::Zip::Archive+ + # Returns a jar file as a +Rex::Zip::Jar+ # def generate_jar raise if not respond_to? :config @@ -42,7 +43,8 @@ module Msf::Payload::Java ] + @class_files jar = Rex::Zip::Jar.new - add_class_files(jar, paths) + #add_class_files(jar, paths) + jar.add_files(paths, File.join(Msf::Config.data_directory, "java")) jar.build_manifest(:main_class => "metasploit.Payload") jar.add_file("metasploit.dat", config) @@ -50,7 +52,7 @@ module Msf::Payload::Java end def generate_war(opts={}) - zip = Rex::Zip::Archive.new + zip = Rex::Zip::Jar.new web_xml = %q{ + # war = Rex::Zip::Jar.new + # war.add_file("WEB-INF/", '') + # war.add_file("WEB-INF/", "web.xml", web_xml) + # war.add_file("WEB-INF/classes/", '') + # files = [ + # [ "servlet", "examples", "HelloWorld.class" ], + # [ "Foo.class" ], + # [ "servlet", "Bar.class" ], + # ] + # war.add_files(files, "./class_files/", "WEB-INF/classes/") + # + # + # The above code would create a jar with the following structure from files + # found in ./class_files/ : + # + # +- WEB-INF/ + # +- web.xml + # +- classes/ + # +- Foo.class + # +- servlet/ + # +- Bar.class + # +- examples/ + # +- HelloWorld.class + # + def add_files(files, path, base_dir="") + files.each do |file| + # Add all of the subdirectories if they don't already exist + 1.upto(file.length - 1) do |idx| + full = base_dir + file[0,idx].join("/") + "/" + if !(entries.map{|e|e.name}.include?(full)) + add_file(full, '') + end + end + # Now add the actual file, grabbing data from the filesystem + fd = File.open(File.join( path, file ), "rb") + data = fd.read(fd.stat.size) + fd.close + add_file(base_dir + file.join("/"), data) + end + end end end