シリーズ八十から八のJBoss:JBossのセキュリティ問題 - ページはJBossのWebアプリケーションのエラーメッセージに表示されたときに非表示にする方法を...

アウトライン

あなたは次のようにエラーが発生したときにエラーページ、エラーページを扱う考慮していない場合は、Webアプリケーションのエラーやその他の異常は通常のJBossに配備403404500、Webアプリケーションをスローされます。




それはエラーページの2つの情報を含むので:

  • ヘッダはJBossWebのバージョン情報を表示します
  • JBossWebに関する表示バージョン情報ページ
実際の生産では、ハッカーが、サーバは、JBossである知っているような、安全性の問題が発生しますので、サービスを攻撃するために、セキュリティの脆弱性をJBossの関連を検索します。この記事では、可能なセキュリティ攻撃を避けるために、この情報を保護する方法を示します。

どのように非表示にするには

私たちの三つのステップ:

まず:書き換えorg.apache.catalina.valves.ErrorReportValve JBossWebは、一例として、次のとおりです。

package org.jboss.web.values;

import java.io.IOException;
import java.io.Writer;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.valves.ErrorReportValve;
import org.apache.catalina.util.RequestUtil;

public class CustomErrorReportValve extends ErrorReportValve {

    protected void report(Request request, Response response, Throwable throwable) {
        int statusCode = response.getStatus();
        if ((statusCode < 400) || (response.getContentCount() > 0)) {
            return;
        }
        String message = RequestUtil.filter(response.getMessage());
        if (message == null) {
            message = "";
        }
        StringBuffer sb = new StringBuffer();
        sb.append("<html><head><title>");
        sb.append(sm.getString("errorReportValve.statusHeader", "" + statusCode, message));
        sb.append("</title>");
        sb.append("<style><!--");
        sb.append(org.apache.catalina.util.TomcatCSS.TOMCAT_CSS);
        sb.append("--></style> ");
        sb.append("</head><body>");
        sb.append("<h1>");
        sb.append(sm.getString("errorReportValve.statusHeader", "" + statusCode, message));
        sb.append("</h1>");
        sb.append("</body></html>");
        try {
            try {
                response.setContentType("text/html");
                response.setCharacterEncoding("utf-8");
            } catch (Throwable t) {
                if (container.getLogger().isDebugEnabled())
                    container.getLogger().debug("status.setContentType", t);
            }
            Writer writer = response.getReporter();
            if (writer != null) {
                // If writer is null, it's an indication that the response has
                // been hard committed already, which should never happen
                writer.write(sb.toString());
            }
        } catch (IOException e) {
            ;
        } catch (IllegalStateException e) {
            ;
        }
    }
}

第二: 書き換えErrorReportValveは、コンパイラは、私たちがCustomErrorReportValve.jar用のJARパッケージをコンパイルなど、ここのように、パッケージのjarパッケージを生成します。

第三: JBossの設定

次のように設定されたJBoss 7/8 WildFly

1.CustomErrorReportValve.jar 放置到您应用WEB-INF/lib目录

2.创建WEB-INF/jboss-web.xml,添加次のように<バルブ>の構成は以下のとおりです。

<jboss-web>
    <valve>
       <class-name>com.redhat.jboss.support.CustomErrorReportValve</class-name>
    </valve>
</jboss-web>

次のようにJBossバージョン7の前に設定されています。

1。意志CustomErrorReportValve.jar 放置到 $JBOSS_HOME/server/$PROFILE/lib

2. 编辑$JBOSS_HOME/server/$PROFILE/deploy/jboss-web.deployer/server.xml中Host元素,添加errorReportValveClass属性指向重写的ErrorReportValve如下:

<Host name="localhost" errorReportValveClass="org.jboss.web.values.CustomErrorReportValve" >

隐藏后效果

隐藏后效果如下图所示:







ます。https://my.oschina.net/iwuyang/blog/197248で再現

おすすめ

転載: blog.csdn.net/weixin_34308389/article/details/91897378