Java4Shell: Is Your Server Next? Find Every Vulnerable JVM

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Java4Shell: Is Your Server Next? Find Every Vulnerable JVM

CVE-2026-114938 (Java4Shell) 是 OpenJDK AVX-512 Base64 解码器中的堆缓冲区溢出漏洞。我在另一篇文章中介绍了背景信息。本文是一份操作手册:如何查找关键的 JVM、运行什么命令、更改什么设置以及如何验证其有效性。我尚未在易受攻击的机器上运行这些命令。这些命令来自 Qualys、Upwind、Endor Labs 和 Equixly 的报告,我仅核实了 shell 和 Java 代码片段的语法。请先在测试环境中运行。

TL;DR Step Goal Time

  1. Inventory Find the real runtime behind every Java process minutes per host
  2. Hardware check Split hosts by AVX-512 VBMI seconds
  3. Patch Move to a vendor build that carries the fix your restart window
  4. Mitigate Apply a JVM flag where you cannot patch one restart
  5. Verify Prove the flag or build is live in the running process seconds
  6. Watch Alert on crash and decode patterns ongoing

简而言之: 步骤 目标 时间

  1. 清单 查找每个 Java 进程背后的实际运行时 每台主机几分钟

  2. 硬件检查 按 AVX-512 VBMI 分割主机 几秒钟

  3. 修补 迁移到包含修复程序的供应商版本 您的重启窗口

  4. 缓解 在无法修补的地方应用 JVM 标志 重启一次

  5. 验证 证明标志或版本在运行的进程中生效 几秒钟

  6. 监控 对崩溃和解码模式发出警报 持续进行

  7. Inventory the JVM that actually runs Your shell’s java tells you very little. Jenkins, Jira, Confluence, Keycloak and Elasticsearch ship or select their own runtime. Equixly and Endor Labs both call this out. Ask the process.

  8. 清单:实际运行的 JVM 你 shell 中的 java 命令提供的信息很少。Jenkins、Jira、Confluence、Keycloak 和 Elasticsearch 都会自带或选择自己的运行时。Equixly 和 Endor Labs 都指出了这一点。直接询问进程本身。

#!/usr/bin/env bash
# jvm-inventory.sh: one line per running JVM with its real binary and version
set -u
for pid in $(pgrep -f '[j]ava'); do
  exe=$(readlink -f "/proc/$pid/exe" 2>/dev/null || echo unknown)
  ver=$(jcmd "$pid" VM.version 2>/dev/null | grep -m1 -E 'JDK|OpenJDK' || echo "jcmd unavailable")
  printf '%s\t%s\t%s\n' "$pid" "$exe" "$ver"
done

jcmd must run as the same user as the target JVM. If it prints “jcmd unavailable”, the process may be a minimal runtime without the JDK tools. Fall back to “$exe” -version.

jcmd 必须以与目标 JVM 相同的用户身份运行。如果它打印“jcmd unavailable”,则该进程可能是一个没有 JDK 工具的最小运行时。请回退使用 “$exe” -version。

Version triage, using the ranges Qualys and Upwind list. Line Affected Fixed Oracle build 17 17.0.6 and later, before the fix 17.0.21.1 21 up to 21.0.13 21.0.13.1 25 up to 25.0.5 25.0.5.1 27 up to 27.0.1 27.0.1.1 8 Oracle Enterprise Performance Pack 8u511b33-perf 8u513-perf 11, 17.0.0 to 17.0.5, standard 8 not affected none needed

版本分类,使用 Qualys 和 Upwind 列出的范围: 行 受影响版本 修复版本 Oracle 构建 17 17.0.6 及之后,修复前 17.0.21.1 21 21.0.13 及之前 21.0.13.1 25 25.0.5 及之前 25.0.5.1 27 27.0.1 及之前 27.0.1.1 8 Oracle 企业性能包 8u511b33-perf 8u513-perf 11, 17.0.0 到 17.0.5, 标准 8 不受影响 无需操作

A version number is not proof. Endor Labs warns that an LTS build with a matching number may still lack the commit, because the fix is tracked as JDK-8393212. Treat the vendor advisory as the source of truth, and note that Qualys lists Corretto 17.0.21.1.2 as released.

版本号并不能作为证明。Endor Labs 警告称,具有匹配版本号的 LTS 构建可能仍缺少该提交,因为该修复程序被追踪为 JDK-8393212。请将供应商公告视为事实来源,并注意 Qualys 已将 Corretto 17.0.21.1.2 列为已发布。

  1. Check the hardware Only x86-64 hosts with AVX-512 VBMI reach the vulnerable routine. Run this on each host or container node. grep -m1 ‘^flags’ /proc/cpuinfo | tr ’ ’ ‘\n’ | grep -E ’^(avx512f|avx512bw|avx512vbmi|bmi2)$’ | sort

  2. 检查硬件 只有具备 AVX-512 VBMI 的 x86-64 主机才会触发易受攻击的例程。在每台主机或容器节点上运行此命令。 grep -m1 ‘^flags’ /proc/cpuinfo | tr ’ ’ ‘\n’ | grep -E ’^(avx512f|avx512bw|avx512vbmi|bmi2)$’ | sort

Per Qualys, you are on the hardware side of the risk only when all four flags appear. Intel Ice Lake and later server parts and AMD Zen 4 and later qualify. ARM64, including Graviton and Apple silicon, does not. In Kubernetes, pods inherit the node’s CPU, so check the node and not the image.

根据 Qualys 的说法,只有当所有四个标志都出现时,你才处于硬件风险范围内。Intel Ice Lake 及以后的服务器部件和 AMD Zen 4 及以后的部件符合条件。ARM64(包括 Graviton 和 Apple 芯片)则不受影响。在 Kubernetes 中,Pod 继承节点的 CPU,因此请检查节点而不是镜像。

Which nodes would run the vulnerable path

for node in $(kubectl get nodes -o name); do pod=“cpucheck-${node#node/}” kubectl debug “$node” -q —image=busybox —profile=general —
sh -c “grep -m1 ‘^flags’ /proc/cpuinfo | tr ’ ’ ‘\n’ | grep -c avx512vbmi” 2>/dev/null
| sed “s|^|$node avx512vbmi=|” done

哪些节点会运行易受攻击的路径

for node in $(kubectl get nodes -o name); do pod=“cpucheck-${node#node/}” kubectl debug “$node” -q —image=busybox —profile=general —
sh -c “grep -m1 ‘^flags’ /proc/cpuinfo | tr ’ ’ ‘\n’ | grep -c avx512vbmi” 2>/dev/null
| sed “s|^|$node avx512vbmi=|” done

Remember Qualys’s caution: a resize or an instance family change can move a workload onto an affected CPU later. A host that passes today is not a permanent pass.

请记住 Qualys 的警告:调整大小或更改实例系列可能会在以后将工作负载移动到受影响的 CPU 上。今天通过检查的主机并不代表永久安全。

  1. Patch Patching is the only complete fix, and the vendors say so. The steps that bite people are all about the running process. Rebuild container images from a base that carries the fixed JDK, then redeploy. Replacing files on disk does not change a JVM that is already running. Restart every Java process. Without a restart you have patched a file, not a process.

  2. 修补 修补是唯一的完整修复方案,供应商也是这么说的。容易出错的步骤都与正在运行的进程有关。请使用包含已修复 JDK 的基础镜像重新构建容器镜像,然后重新部署。替换磁盘上的文件不会改变已经运行的 JVM。必须重启每个 Java 进程。如果不重启,你只是修补了文件,而不是进程。

For bundled runtimes, take the application vendor’s update, not a hand-swapped JDK, unless the vendor documents it. For Temurin, Zulu, Microsoft, Red Hat and distro packages, confirm the fixed build in the vendor advisory. Equixly could not confirm those on November 17.

对于捆绑的运行时,请采用应用程序供应商的更新,而不是手动替换 JDK,除非供应商有相关文档说明。对于 Temurin、Zulu、Microsoft、Red Hat 和发行版软件包,请在供应商公告中确认修复版本。Equixly 在 11 月 17 日无法确认这些版本。

  1. Mitigate where you cannot patch yet Both Qualys and Upwind recommend one flag first. -XX:-UseBASE64Intrinsics It turns off the fast decoder on any architecture. Qualys warns that large Base64 workloads may slow down, and Upwind reports it stopped the overflow on every affected version they tested. In a container, set it through the environment. ENV JAVA_TOOL_OPTIONS=“-XX:-UseBASE64Intrinsics”

  2. 在无法修补的地方进行缓解 Qualys 和 Upwind 都首先推荐使用一个标志: -XX:-UseBASE64Intrinsics 它会在任何架构上关闭快速解码器。Qualys 警告说,大型 Base64 工作负载可能会变慢,而 Upwind 报告称,它在他们测试的每个受影响版本上都阻止了溢出。在容器中,通过环境变量设置它。 ENV JAVA_TOOL_OPTIONS=“-XX:-UseBASE64Intrinsics”

Two alternatives appear in the write-ups, and each has a trap. Flag Trap -XX:UseAVX=2 Disables all AVX-512, so it can slow unrelated work. On ARM the JVM refuses to start. -XX:DisableIntrinsic=_base64_decodeBlock Without -XX:+UnlockDiagnosticVMOptions the JVM will not start. Pushed through JAVA_TOOL_OPTIONS, Upwind calls it a fleet-wide outage.

报告中出现了两种替代方案,每种都有陷阱。 标志 陷阱 -XX:UseAVX=2 禁用所有 AVX-512,因此可能会减慢不相关的工作。在 ARM 上,JVM 会拒绝启动。 -XX:DisableIntrinsic=_base64_decodeBlock 如果没有 -XX:+UnlockDiagnosticVMOptions,JVM 将无法启动。如果通过 JAVA_TOOL_OPTIONS 推送,Upwind 称这会导致全集群中断。

A reverse proxy is not a control. Qualys says so plainly, and CISA’s size-limit advice does not stop this bug on its own.

反向代理不是一种控制手段。Qualys 明确指出,CISA 关于大小限制的建议本身并不能阻止此漏洞。

  1. Verify in the running process Setting a flag in a manifest proves nothing until you ask the process.

Flag state inside a live JVM

jcmd VM.flags | tr ’ ’ ‘\n’ | grep -E ‘UseBASE64Intrinsics|UseAVX’

Or ask a fresh JVM what it would do with your options

java -XX:+PrintFlagsFinal -version | grep -E ‘UseAVX|UseBASE64Intrinsics’

  1. 在运行的进程中验证 在清单中设置标志并不能证明什么,除非你询问进程本身。

实时 JVM 内部的标志状态

jcmd VM.flags | tr ’ ’ ‘\n’ | grep -E ‘UseBASE64Intrinsics|UseAVX’

或者询问一个新的 JVM 它将如何处理你的选项

java -XX:+PrintFlagsFinal -version | grep -E ‘UseAVX|UseBASE64Intrinsics’

You want UseBASE64Intrinsics = false in the process. Remove the flag after the patch lands, because it costs speed.

你需要进程中的 UseBASE64Intrinsics 为 false。在修补完成后移除该标志,因为它会影响速度。

  1. A guard in your own code If you decode untrusted Base64 with java.util.Base64, you can reject the malformed shape before the decoder sees it. Upwind’s detection heuristic is a Base64-alphabet token of 32 or more characters that ends in = and whose length is not a multiple of 4. Well-formed padded Base64 always has a length divisible by 4.

  2. 在你自己的代码中设置防护 如果你使用 java.util.Base64 解码不受信任的 Base64,你可以在解码器看到它之前拒绝畸形的格式。Upwind 的检测启发式方法是:一个由 32 个或更多字符组成的 Base64 字母表标记,以 = 结尾且长度不是 4 的倍数。格式良好的填充 Base64 的长度总是能被 4 整除。

import java.util.Base64;
public final class SafeBase64 {
    private SafeBase64() {}
    /** Rejects padded input whose length cannot be valid Base64 before decoding. */
    public static byte[] decode(String input) {
        if (input.endsWith("=") && input.length() % 4 != 0) {
            throw new IllegalArgumentException("malformed base64 padding");
        }
        return Base64.getDecoder().decode(input);
    }
}

This is defense in depth. It narrows

这是纵深防御。它缩小了……