CC1链(TransformedMap版)上:环境搭建与核心类解析

admin 2026-02-05 07:03:16 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 本文解析Java反序列化CC1链TransformedMap版的环境搭建与核心类原理。通过配置JDK8u65及Maven依赖,深入剖析Transformer接口及其实现类ConstantTransformer与ChainedTransformer。重点讲解InvokerTransformer如何利用反射机制实现任意方法调用,这是构建反序列化攻击链的关键基础,为后续构造完整利用链提供了必要的技术铺垫。 综合评分: 75 文章分类: 代码审计,漏洞分析,WEB安全


cover_image

CC1链(TransformedMap版)上:环境搭建与核心类解析

原创

Pai Pai

湘岚实验室

2026年2月4日 17:19 江苏

CC1链(TransformedMap版)

红烧花园宝宝:https://lxu2n.github.io/posts/9e8a5add/

白日梦组长视频:https://www.bilibili.com/video/BV1no4y1U7E1/?spm_id_from=333.1387.homepage.video_card.click

文章:https://drun1baby.top/2022/06/06/Java反序列化Commons-Collections篇01-CC1链/

环境搭建

  • JDK8u65:https://www.oracle.com/cn/java/technologies/javase/javase8-archive-downloads.html
  • https://github.com/frohoff/jdk8u-jdk/tree/master/src/share/classes/sun
  • Maven3.6.3:安装教程 https://blog.csdn.net/qq_46554590/article/details/119428896

新建一个Java项目,使用JDK8u65、Maven3.6.3

image-20251026095523827

image-20251026100433147

在项目根目录中的pom.xml中添加对CC1链的依赖包

<?xml version="1.0" encoding="UTF-8"?>
<project&nbsp;xmlns="http://maven.apache.org/POM/4.0.0"
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
&nbsp; &nbsp;&nbsp;<modelVersion>4.0.0</modelVersion>

&nbsp; &nbsp;&nbsp;<groupId>org.example</groupId>
&nbsp; &nbsp;&nbsp;<artifactId>CC1</artifactId>
&nbsp; &nbsp;&nbsp;<version>1.0-SNAPSHOT</version>

&nbsp; &nbsp;&nbsp;<properties>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<maven.compiler.source>8</maven.compiler.source>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<maven.compiler.target>8</maven.compiler.target>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
&nbsp; &nbsp;&nbsp;</properties>

&nbsp; &nbsp;&nbsp;<dependencies>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<dependency>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<groupId>commons-collections</groupId>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<artifactId>commons-collections</artifactId>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<version>3.2.1</version>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</dependency>
&nbsp; &nbsp;&nbsp;</dependencies>
</project>

image-20251209155010971

可以importCC包验证一下,没有报错就是成功了

import&nbsp;org.apache.commons.collections.functors.InvokerTransformer;

直接解压缩JDK8u65的src压缩包,然后打开项目结构中的SDK,在源路径中将src导入进去

image-20251209155234372

image-20251209155253809

可以跑个程序验证一下,没报错就是成功

import&nbsp;org.apache.commons.collections.functors.InvokerTransformer;

public&nbsp;class&nbsp;Test&nbsp;{
&nbsp; &nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[] args)&nbsp;throws&nbsp;Exception{
&nbsp; &nbsp; &nbsp; &nbsp; Class.forName("sun.reflect.annotation.AnnotationInvocationHandler");
&nbsp; &nbsp; }
}

image-20251209155317463

Common-Collections介绍

大佬文章:闪烁之狐https://blinkfox.github.io/2018/09/13/hou-duan/java/commons/commons-collections-bao-he-jian-jie/

简单来说,Common-Collections 这个项目开发出来是为了给 Java 标准的 Collections API 提供了相当好的补充,在此基础上对其常用的数据结构操作进行了很好的封装、抽象和补充

包结构

  • org.apache.commons.collections – CommonsCollections自定义的一组公用的接口和工具类
  • org.apache.commons.collections.bag – 实现Bag接口的一组类
  • org.apache.commons.collections.bidimap – 实现BidiMap系列接口的一组类
  • org.apache.commons.collections.buffer – 实现Buffer接口的一组类
  • org.apache.commons.collections.collection –实现java.util.Collection接口的一组类
  • org.apache.commons.collections.comparators– 实现java.util.Comparator接口的一组类
  • org.apache.commons.collections.functors –Commons Collections自定义的一组功能类
  • org.apache.commons.collections.iterators – 实现java.util.Iterator接口的一组类
  • org.apache.commons.collections.keyvalue – 实现集合和键/值映射相关的一组类
  • org.apache.commons.collections.list – 实现java.util.List接口的一组类
  • org.apache.commons.collections.map – 实现Map系列接口的一组类
  • org.apache.commons.collections.set – 实现Set系列接口的一组类

攻击链分析

目的利用runtime

public class&nbsp;test&nbsp;{
&nbsp; &nbsp; public static void main(String[] args) throws Exception{
&nbsp; &nbsp; &nbsp; &nbsp; Runtime.getRuntime().exec("calc");
&nbsp; &nbsp; }
}

反序列化的攻击思路

在入口类需要一个readObject方法,在结尾需要一个能够命令执行的方法,中间通过链子引导过去,从尾部出发去寻找头

先找到一个可以利用的类(调用可以执行命令的方法A),然后后再去找调用了这个方法A的方法B,然后继续找调用了方法B的方法C,就这样一直找,直到找到了readObject方法,对其重写

img

寻找实现类

因为Runtime类是不能序列化的,所以要使用反射才能调用类中的getRuntime方法、exec方法

image-20251027165224080

这个是我们注重分析的

image-20260203205834041

因为Runtime类是不能序列化的,所以要使用反射才能调用类中的getRuntime方法、exec方法

Transformer

Transformer接口,点击选中Transformer,快捷键ctrl+alt+B查看实现接口的类,可以发现:ChainedTransformerConstantTransformerInvokerTransformer这三个类

image-20260203210217689

ConstantTransformer

image-20260203210629286

&nbsp;public&nbsp;Object&nbsp;transform(Object input)&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;iConstant;
&nbsp; &nbsp; }

这个意思是不管接受什么,都返回它本身

ChainedTransformer

看名字可得这个是链式的,

&nbsp; &nbsp;&nbsp;public&nbsp;ChainedTransformer(Transformer[] transformers)&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;super();
&nbsp; &nbsp; &nbsp; &nbsp; iTransformers = transformers;
&nbsp; &nbsp; }

&nbsp; &nbsp;&nbsp;/**
&nbsp; &nbsp; &nbsp;* Transforms the input to result via each decorated transformer
&nbsp; &nbsp; &nbsp;*
&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;object &nbsp;the input object passed to the first transformer
&nbsp; &nbsp; &nbsp;*&nbsp;@return&nbsp;the transformed result
&nbsp; &nbsp; &nbsp;*/
&nbsp; &nbsp;&nbsp;public&nbsp;Object&nbsp;transform(Object object)&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;i =&nbsp;0; i < iTransformers.length; i++) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object = iTransformers[i].transform(object);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;object;
&nbsp; &nbsp; }

大概作用是赋值的时候他会传一个调用方法的数组,把传进去的对象链式调用,前一个输出作为后一个的输入,递归调用

InvokerTransformer //重点

&nbsp; &nbsp;&nbsp;public&nbsp;Object&nbsp;transform(Object input)&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(input ==&nbsp;null) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;returnnull;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;try&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Class cls = input.getClass();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Method method = cls.getMethod(iMethodName, iParamTypes);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;method.invoke(input, iArgs);

&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;catch&nbsp;(NoSuchMethodException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;thrownew&nbsp;FunctorException("InvokerTransformer: The method '"&nbsp;+ iMethodName +&nbsp;"' on '"&nbsp;+ input.getClass() +&nbsp;"' does not exist");
&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;catch&nbsp;(IllegalAccessException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;thrownew&nbsp;FunctorException("InvokerTransformer: The method '"&nbsp;+ iMethodName +&nbsp;"' on '"&nbsp;+ input.getClass() +&nbsp;"' cannot be accessed");
&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;catch&nbsp;(InvocationTargetException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;thrownew&nbsp;FunctorException("InvokerTransformer: The method '"&nbsp;+ iMethodName +&nbsp;"' on '"&nbsp;+ input.getClass() +&nbsp;"' threw an exception", ex);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }

}

在这里接受一个对象然后反射调用,有方法值,参数类型,参数都可控,即任意方法调用,即攻击链分析的最后一点

public&nbsp;InvokerTransformer(String methodName, Class[] paramTypes, Object[] args)&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;super();
&nbsp; &nbsp; &nbsp; &nbsp; iMethodName = methodName;
&nbsp; &nbsp; &nbsp; &nbsp; iParamTypes = paramTypes;
&nbsp; &nbsp; &nbsp; &nbsp; iArgs = args;
&nbsp; &nbsp; }
&nbsp;try&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Class cls = input.getClass();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Method method = cls.getMethod(iMethodName, iParamTypes);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;method.invoke(input, iArgs);

&nbsp; &nbsp; &nbsp; &nbsp; }

-END-


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:湘岚实验室 Pai Pai《CC1链(TransformedMap版)上:环境搭建与核心类解析》

网络安全细分16个专业 网络安全文章

网络安全细分16个专业

文章总结: 本文概述网络安全16个专业方向,划分为基础防御、技术攻坚、体系构建、战略管理及新兴前沿五个层级,涵盖监控检测、渗透测试、威胁情报等核心内容。文章建议
评论:0   参与:  0