### # # javacompile.rb mixin v0.2 # by Trancer - www.rec-sec.com # # Java Compilation mixin for the Metasploit Framework. # This mixin enables on-the-fly Java code compilation. # # Usage: # # OUTPUTPATH - defines the path of the working directory (where the files will be created). # # java_compile(filename,data) - Compiling Java code. # filename - the file and public class name. # data - the Java code to compile. # # java_clean(filename) - Cleaning the working directory. # filename - the file name to delete (both .java and .class files). # ### module Msf module Exploit::JAVACOMPILE def initialize(info = {}) super register_options( [ OptString.new('OUTPUTPATH', [ true, 'Working directory location.', File.join(Msf::Config.install_root, 'data', 'exploits', 'java')]), ], Msf::Exploit::JAVACOMPILE ) end def java_compile(filename,data) binfile = '' srcfile = filename + ".java" outfile = filename + ".class" srcpath = File.expand_path(File.join(datastore['OUTPUTPATH'], srcfile)) outpath = File.expand_path(File.join(datastore['OUTPUTPATH'], outfile)) tmpfile = File.new(srcpath,"wb") tmpfile.write(data) tmpfile.close print_status("File #{srcfile} created.") system("javac #{srcpath}") if !File.exist?("#{outpath}") print_status("File #{srcfile} did not compile.") else print_status("File #{outfile} created.") jfile = File.open(outpath,"rb") binfile = jfile.read jfile.close return binfile end end def java_clean(filename) srcfile = filename + ".java" outfile = filename + ".class" srcpath = File.expand_path(File.join(datastore['OUTPUTPATH'], srcfile)) outpath = File.expand_path(File.join(datastore['OUTPUTPATH'], outfile)) File.delete(srcpath) File.delete(outpath) print_status("Working directory cleaned.") return end end end