【java安全】CC链学习

对cc链的学习作一个总结

CC链总结

image

CC1

•CommonsCollections1,依赖 commons-collections 3.1, 3.2.1

•JDK < 8u72

source:sun.reflect.annotation.AnnotationInvocationHandler#readObject()​ 自己实现了readObject,并且满足一定条件时可以触发到map的get和set方法

gadget:TransformedMap​或LazyMap#get

sink:ChainedTransformer#transform

image

CC2

•依赖 commons-collections 4

source:java.util.PriorityQueue#readObject()​:重写了readObject,其中会对反序列化后的数据进行排序,因此可以构造TransformingComparator,从而触发恶意的Transformer方法

gadget: TransformingComparator#compare()

sink:TemplatesImpl#newTransformer()

image

CC3

•CommonsCollections3,依赖 commons-collections 3.1, 3.2.1

•JDK < 8u72

source: AnnotationInvocationHandler#readObject()

gadget: InstantiateTransformer#transform()

sink: TemplatesImpl#newTransformer()

前面和CC1是一样的,都是AnnotationInvocationHandler#readObject()​触发到LazyMap#get()​,从而触发Transformer​,而这里使用到InstantiateTransformer​实例化TrAXFilter​,TrAXFilter​实例化过程中调用到sink点

image

CC4

•CommonsCollections4,依赖 commons-collections 4

source:java.util.PriorityQueue#readObject()

gadget:InstantiateTransformer#transform()

sink:TemplatesImpl#newTransformer()

CC2的前部分+CC3的后部分

image

CC5

•CommonsCollections5,依赖 commons-collections 3.1, 3.2.1

source:javax.management.BadAttributeValueExpException#readObject()

gadget:org.apache.commons.collections.keyvalue.TiedMapEntry#toString()

sink:org.apache.commons.collections.functors.InvokerTransformer#transform()

引入TiedMapEntry​,其equals/hashCode/toString​方法会调用getValue​方法,从而触发底层map的get方法

BadAttributeValueExpException​可以触发任意类的tostring​方法,TiedMapEntry​的tostring​方法中触发map的get操作,从而连接lazymap -> transformer调用

image

CC6

•CommonsCollections6,依赖 commons-collections 3.1, 3.2.1

source:java.util.HashSet#readObject()

gadget:org.apache.commons.collections.keyvalue.TiedMapEntry#hashCode()

sink:org.apache.commons.collections.functors.InvokerTransformer#transform()

HashSet#readObject()​会调用其内部HashMap#put()​从而调用其hash​方法,进而调用到TiedMapEntry#hashCode()​再到lazymap#get​->Transformer

image

CC7

•CommonsCollections7,依赖 commons-collections 3.1, 3.2.1

source: java.util.Hashtable#readObject()

gadget: org.apache.commons.collections.keyvalue.TiedMapEntry#hashCode()​、AbstractMap.equals()

sink: org.apache.commons.collections.functors.InvokerTransformer#transform()

引入Hashtable​,其readObject方法中会调用到key的hashcode​、equals​方法,因此可以想到继续使用TiedMapEntry​串链

这里改用AbstractMap#equals()​串联,其equals方法中可以触发map的get方法

image