项目场景:

在项目上线进行渗透测试过程中,客户反馈,项目异常界面泄露中间件版本号,需要隐藏,以及tomcat错误异常的信息。


问题描述

渗透测试:http://ip:port/om/include/makecvs.php?Event=http|echo%20"<?php%20echo%20md5(pkgizscxsn);unlink(__FILE__);?>"%20>>%20/usr/www/pkgizscxsn.php%20&&%20chmod%20755%20/usr/www/pkgizscxsn.php||进行此地址时候,tomcat会校验参数合法性,检查到非法字符,会报错。需要去掉中间件版本号和异常报错信息。
在这里插入图片描述


尝试分析:

1.使用springboot内置tomcat配置错误界面 server.error.path=/error2.html 去指定错误页面。还是年轻,这个不好使。

2.使用springboot默认错误页面,这个也不生效

在这里插入图片描述

3.企图用全局异常捕捉它,但是捕捉不到,异常是tomcat容器抛出的,不是java程序。
在这里插入图片描述

在这里插入图片描述

4.继承ErrorReportValve类,重写了report方法,将showReport,showServerInfo判断取反,就是为了不显示异常信息。结果还是不生效。
因此观察ErrorReportValve 这个类,发现showReport和showServerInfo均是不支持配置。
在这里插入图片描述
然后查阅官方资料,意思我李姐就是不支持配置。
在这里插入图片描述后来有一位群友点拨了我一下,然后我就改了一下,是可以的,tomcat源码也是java写的,主要就是修改简单的配置也没什么难度,就可以解决。
在这里插入图片描述


解决方案:

步骤1:下载tomcat-embed-core-8.5.51-sources.jar源码解压缩
本地仓库地址:xxxx\org\apache\tomcat\embed\tomcat-embed-core\8.5.51
解压完会有三个文件夹
在这里插入图片描述

步骤2:创建一个maven项目,将javax和org复制到java文件夹下,META-INF复制到resource文件夹下。配置pom.xml文件如下:具体版本号视情况而定。将ErrorReportValve 这个类下的showReport和showServerInfo改为false
**注意:**jdk版本问题,使用对应的jdk1.7版本进行编译打包。

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-core</artifactId>
    <version>8.5.51-my</version>
    <description>Core Tomcat implementation</description>
    <url>http://tomcat.apache.org/</url>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    <dependencies>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-annotations-api</artifactId>
            <version>8.5.51</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>javax.mail-api</artifactId>
            <version>1.5.6</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.ejb</artifactId>
            <version>3.1.1</version>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <version>8.5.51</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.catalina</groupId>
            <artifactId>com.springsource.org.apache.catalina</artifactId>
            <version>7.0.26</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.xsd</include>
                    <include>**/*.dtd</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

4.打包完注意包名一致,然后解压你的项目替换jar包,或者替换你仓库里jar包就可以了。
/BOOT-INF/lib 项目里这个路径,替换即可,然后使用jar -cfM0 重新打包即可。

附上成功截图:
在这里插入图片描述
结尾:只是去掉中间件版本号网上一搜就有。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐