代码之家  ›  专栏  ›  技术社区  ›  Adriano_Pinaffo

IIS:如何禁用HTTP方法跟踪?

  •  0
  • Adriano_Pinaffo  · 技术社区  · 7 年前

    我跟随 this 这导致了 this 尝试禁止我的网站接受跟踪方法(动词)。基本上我把下面的部分添加到 <system.webServer> 在web.config(默认网站和其他网站)中:

    <security>
       <requestFiltering>
           <verbs applyToWebDAV="false">
              <add verb="TRACE" allowed="false" />
           </verbs>
       </requestFiltering>
    </security>
    

    它没用。然后我转到c:\windows\system32\inetsrv\config\applicationhost.config并替换了里面所有处理程序的动词 <handlers> . 简而言之,所有的行都是这样的:

    <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    

    变成这样:

    <add name="StaticFile" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    

    我甚至重新启动了服务器,但是当我检查可用的方法时,跟踪仍然存在:

    $ curl -I -X OPTIONS https://example.com/mysite
    HTTP/1.1 200 OK
    Allow: OPTIONS, TRACE, GET, HEAD, POST
    Public: OPTIONS, TRACE, GET, HEAD, POST
    X-XSS-Protection: 1; mode=block
    Date: Thu, 07 Feb 2019 21:03:49 GMT
    Content-Length: 0
    

    那么,我该怎么处理呢?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Lex Li    7 年前

    真正阻止 TRACE 请求,您仍应使用 痕迹 动词被阻止。

    curl命令向IIS发送选项请求,并且 ProtocolSupportModule 生成响应消息,

    https://docs.microsoft.com/en-us/iis/get-started/introduction-to-iis/iis-modules-overview

    但是,Microsoft没有在 system.webServer/httpProtocol 用于更改标题值以隐藏的节 痕迹 从那里。

    但解决方法是使用URL重写模块,

    https://blogs.msdn.microsoft.com/benjaminperkins/2012/11/02/change-or-modify-a-response-header-value-using-url-rewrite/

    在其中为创建两个出站规则 Allow 和 Public 报头,

    <rewrite>
        <outboundRules>
            <rule name="ChangeHeaders" stopProcessing="false">
                <match serverVariable="RESPONSE_Allow" pattern="OPTIONS, TRACE, GET, HEAD, POST" />
                <action type="Rewrite" value="OPTIONS, GET, HEAD, POST" />
            </rule>
            <rule name="Public">
                <match serverVariable="RESPONSE_Public" pattern="OPTIONS, TRACE, GET, HEAD, POST" />
                <action type="Rewrite" value="OPTIONS, GET, HEAD, POST" />
            </rule>
        </outboundRules>
    </rewrite>