Detect-DefenseLab GitHub avatar

fastjson2-2.0.61-rce-detection

Detect-DefenseLab

This repository provides a complete reproduction study of the RCE vulnerability in Fastjson2 (≤2.0.62) caused by AutoType white‑list bypass via FNV‑1a hash collision, including root cause analysis, fix diff, exploit chain construction, and a five‑layer defense system.

Stars

5

7-day growth

No data

Forks

3

Open issues

0

License

No data

Last updated

2026-07-27

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

The vulnerability affects all Fastjson2 ≤2.0.62 with default settings—no need to enable SupportAutoType—making it a critical, widely exploitable issue; the repository not only dissects the root cause but also delivers a production‑ready, VM‑verified multi‑layer defense (WAF, Suricata, RASP, HIDS, eBPF) with zero false positives.

Who it is for

  • Security researchers studying Java deserialization vulnerabilities
  • Java developers using Fastjson2 in production
  • DevOps and security engineers responsible for application defense
  • Software architects evaluating migration from Fastjson 1.x to 2.x

Use cases

  • Understanding the FNV‑1a hash collision root cause and AutoType bypass mechanics
  • Assessing and upgrading vulnerable Fastjson2 installations to 2.0.63
  • Implementing WAF rules, Suricata signatures, RASP hooks, and eBPF monitoring to block exploitation
  • Comparing the 1.x vs 2.x vulnerability landscape for unified risk management

Strengths

  • Detailed root cause analysis with pseudo‑code and FNV‑1a collision explanation
  • Complete exploit chain and collision finder tool (C/Python) with a reproducible Docker lab
  • Five‑layer defense (WAF, IDS, RASP, HIDS, eBPF) all VM‑tested with 0 false positives
  • Thorough inter‑generational comparison with Fastjson 1.x study, highlighting the failure of 'upgrade to 2.x' as a panacea

Considerations

  • PoC is not publicly disclosed; all components are for research only in isolated environments
  • The fix (2.0.63) is already released; upgrading is the only complete cure, while defenses are mitigations
  • Requires local setup and Docker to reproduce the lab environment

README quick start

Fastjson2 全版本 RCE 漏洞研究(PR #7695)

研究背景:本目录承接 ../fastjson-1.2.83-rce-detection 中对 Fastjson 1.x 反序列化 RCE 漏洞的研究脉络, 对 Fastjson2 于 2026-07-27 披露、影响全版本(≤ 2.0.62)的 AutoType 绕过 RCE 漏洞做完整复现式研究。

本仓库聚焦:根因剖析 → 修复 diff 解读 → 与 1.x 的代际对比 → 详细 EXP 构造 → 检测与防御。 提供本地研究用漏洞靶场与利用脚本(平行复刻 1.x 的 lab/ 脉络),所有组件仅在研究者自有环境运行。


0. 一句话结论

Fastjson2 在 SupportAutoType 默认关闭 的情况下,仍会对泛型对象元素(Object.class 等)的 @type 做白名单校验。该校验对 @type 字符串逐字符计算增量 FNV-1a 哈希,并在「某前缀哈希命中白名单哈希」时 直接按完整字符串 loadClass,却不校验该前缀文本是否真的等于白名单类名

攻击者据此构造 FNV-1a 选择前缀碰撞(chosen-prefix collision),使一个形如 jar:http://... 的 URL 串的前缀 哈希命中内建白名单,从而让该 URL 串进入应用上下文类加载器(ClassLoader),触发远程类加载 → RCE

修复版本:Fastjson2 2.0.63(修复合入 PR #7695)。受影响:所有 ≤ 2.0.62 且未启用 SafeMode 的 Fastjson2 用法。


1. 漏洞摘要

内容
披露时间2026-07-27(微信公众号文章 + GitHub PR #7695)
组件com.alibaba:fastjson2
受影响版本≤ 2.0.62(含 1.x 迁移建议中推荐的「升级到 fastjson2」用法)
修复版本2.0.63(PR #7695)
漏洞类型反序列化 AutoType 白名单绕过 → 远程类加载 → 任意代码执行
根因增量 FNV-1a 哈希匹配白名单后缺少文本等价校验,可被哈希碰撞绕过
默认配置可利用(无需开启 SupportAutoType,默认关闭即中招)
JDK 版本全版本(与 JDK 版本无关,区别于 1.x 的 JDK 11.0.1 限制)
必要条件应用将不可信 JSON 反序列化为 Object/JSONObject/泛型(最常见用法)
PoC 公开否(原文声明未公开)

⚠️ 关键反讽:1.x 研究结论中「升级到 fastjson2(架构重构,不受此漏洞影响)」正是本漏洞的触发面。 因此 1.x 与 2.x 的防护策略需要重新统一评估


2. 与 1.x 研究的脉络关系

../fastjson-1.2.83-rce-detection 的完整研究脉络(README → 研究日志 → 根因 → 编码 diff → 验证 → 防御)已证明:

  • 1.x 的绕过机制是 @JSONType 资源探测 → LaunchedURLClassLoaderjar: URL 远程 defineClass
  • 1.x 把「升级到 fastjson2」作为根因级修复建议(见 1.x README 【最终结论】)。

本研究的增量贡献在于:fastjson2 用「FNV-1a 哈希白名单」替换了 1.x 的「字符串类名白/黑名单」, 本意是性能优化(避免存完整类名、用 64 位哈希做 O(log n) 二分匹配),但引入了哈希语义不可信这一全新攻击面。 即:1.x 的问题是「名单可被绕过」,2.x 的问题是「哈希碰撞使名单本身失效」。

详细代际对比见 docs/detection/COMPARISON_1X_2X.md


3. 根因(极简版)

ObjectReaderProvider.checkAutoType 的伪代码(修复前):

long hash = MAGIC_HASH_CODE;                 // FNV-1a offset basis
for (int i = 0; i = 0) {
        clazz = loadClass(typeName);          // ★ 用【完整 typeName】去加载类!
        ...                                    //   此时完全没有校验 typeName[0..i] 文本 == 白名单类名
    }
}
  • acceptHashCodes = 内建「基本安全类型」白名单(includeBasic)的 FNV-1a 哈希数组(排序后二分)。
  • 命中条件是哈希值相等,而非字符串相等
  • FNV-1a 是非密码学哈希,64 位空间下可通过「追加约 8~12 字节自由字符」在可行计算量内构造出

Description

fastjson2 (≤ 2.0.61) autoType RCE 检测防御体系 — 五层 × 六产品纵深防御,覆盖完整攻击链,VM 端到端验证通过

Related repositories

Similar projects matched by category, topics, and programming language.

oversecured
oversecured GitHub avatar

Samsung_Vulnerabilities

Oversecured discloses a report of 176 vulnerabilities discovered in Samsung preinstalled apps between 2022 and 2025, with 140 detailed, all fixed in collaboration with Samsung.

Java
310
wxxsfxyzm
wxxsfxyzm GitHub avatar

MiuiBackGestureHook

An LSPosed module that hooks MIUI SystemUI back gestures using modern Xposed API 102 for research and customization.

Java
86
SangLuoCN
SangLuoCN GitHub avatar

OneStep4

OneStep4.0 is a multi-window desktop container for Android that requires root or system-level privileges, enabling a main window with several side windows for efficient app multitasking.

Java
84