your programing

UrlScan없이 Azure / IIS7에서 과도한 HTTP 응답 헤더 제거 / 숨기기 / 비활성화

lovepro 2020. 10. 7. 07:59
반응형

UrlScan없이 Azure / IIS7에서 과도한 HTTP 응답 헤더 제거 / 숨기기 / 비활성화


과도한 헤더 를 제거해야합니다 (주로 침투 테스트를 통과하기 위해). UrlScan 실행과 관련된 솔루션을 찾는 데 시간을 보냈지 만 Azure 인스턴스가 시작될 때마다 UrlScan을 설치해야 하므로 이는 번거 롭습니다 .

startup.cmd에서 설치 관리자를 배포하지 않는 좋은 Azure 솔루션이 있어야합니다.

응답 헤더가 다른 위치에 추가된다는 것을 이해합니다 .

  • 서버 : IIS에 의해 추가되었습니다.
  • X-AspNet-Version : HttpResponse 클래스에서 Flush시 System.Web.dll에 의해 추가됨
  • X-AspNetMvc-Version : System.Web.dll의 MvcHandler에 의해 추가되었습니다.
  • X-Powered-By : IIS에 의해 추가됨

IIS 모듈을 생성하거나 필요한 설치 프로그램을 배포하지 않고 asafaweb.com 에서 "과도한 헤더"경고를 피하기 위해 HTTP 응답 헤더를 제거 / 숨기기 / 비활성화하도록 IIS7을 구성하는 방법이 있습니까 (web.config 등을 통해?) Azure 인스턴스가 시작될 때마다 실행됩니까?


다음 변경 사항을 통해 사용자 지정 HttpModule 작성 하지 않고도 Azure에서 이러한 HTTP 응답 헤더를 제거 할 수 있습니다.

인터넷에있는 대부분의 정보는 오래되었으며 UrlScan (이후 IIS7에 통합되었지만 RemoveServerHeader=1옵션이 제거됨)과 관련됩니다. 아래는 내가 찾은 가장 좋은 솔루션입니다 ( 이 블로그 , 이 답변이 블로그를 결합한 덕분에 ).

Server 를 제거하려면 Global.asax로 이동하여 Application_PreSendRequestHeaders이벤트를 찾아서 만들고 다음을 추가합니다 ( BK이 블로그 덕분 에 Cassini / 로컬 개발자에서도 실패하지 않음).

2014 년 4 월 편집 : PreSendRequestHeaders 및 PreSendRequestContext 이벤트를 기본 IIS 모듈과 함께 사용할 수 있지만 IHttpModule을 구현하는 관리 모듈에는 사용하지 마십시오. 이러한 속성을 설정하면 비동기 요청에 문제가 발생할 수 있습니다 . 올바른 버전은 BeginRequest 이벤트를 사용하는 것입니다.

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        var application = sender as HttpApplication;
        if (application != null && application.Context != null)
        {
            application.Context.Response.Headers.Remove("Server");
        }
    }

X-AspNet-Version 을 제거하려면 web.config에서 다음을 찾아서 만들고 <system.web>추가합니다.

  <system.web>
    <httpRuntime enableVersionHeader="false" />

    ...

X-AspNetMvc-Version 을 제거하려면 Global.asax로 이동하여 Application_Start이벤트를 찾아서 만들고 다음과 같이 줄을 추가합니다.

  protected void Application_Start()
  {
      MvcHandler.DisableMvcResponseHeader = true;
  }

X-Powered-By 를 제거하려면 web.config에서 다음을 찾아서 <system.webServer>추가합니다.

  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
      </customHeaders>
    </httpProtocol>

    ...

MSDN 은 Azure 웹 사이트에서 헤더를 숨기는 방법에 대한 이 문서게시 했습니다 . 이제 system.webServer에 항목을 추가하여 web.config에서 서버를 숨길 수 있습니다.

<security>
      <requestFiltering removeServerHeader ="true" />
</security>

VS는 위의 경우 잘못된 것으로 눈살을 찌푸 릴 것입니다. 위의 링크에는 사진으로 코드가 있으며 찾기가 어렵습니다. MVC 버전은 x-powered-by 및 .Net 버전과 동일하게 위와 같이 응용 프로그램 시작에서 여전히 숨겨져 있습니다.


몇 줄의 구성과 코드 변경없이이를 달성하는 데 도움이되는 NuGet 패키지도 있습니다. NWebsec. 버전 헤더 제거에 대한 문서는 https://github.com/NWebsec/NWebsec/wiki/Suppressing-version-headers 에서 찾을 수 있습니다.

It's demoed here: http://www.nwebsec.com/HttpHeaders/VersionHeaders (in Azure)

Disclaimer: I'm the developer on the project.


Nick Evans' answer is perfect, but...

If you remove these headers for a security purpose, don't forget to change the ASP.NET Session coockie name ! Because it is easier to guess the language used or the server version when you see this :

enter image description here

To change the cookie name: (be creative)

<system.web>
  <sessionState cookieName="PHPSESSID" />
</system.web>

Rolling up the previous answers from @giveme5minutes and @AKhooli as they relate to Azure Websites plus a few other items the scanner wants to see, these are the changes that I made to make ASafaWeb happy with an Azure site.

It still complains about the Azure affinity header cookie not being https only but affinity is the type of cookie you do want replayed anyway, right?

<system.web>
    <compilation debug="false">
    <httpRuntime enableVersionHeader="false" />
    <httpCookies httpOnlyCookies="true" requireSSL="true" />    
    <customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx" />
</system.web>

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-Frame-Options" value="DENY" />
        <remove name="X-Powered-By" />
      </customHeaders>
    </httpProtocol>
    <security>
      <!--removes Azure headers-->
      <requestFiltering removeServerHeader="true" />
    </security>
</system.webServer>

참고URL : https://stackoverflow.com/questions/12803972/removing-hiding-disabling-excessive-http-response-headers-in-azure-iis7-without

반응형