安全漏洞

342 阅读2分钟

目标可能存在Apache Log4j2 远程代码执行漏洞(CVE-2021-44228)

漏洞描述

image.png

解决过程

直观方法

先确定漏洞所属服务器上有哪些应用程序,我的是服务器上部署了Springboot的一个jar包运行,本地核对该项目的源代码时,通过idea查看lib下jar包的版本(External Libraries):

image.png

我的项目里之前是用其他maven依赖时自动注入的2.15版本,可以修改pom.xml文件,在<properties></properties>标签中添加命令<log4j2.version>2.17.0</log4j2.version>来指定log4j2点版本号即可。

服务器上排查或验证

  1. 可以在程序包所在目录直接查看jar包或war包内的第三方库,使用命令:jar -tf jar包或者war包|grep 'log4j.*jar$',这句话是用来检查jar包或者war包下有没有log4j的jar包,运行命令后会输出jar包的信息。

  2. 如果项目是解压后的war项目目录或者lib单独打包放在项目外边的,可以使用命令find . -name log4j*.jar来查找相关的jar包信息

JAVA JMX agent不安全的配置漏洞

漏扫描述

image.png

解决过程

  • 用监控的方式启动Springboot项目的jar包,执行以下命令:
nohup java -Djava.rmi.server.hostname=服务器IP \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=1099 \
-Dcom.sun.management.jmxremote.authenticate=true \
-Dcom.sun.management.jmxremote.ssl=true \
-jar 运行的具体jar包 >catalina.out 2>&1 &

如果执行后应用程序的日志输出文件报错:Password file not found:.../jmxremote.password,例如我的报错内容如下:

[root@yuyin-2 rdboot]# tail -f catalina.out
nohup: ignoring input
Error: Password file not found: /usr/local/java/jdk/jre/lib/management/jmxremote.password
sun.management.AgentConfigurationError
        at sun.management.jmxremote.ConnectorBootstrap.checkPasswordFile(ConnectorBootstrap.java:563)
        at sun.management.jmxremote.ConnectorBootstrap.startRemoteConnectorServer(ConnectorBootstrap.java:426)
        at sun.management.Agent.startAgent(Agent.java:262)
        at sun.management.Agent.startAgent(Agent.java:452)

此时我们可以到日志输出中的jdk目录进行如下操作:

/usr/local/java/jdk/jre/lib/management/目录中执行命令:

mv jmxremote.password.template jmxremote.password
mod +w jmxremote.password
vi jmxremote.password

放开monitorRole QED 和 controlRole R&D这两行的注释,然后保存退出。执行命令:chmod 0400 jmxremote.password,然后再次执行上述运行jar包的命令即可。