改變您的HTTP伺服器的預設banner

來源:互聯網
上載者:User

標籤:protoc   logs   mvc   src   .config   項目   power   www   庫項目   

(以下方法僅針對 IIS Asp.net)

 

伺服器掃描發現漏洞,其中一個是:

 

可通過HTTP擷取遠端WWW服務資訊 [Microsoft-IIS/8.5]

漏洞描述 本外掛程式檢測遠端HTTP Server資訊。這可能使得攻擊者瞭解遠程系統類別型以便進行下一步的攻擊。
解決方案 NSFOCUS建議您採取以下措施以降低威脅

 

開啟網頁,審查代碼,我們發現這幾個標題明顯標明我們的伺服器和平台資訊,存在安全風險,必須要隱藏

 

解決方案:

建立一個類庫項目 CustomHttpModules,添加一個自訂 HttpModule

namespace CustomHttpModules{    public class HeaderFilterHttpModule : IHttpModule    {        public void Init(HttpApplication context)        {            context.PreSendRequestHeaders += OnPreSendRequestHeaders;        }        public void Dispose()        { }        void OnPreSendRequestHeaders(object sender, System.EventArgs e)        {            HttpContext.Current.Response.Headers.Remove("Server");            HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");            HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");            HttpContext.Current.Response.Headers.Remove("X-Frame-Options");        }     }}

編譯後,拷貝DLL到網站BIN目錄,修改網站的 Web.config

<system.webServer>    <modules>      <add name="HeaderFilterModule" type="CustomHttpModules.HeaderFilterHttpModule,CustomHttpModules"/>    </modules>    <httpProtocol>      <customHeaders>        <remove name="X-Powered-By"/>      </customHeaders>    </httpProtocol>  </system.webServer>

再次運行網站,審查代碼,幾個標題全沒了,搞定!

 

這種方法是最安全方便的,只要拷貝一個DLL和修改一處配置,不需要設定IIS(比如虛擬機器主機),也不需要修改和編譯網站代碼。

 

改變您的HTTP伺服器的預設banner

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.