Java4Shell: RCE in OpenJDK when processing Base64
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Write once, RCE everywhere
一次编写,随处 RCE
Story by the New York Times
《纽约时报》报道
A memory-corruption vulnerability in OpenJDK’s Base64 decoder. A remote attacker with no credentials can overwrite heap memory, read it in the style of Heartbleed, and reach remote code execution.
OpenJDK 的 Base64 解码器中存在一个内存损坏漏洞。未经授权的远程攻击者可以覆盖堆内存,以类似“心脏出血”(Heartbleed)的方式读取数据,并实现远程代码执行。
Begin ↓ Technical write-up ↘ Check your servers ↘ Recommendations ↘
开始 ↓ 技术报告 ↘ 检查您的服务器 ↘ 建议 ↘
After we disclosed PHP2Shell, we realized many people didn’t know what PHP was. So we decided to go after something a little more familiar: Java.
在我们披露 PHP2Shell 之后,我们意识到许多人并不了解 PHP。因此,我们决定研究一个大家更熟悉的目标:Java。
Today, we are disclosing Java4Shell (CVE-2026-114938), a memory-corruption vulnerability in OpenJDK’s Base64 decoder. OpenJDK is the most popular Java runtime. Under CVSS 4.0, this vulnerability scores 9.2 out of 10 (CRITICAL).
今天,我们披露了 Java4Shell (CVE-2026-114938),这是 OpenJDK Base64 解码器中的一个内存损坏漏洞。OpenJDK 是最流行的 Java 运行时环境。根据 CVSS 4.0 标准,该漏洞评分为 9.2 分(最高 10 分,属于“严重”级别)。
While PHP is a high-level web technology, Java sits much deeper. Java is the world’s third most popular programming language, powering 90% of Fortune 500 companies. It is the beating heart of the modern economy. Banking, aviation, telecommunications, nearly every critical sector runs on Java, including national security systems.
虽然 PHP 是一种高级 Web 技术,但 Java 的地位要深远得多。Java 是全球第三大最受欢迎的编程语言,为 90% 的财富 500 强企业提供支持。它是现代经济跳动的心脏。银行、航空、电信,几乎每个关键领域都在运行 Java,包括国家安全系统。
Base64 is a very common way of representing binary data as text. It is used in authentication protocols, to encode file uploads, and to deliver network messages. To decode Base64 faster, OpenJDK uses specialized x86-64 CPU instructions to process many bytes at once. We discovered a bug in that optimized machine-level code that lets malformed input overwrite neighboring memory. With careful exploitation, the corruption can reveal sensitive memory, as Heartbleed did, or lead to remote code execution. The corruption itself can be triggered by just 64 A characters followed by a single =:
Base64 是一种将二进制数据表示为文本的常用方式。它被用于身份验证协议、编码文件上传以及传输网络消息。为了加快 Base64 解码速度,OpenJDK 使用专门的 x86-64 CPU 指令来同时处理多个字节。我们在该优化后的机器级代码中发现了一个漏洞,它允许畸形输入覆盖相邻内存。通过精心利用,这种损坏可以像“心脏出血”漏洞一样泄露敏感内存,或导致远程代码执行。该损坏只需 64 个字符“A”后跟一个“=”即可触发:
In older OpenJDK 17, the trigger input is 128 of A followed by =.
在较旧的 OpenJDK 17 版本中,触发输入为 128 个“A”后跟一个“=”。
Our initial testing demonstrated remote code execution in the following widely deployed Java applications, in their default configs.
我们的初步测试证明,在以下广泛部署的 Java 应用程序的默认配置中,可以实现远程代码执行。
The lists are non-exhaustive. We also demonstrated RCE in sample applications built on widely used frameworks, including Apache Struts and Spring Boot. Ordinary features such as authentication and file uploads can expose the vulnerable Base64 decoder, extending the potential impact far beyond the products we tested. samczsun also shared a client-side exploit with us. A Java program that opens a TLS connection to a malicious server can be compromised, even if it exposes no service of its own.
该列表并不详尽。我们还在基于广泛使用的框架(包括 Apache Struts 和 Spring Boot)构建的示例应用程序中演示了 RCE。身份验证和文件上传等普通功能可能会暴露易受攻击的 Base64 解码器,从而将潜在影响范围扩大到我们测试的产品之外。samczsun 还与我们分享了一个客户端漏洞利用程序。一个打开通往恶意服务器 TLS 连接的 Java 程序,即使它本身没有暴露任何服务,也可能遭到入侵。
Here are a demo video of the exploits running:
以下是漏洞利用运行的演示视频:
Memory corruption is the most common class of vulnerability on the Internet. But one of Java’s biggest selling points is memory safety. Java manages memory on developers’ behalf and checks memory accesses, protecting applications from the memory-corruption bugs common in other software.
内存损坏是互联网上最常见的漏洞类型。但 Java 的最大卖点之一是内存安全性。Java 代替开发人员管理内存并检查内存访问,从而保护应用程序免受其他软件中常见的内存损坏错误的影响。
But like PHP and many other technologies, much of Java itself is written in low-level languages like C, C++, and, in this case, assembly, where memory corruption is still a part of life.
但与 PHP 和许多其他技术一样,Java 本身的大部分代码是用 C、C++ 等低级语言编写的,在本例中还涉及汇编语言,而在这些语言中,内存损坏仍然是不可避免的问题。
To speed up Base64 decoding, OpenJDK uses specialized AVX-512 VBMI instructions on supported x86-64 processors. The bug sits in the hand-rolled assembly code that handles the final few characters. For the 65-character input above, OpenJDK allocates a 50-byte result array. After decoding the first 64 characters, the routine mishandles the stray = and calculates a negative output length. That invalid length becomes a full 64-byte write, sending 62 bytes past the end of the array. Java eventually rejects the input, but by then neighboring objects may already be corrupted.
为了加速 Base64 解码,OpenJDK 在支持的 x86-64 处理器上使用了专门的 AVX-512 VBMI 指令。该漏洞位于处理最后几个字符的手写汇编代码中。对于上述 65 个字符的输入,OpenJDK 会分配一个 50 字节的结果数组。在解码前 64 个字符后,该例程错误地处理了多余的“=”,并计算出了一个负的输出长度。这个无效的长度导致了完整的 64 字节写入,从而越过了数组末尾 62 个字节。Java 最终会拒绝该输入,但到那时,相邻的对象可能已经被损坏。
As with PHP2Shell, Calif used AI to find and weaponize Java4Shell. AI brings the horsepower. Our researchers bring the context. The best hacker today is neither AI nor human. It is the centaur hacker, part human, part AI.
与 PHP2Shell 一样,Calif 使用人工智能来发现并武器化 Java4Shell。人工智能提供了算力,而我们的研究人员提供了背景知识。当今最优秀的黑客既不是人工智能,也不是人类,而是“半人马黑客”——即人机协作的黑客。
It took our own Quang Luong an hour to discover the vulnerability, and two more hours to develop the first working exploit. The total token cost was less than $200.
我们的研究员 Quang Luong 花了一个小时发现了该漏洞,又花了两个小时开发出第一个可用的漏洞利用程序。总的 Token 成本不到 200 美元。
One thing to note about this vulnerability is that there is no universal exploit. Depending on how Base64 is used and how the application works, different steps may be required for exploitation. Calif was able to accelerate the exploit development by spending initial effort building pipelines and strategies, then directing AI agents to use those for initial exploitation. Afterwards, most of the later chains are built almost autonomously with AI.
关于此漏洞需要注意的一点是,没有通用的漏洞利用程序。根据 Base64 的使用方式和应用程序的工作原理,利用该漏洞可能需要不同的步骤。Calif 通过投入初期精力构建流水线和策略,然后指导 AI 代理进行初步利用,从而加速了漏洞利用的开发。此后,后续的大部分链式攻击几乎都是由 AI 自主构建的。
Java is one of many shared software stacks we all rely on. Over the years, it has grown to serve many different needs. Each feature request may make sense on its own, but everyone inherits the added complexity. Those who need a feature get the benefit. Everyone else carries the code and its risks, even if they never use it.
Java 是我们共同依赖的众多共享软件栈之一。多年来,它不断发展以满足各种不同的需求。每个功能请求本身可能都有道理,但每个人都继承了由此增加的复杂性。需要该功能的人获得了收益,而其他人则承担了代码及其带来的风险,即使他们从未使用过该功能。
Java4Shell is a concrete example. The Base64 optimization helps applications that decode enormous amounts of data. But the code ships to everyone else too, including applications that gain little from it. On affected systems, an optimization few applications needed became a serious security risk.
Java4Shell 就是一个具体的例子。Base64 优化有助于那些解码海量数据的应用程序。但该代码也随之分发给了其他人,包括那些几乎从中获益甚微的应用程序。在受影响的系统上,一个很少有应用程序需要的优化措施变成了一个严重的安全风险。
Features can be useful, and most bugs can be fixed. But why do we have to worry about code we never needed in the first place?
功能可能很有用,大多数错误也可以修复。但我们为什么要为那些我们根本不需要的代码而担忧呢?
If you don’t need something, there is little reason to keep it running in your systems. Do you need that hand-rolled assembly Base64 decoder to process a few hundred bytes? Probably not.
如果你不需要某样东西,就没有理由让它在你的系统中运行。你需要那个手写的汇编 Base64 解码器来处理几百个字节吗?可能不需要。
Earlier this year we found Squidbleed, an older cousin of Heartbleed, hiding in the Squid proxy since 1997. The bug was in Squid’s FTP module. But who uses FTP anymore? It’s a dead protocol and should be removed.
今年早些时候,我们发现了 Squidbleed,它是“心脏出血”漏洞的“老表”,自 1997 年以来一直隐藏在 Squid 代理中。该漏洞位于 Squid 的 FTP 模块中。但现在还有谁在使用 FTP 呢?这已经是一个过时的协议,应该被移除。
Removing code is harder than it sounds. An apparently unused feature may have hidden dependencies. Someone has to understand what can be removed, make the change, and test what remains.
移除代码比听起来要困难得多。一个看似未使用的功能可能存在隐藏的依赖关系。必须有人了解哪些可以移除,进行更改,并测试剩余的部分。
This is where AI can help to make that work practical at a scale we could not previously afford.
这就是人工智能可以发挥作用的地方,它能以我们以前无法负担的规模使这项工作变得切实可行。
The same centaur hacker that discovered PHP2Shell and Java4Shell can comb a large codebase and flag dead code, bloated features, and needless optimizations. We call this vibe-uncoding: identify the parts a system actually needs, then remove everything else.
发现 PHP2Shell 和 Java4Shell 的那位“半人马黑客”可以梳理大型代码库,并标记出死代码、臃肿的功能和不必要的优化。我们称之为“直觉去代码化”(vibe-uncoding):识别系统真正需要的部分,然后移除其他所有内容。