防止黑客利用Tomcat中间件及版本号有针对性发起攻击。
# 进入tomcat/lib目录 cd Tomcat目录/lib # 解决catalina.jar,备份ServerInfo.properties unzip catalina.jar cp org/apache/catalina/util/ServerInfo.properties ServerInfo.properties.bak # 替换中间件名称、版本号为Unknown sed -i "s/server.info=.*/server.info=Unknown/g" org/apache/catalina/util/ServerInfo.properties sed -i "s/server.number=.*/server.number=Unknown/g" org/apache/catalina/util/ServerInfo.properties # 查看替换是否成功,输出server.info与server.number均为Unknown即正常 grep server org/apache/catalina/util/ServerInfo.properties # 修改的配置文件替换jar内文件 jar uvf catalina.jar org/apache/catalina/util/ServerInfo.properties # 删除解压的临时文件 rm org META-INF -rf
#!/bin/bash [ ! -d "lib" ] && echo "lib目录不存在,请检查脚本是否正确放到tomcat目录下" && exit; cd ./lib [ -d "org" ] && rm -rf org; [ -d "META-INF" ] && rm -rf META-INF; unzip -q catalina.jar [ $? != 0 ] && echo "unzip命令不存在,请安装后重试" && exit; sed -i "s/server.info=.*/server.info=Unknown/g" org/apache/catalina/util/ServerInfo.properties sed -i "s/server.number=.*/server.number=Unknown/g" org/apache/catalina/util/ServerInfo.properties jar uvf catalina.jar org/apache/catalina/util/ServerInfo.properties [ $? != 0 ] && echo "jar命令不存在,可能在PATH中找不到,请正确配置后重试" && exit; rm org META-INF -rf echo "操作完成。"
将脚本命名为 tomcat-no-version.sh
,放入tomcat目录下执行 sh tomcat-no-version.sh