IBM Java 获取默认值(以缓解 CVE-2021-44228 AKA Log4Shell 漏洞)

Til*_*ilo 9 java websphere

如何在 Java (IBM Java) 上转储默认值以检查以下默认值?

"com.sun.jndi.rmi.object.trustURLCodebase"
"com.sun.jndi.cosnaming.object.trustURLCodebase"
Run Code Online (Sandbox Code Playgroud)

类似这样,但对于上述参数:

"com.sun.jndi.rmi.object.trustURLCodebase"
"com.sun.jndi.cosnaming.object.trustURLCodebase"
Run Code Online (Sandbox Code Playgroud)

这是针对CVE-2021-44228缓解审查的。

理想情况下,这可以在 cmd 上检查,而不需要运行测试代码。

这是我尝试的测试代码,但未显示(显示 Null):

java -XX:+PrintFlagsFinal -version
Run Code Online (Sandbox Code Playgroud)

编译并运行:

import java.util.Properties;

class TiloDisplay
{
    public static void main(String[] args)
    {
        Properties prop = System.getProperties();
        printProperties(prop);
    }

    public static void printProperties(Properties prop) {
        prop.stringPropertyNames().stream()
                .map(key -> key + ": " + prop.getProperty(key))
                .forEach(System.out::println);
        System.out.println("CVE check part ========================================== " );
        System.out.println("CVE check for:: com.sun.jndi.ldap.object.trustURLCodebase: " + prop.getProperty("com.sun.jndi.ldap.object.trustURLCodebase"));
        System.out.println("CVE check for:: com.sun.jndi.rmi.object.trustURLCodebase: " + prop.getProperty("com.sun.jndi.rmi.object.trustURLCodebase"));
        System.out.println("CVE check for:: com.sun.jndi.cosnaming.object.trustURLCodebase: " + prop.getProperty("com.sun.jndi.cosnaming.object.trustURLCodebase"));
        System.out.println("Cross Check: " + prop.getProperty("java.version"));
    }
}
Run Code Online (Sandbox Code Playgroud)

Vol*_*ıcı 9

CVE-2021-44228 根据攻击者的想象力创建了一个巨大的攻击面,RCE只是其中之一。

我强烈建议您避免依赖针对特定攻击向量的 JVM 功能得出错误的结论;还有更多的向量。只需升级log4j-core到 2.15.0 或设置log4j2.formatMsgNoLookups=true系统属性即可。

  • 你是对的@Vokan,但这仍然是一个有效的问题...... (2认同)

che*_*hes 7

回答问题的信件

默认情况下,相关系统属性似乎没有任何值。如果他们这样做了,您可以检查:

java -XshowSettings:properties -version
Run Code Online (Sandbox Code Playgroud)

请注意,-X标志是非标准的,尽管 IBM Java 支持这一标志(已检查 Semeru 11)。

至于上下文

实现(至少在OpenJDKfalse中)查询属性值,默认为属性未设置,例如,

java -XshowSettings:properties -version
Run Code Online (Sandbox Code Playgroud)

因此,-XshowSettings问题中的编程检查都无法帮助确定您的 JVM 对于这些功能默认的行为,或者如果您显式设置它们,您正在运行的 JVM 版本是否使用这些属性。

我同意Volkan 的观点,但我还想验证这些(危险的)JNDI功能是否已禁用,无论 Log4j 漏洞如何。不幸的是,尽管我们需要另一种方法来做到这一点,最好是一种独立于实现的方法。