简体   繁体   English

Log4j 1:如何在不更新版本到 2.15.0 的情况下缓解 log4j 中的漏洞

[英]Log4j 1: How to mitigate the vulnerability in log4j without updating version to 2.15.0

I am using log4j 1.2.16.我正在使用 log4j 1.2.16。 I am using this with maven selenium testng java project.我将它与 maven selenium testng Z93F725A07423FE1C889F448B33D21F4 项目一起使用。 I am looking for a solution without upgrading the version of log4j.我正在寻找不升级log4j版本的解决方案。

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
</dependency>

Since you're using log4j 1, the specific vulnerability is not present there.由于您使用的是 log4j 1,因此此处不存在 特定漏洞 See http://slf4j.org/log4shell.html :http://slf4j.org/log4shell.html

Is log4j 1.x vulnerable? log4j 1.x 是否易受攻击? As log4j 1.x does not offer a look-up mechanism, it does not suffer from CVE-2021-44228.由于 log4j 1.x 不提供查找机制,因此它不会受到 CVE-2021-44228 的影响。 However, note that log4j 1.x is no longer being maintained.但是,请注意不再维护 log4j 1.x。 Thus, we urge you to migrate to one of its successors such as SLF4J and logback.因此,我们敦促您迁移到它的继任者之一,例如 SLF4J 和 logback。 Do migrate without delaying too much.迁移不要耽误太多时间。 Given that log4j version 1,x is still very widely deployed.鉴于 log4j 版本 1,x 的部署仍然非常广泛。 we have been receiving a steady stream of questions regarding the vulnerability of log4j version 1.x.我们一直收到关于 log4j 版本 1.x 漏洞的稳定 stream 问题。

As log4j 1.x does not offer a look up mechanism, it does not suffer from CVE-2021-44228.由于 log4j 1.x 不提供查找机制,因此它不受 CVE-2021-44228 的影响。

Having said this, log4j 1.x is no longer being maintained with all the entailed security implications.话虽如此,log4j 1.x 不再维护所有必要的安全隐患。 Thus, we definitely urge you to migrate to one of its successors such as SLF4J/logback, sooner rather than later.因此,我们强烈建议您尽快迁移到其继任者之一,例如 SLF4J/logback。 But do migrate without waiting for months.但是不要等待几个月就可以迁移。 Also note that tools exist to automate the migration.另请注意,存在用于自动迁移的工具。

The other answer is not correct.另一个答案是不正确的。 There is also a vulnerability for Version 1.x.版本 1.x 也存在漏洞。 CVE-2021-4104 https://access.redhat.com/security/cve/CVE-2021-4104 : CVE-2021-4104 https://access.redhat.com/security/cve/CVE-2021-4104

A flaw was found in the Java logging library Apache Log4j in version 1.x.在 1.x 版本的 Java 日志库 Apache Log4j 中发现了一个缺陷。 JMSAppender in Log4j 1.x is vulnerable to deserialization of untrusted data. Log4j 1.x 中的 JMSAppender 容易受到不受信任数据的反序列化。 This allows a remote attacker to execute code on the server if the deployed application is configured to use JMSAppender and to the attacker's JMS Broker.如果部署的应用程序配置为使用 JMSAppender 和攻击者的 JMS 代理,这允许远程攻击者在服务器上执行代码。

For the mitigation of this vulnerability:为了缓解此漏洞:

These are the possible mitigations for this flaw for releases version 1.x:以下是针对 1.x 版本的此缺陷的可能缓解措施:

  • Comment out or remove JMSAppender in the Log4j configuration if it is used Log4j配置中的JMSAppender如果使用的话,注释掉或者去掉
  • Remove the JMSAppender class from the classpath.从类路径中删除 JMSAppender class。 For example:例如:

zip -q -d log4j-*.jar org/apache/log4j/net/JMSAppender.class zip -q -d log4j-*.jar org/apache/log4j/net/JMSAppender.class

  • Restrict access for the OS user on the platform running the application to prevent modifying the Log4j configuration by the attacker.限制操作系统用户在运行应用程序的平台上的访问,防止攻击者修改Log4j配置。

Safest solution is an update to log4j2 2.17.0 version.最安全的解决方案是更新 log4j2 2.17.0版本。

use this dependency使用这个依赖

<dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.17.0</version>
</dependency>

Add log4j2.xml file in src/main/resources or src/test/resources.在 src/main/resources 或 src/test/resources 中添加 log4j2.xml 文件。

log4j2.xml log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d [%t] %-5level %logger{36} (%F:%L)- %msg%n" />
        </Console>
        <File name="MyFile" fileName="trace.log" immediateFlush="true" append="true">
            <PatternLayout pattern="%d [%t] %-5level %logger{36} (%F:%L)- %msg%n"/>
        </File>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="Console" />
            <AppenderRef ref="MyFile"/>
        </Root>
    </Loggers>
</Configuration>

Imports needed需要进口

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Usage in java class java class 中的用法

@BeforeClass
    public void generateLog() throws URISyntaxException {
        Logger logger = LogManager.getLogger(Base.class);
    }

I use this command: zip -d /home/server-cliet.jar BOOT-INF/lib/log4j-1.2.17.jar/org/apache/log4j/net/JMSAppender.class我使用这个命令: zip -d /home/server-cliet.jar BOOT-INF/lib/log4j-1.2.17.jar/org/apache/log4j/net/JMSAppender.ZA2F21ED4F8EBC02CBB4CDBB4

(log4j-1.2.17.jar is the dependent jar of server-cliet.jar) (log4j-1.2.17.jar是server-cliet.jar的依赖jar)

it's not working, can anyone help?它不起作用,有人可以帮忙吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM