Posted by Trancer on Jun 03 2009

JavaHere’s a new shiny mixin I wrote for the Metasploit framework – the Java Compilation mixin.
The purpose of this mixin is to bring the power of Metasploit and use it for writing and compiling Java code on-the-fly.
The mixin main usage is to write, compile and embed Java code (Java applets) in HTML pages, mainly for writing exploit and auxiliary modules that exploit vulnerabilities in the JRE\JVM.
The Java compilation mixin can also be used for creating fuzzers and other testing tools for the JRE\JVM.

Code:
javacompile.rb.

Installation:
Place the mixin in the following path:
\msf3\lib\msf\core\exploit

Include the mixin in \msf3\lib\msf\core\exploit.rb file:
# JavaCompile
require 'msf/core/exploit/javacompile'

Using the mixin in exploit and auxiliary modules:
include Msf::Exploit::JAVACOMPILE

The mixin requires JDK to be installed, get it from Sun.

Usage:
OUTPUTPATH – defines the path of the working directory (where the files will be created).

java_compile(filename,data) function is used to compile Java code. filename variable sets the file and public class name and data variable defines the Java code.

java_clean(filename) function is used to clean the working directory. filename variable sets the file name to delete (both .java and .class files) from the working directory.

Demonstration:
The following “exploit” module demonstrate the Java compilation mixin by calling a simple Java applet (displaying “Hello World”) from an HTML page:
java_hello.rb (See comments in the code).

This mixin is still in an early stage and will be modified and improved in time, any kind of feedback and suggestions are welcome.
Cool exploits soon to follow :-)

Categories: Metasploit

6 Responses to “Java Compilation mixin for Metasploit”

  1. cP says:

    Nice one :) you have lots of free time :P

  2. Trancer says:

    haha I wish :)

  3. bulgin says:

    How would you go about using this in 3.3? I see that exploit.rb has been re-written.

  4. Trancer says:

    @bulgin
    Soon there will be a new version of the Java compilation mixin module :P
    And, in Metasploit 3.3 all mixins are in mixins.rb now.

  5. bulgin says:

    Would be greeeeaaaat if a user could manipulate the registry and/or use windows variables such as %homepath% or %userprofiles% instead of only being able to download to root directory.

    Thanks for the great work!

    I look forward to the new developments and let me know when they are out.

  6. Trancer says:

    @bulgin
    Thank you for your feedback.
    You could output the generated Java/Class files wherever you like, just change the OUTPUTPATH location.
    And what do you mean by “manipulate the registry”?

Leave a Reply


Follow Recognize-Security on Twitter