简体   繁体   English

zip -d log4j-1.X.jar 不工作(log4j 1.X 漏洞 CVE-2021-4104)

[英]zip -d log4j-1.X.jar not working (log4j 1.X vulnerability CVE-2021-4104 )

I want to fix the Log4J 1.* vulnerability by using this command:我想使用以下命令修复Log4J 1.* 漏洞:

zip -d /home/server-cliet.jar::BOOT-INF/lib/log4j-1.2.17.jar org/apache/log4j/net/JMSAppender.class

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

This command result is:该命令结果为:

zip warning:/home/server-cliet.jar::BOOT-INF/lib/log4j-1.2.17.jar not found or empty. zip 警告:/home/server-cliet.jar::BOOT-INF/lib/log4j-1.2.17.jar 未找到或为空。

I use another command:我使用另一个命令:

zip -d /home/server-cliet.jar BOOT-INF/lib/log4j-1.2.17.jar/org/apache/log4j/net/JMSAppender.class

Result is:结果是:

zip warning:name not matched:BOOT-INF/lib/log4j-1.2.17.jar/org/apache/log4j/net/JMSAppender.class zip 警告:名称不匹配:BOOT-INF/lib/log4j-1.2.17.jar/org/apache/log4j/net/JMSAppender.class

please help!请帮忙!

First you need to understand what you are trying to do.首先,您需要了解您正在尝试做什么。 The command that you are trying to run appears to be attempting to remove a class from a JAR file that is embedded in another JAR file.您尝试运行的命令似乎试图从嵌入另一个 JAR 文件的 JAR 文件中删除 class。 The outer JAR file appears to be an executable Spring application... or something like that.外部 JAR 文件似乎是可执行的 Spring 应用程序......或类似的东西。 ("BOOT-INF/" is used by the Spring application loader.) The inner JAR is a log4j 1.x JAR. ("BOOT-INF/" is used by the Spring application loader.) The inner JAR is a log4j 1.x JAR.

Next, you need to understand how the zip and unzip commands work on Linux.接下来,您需要了解zip unzip命令如何在 Linux 上工作。 Read the manual entries: man 1 zip and man 1 unzip .阅读手册条目: man 1 zipman 1 unzip

There are a few potential / actual problems with what you have been doing.您一直在做的事情存在一些潜在/实际问题。

  1. The pathname ("/home/server-cliet.jar") doesn't look right to me:路径名(“/home/server-cliet.jar”)对我来说看起来不正确:

    • "/home" is an odd place to put files. “/home” 是一个奇怪的放置文件的地方。 On a typical Linux system, "/home" contains a subdirectory for each user.在典型的 Linux 系统上,“/home”包含每个用户的子目录。 You don't put files there.你不把文件放在那里。

    • "server-cliet.jar" looks like a typo. “server-cliet.jar”看起来像一个错字。 That isn't how you spell client.这不是你拼写客户的方式。

  2. The Linux version of zip 1 doesn't understand :: as refering to JAR / ZIP within a ZIP. The Linux version of zip 1 doesn't understand :: as refering to JAR / ZIP within a ZIP. It thinks it is a normal pathname.它认为这是一个正常的路径名。 Which doesn't work.这是行不通的。 That's why you got the first "not found or empty" message.这就是您收到第一个“未找到或为空”消息的原因。

  3. The second command failed because Linux zip -d only knows how to delete an entry of a ZIP / JAR.第二个命令失败,因为 Linux zip -d只知道如何删除 ZIP / Z529E6245A4C8C2BF37AECF633 的条目It doesn't deal withe JAR-in-a-JAR scenario.它不处理 JAR-in-a-JAR 场景。 So the command is actually telling zip to delete an entry that doesn't exist.所以该命令实际上是告诉zip删除一个不存在的条目。

  4. It is also not clear that BOOT-INF/lib/log4j-1.2.17.jar is the correct pathname for the inner JAR.也不清楚BOOT-INF/lib/log4j-1.2.17.jar是内部 JAR 的正确路径名。 The minor version number might be different.次要版本号可能不同。


So... dealing with this is going to be messy.所以......处理这个会很混乱。 What you need to do is 2 :你需要做的是2

  • Unzip the outer JAR into a temporary directory将外层JAR解压到临时目录下
  • Find the log4j-1.2.xx JAR in the temp directory在temp目录下找到log4j-1.2.xx JAR
  • Use zip -d to delete the class from the log4j-1.2.xx JAR.使用zip -d从 log4j-1.2.xx JAR 中删除 class。 Or just replace that entire JAR with a fixed version of log4j-1.2 downloaded from a reliable source.或者只是用从可靠来源下载的 log4j-1.2 的固定版本替换整个 JAR。
  • Rezip the (updated) temporary directory重新压缩(更新的)临时目录
  • Use unzip -l on the resulting JAR file to confirm that the paths are correct.对生成的 JAR 文件使用unzip -l以确认路径是否正确。

Finally, note that this is only necessary if your server-cliet application is actually configured to use the JMS appender.最后,请注意,仅当您的server-cliet应用程序实际配置为使用 JMS 附加程序时,才需要这样做。 According to the CVE, this is not the default behavior, so if your app doesn't configure it, then this rigmarole may not be strictly necessary.根据 CVE,这不是默认行为,因此如果您的应用程序没有配置它,那么这种繁琐的操作可能不是绝对必要的。 Though it may be needed to get your corporate IT security team off your back.尽管可能需要让您的企业 IT 安全团队摆脱困境。


1 - In fact, I'm not sure of which version of zip does support that syntax. 1 - 事实上,我不确定zip的哪个版本支持该语法。 If someone knows, please comment.如果有人知道,请发表评论。
2 - I am not going to tell you the exact commands to run. 2 - 我不会告诉你要运行的确切命令。 You should be able to work it out from the manual entries and some trial and error.您应该能够通过手动输入和一些试验和错误来解决它。 If you can't, maybe hire a Linux professional to help you out with this.如果你不能,也许聘请 Linux 专业人员来帮助你解决这个问题。

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

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