【问题标题】:Removing Unused HTTP Handlers for Better Performance & Security删除未使用的 HTTP 处理程序以获得更好的性能和安全性
【发布时间】:2015-05-05 14:11:02
【问题描述】:

从哪里可以获得所有默认 IIS HTTP 处理程序的功能列表?我需要文件!!我读过一些博客,出于性能和安全原因,建议删除数十个未使用的 HTTP 处理程序。

例如建议删除 TraceHandler-Integrated 和 TraceHandler-Integrated-4.0,否则导航到 /trace.axd 会导致 500 Internal Server Error 而不是 404 Not Found,并且您不应该在生产环境中进行跟踪。

GitHub 项目(现已删除)建议手动删除大量列表的一些 HTTP 处理程序:

<system.webServer>
  <handlers>
    <remove name="TraceHandler-Integrated-4.0" />
    <remove name="TraceHandler-Integrated" />
    <remove name="AssemblyResourceLoader-Integrated-4.0" />
    <remove name="AssemblyResourceLoader-Integrated" />
    <remove name="WebAdminHandler-Integrated-4.0" />
    <remove name="WebAdminHandler-Integrated" />
    <remove name="HttpRemotingHandlerFactory-soap-ISAPI-2.0-64" />
    <remove name="svc-ISAPI-4.0_32bit" />
    <remove name="ScriptHandlerFactoryAppServices-Integrated-4.0" />
    <remove name="ScriptResourceIntegrated-4.0" />
    <remove name="svc-ISAPI-4.0_64bit" />
    <remove name="svc-Integrated-4.0" />
    <remove name="vbhtm-ISAPI-4.0_32bit" />
    <remove name="vbhtm-ISAPI-4.0_64bit" />
    <remove name="vbhtm-Integrated-4.0" />
    <remove name="vbhtml-ISAPI-4.0_32bit" />
    <remove name="vbhtml-ISAPI-4.0_64bit" />
    <remove name="vbhtml-Integrated-4.0" />
    <remove name="xamlx-ISAPI-4.0_32bit" />
    <remove name="xamlx-ISAPI-4.0_64bit" />
    <remove name="xamlx-Integrated-4.0" />
    <remove name="xoml-ISAPI-4.0_32bit" />
    <remove name="xoml-ISAPI-4.0_64bit" />
    <remove name="xoml-Integrated-4.0" />
    <remove name="HttpRemotingHandlerFactory-rem-Integrated-4.0" />
    <remove name="HttpRemotingHandlerFactory-rem-ISAPI-2.0" />
    <remove name="rules-ISAPI-4.0_32bit" />
    <remove name="rules-Integrated-4.0" />
    <remove name="HttpRemotingHandlerFactory-soap-Integrated" />
    <remove name="HttpRemotingHandlerFactory-soap-ISAPI-2.0" />
    <remove name="HttpRemotingHandlerFactory-soap-ISAPI-4.0_64bit" />
    <remove name="HttpRemotingHandlerFactory-soap-Integrated-4.0" />
    <remove name="HttpRemotingHandlerFactory-soap-ISAPI-4.0_32bit" />
    <remove name="rules-ISAPI-4.0_64bit" />
    <remove name="HttpRemotingHandlerFactory-rem-ISAPI-2.0-64" />
    <remove name="HttpRemotingHandlerFactory-rem-Integrated" />
    <remove name="HttpRemotingHandlerFactory-rem-ISAPI-4.0_32bit" />
    <remove name="HttpRemotingHandlerFactory-rem-ISAPI-4.0_64bit" />
    <remove name="AXD-ISAPI-2.0-64" />
    <remove name="cshtml-ISAPI-4.0_64bit" />
    <remove name="cshtml-Integrated-4.0" />
    <remove name="cshtm-Integrated-4.0" />
    <remove name="cshtml-ISAPI-4.0_32bit" />
    <remove name="cshtm-ISAPI-4.0_64bit" />
    <remove name="cshtm-ISAPI-4.0_32bit" />
    <remove name="AXD-ISAPI-4.0_64bit" />
    <remove name="AXD-ISAPI-2.0" />
    <remove name="AXD-ISAPI-4.0_32bit" />
    <remove name="PageHandlerFactory-ISAPI-2.0-64" />
    <remove name="PageHandlerFactory-ISAPI-2.0" />
    <remove name="PageHandlerFactory-ISAPI-4.0_64bit" />
    <remove name="PageHandlerFactory-ISAPI-4.0_32bit" />
    <remove name="aspq-ISAPI-4.0_64bit" />
    <remove name="aspq-Integrated-4.0" />
    <remove name="WebServiceHandlerFactory-ISAPI-2.0" />
    <remove name="aspq-ISAPI-4.0_32bit" />
    <remove name="WebServiceHandlerFactory-Integrated-4.0" />
    <remove name="WebServiceHandlerFactory-Integrated" />
    <remove name="SimpleHandlerFactory-ISAPI-4.0_64bit" />
    <remove name="SimpleHandlerFactory-Integrated-4.0" />
    <remove name="SimpleHandlerFactory-Integrated" />
    <remove name="SimpleHandlerFactory-ISAPI-2.0" />
    <remove name="SimpleHandlerFactory-ISAPI-2.0-64" />
    <remove name="WebServiceHandlerFactory-ISAPI-4.0_32bit" />
    <remove name="WebServiceHandlerFactory-ISAPI-4.0_64bit" />
    <remove name="WebServiceHandlerFactory-ISAPI-2.0-64" />
    <remove name="SimpleHandlerFactory-ISAPI-4.0_32bit" />
    <remove name="ISAPI-dll" />
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
    <remove name="OPTIONSVerbHandler" />
    <remove name="TRACEVerbHandler" />
  </handlers>
</system.webServer>

【问题讨论】:

  • 似乎没有关于所有处理程序的完整文档(目前)。我建议不要删除上面的所有处理程序,这可能会带来比修复更多的安全漏洞。您真的很想了解每个处理程序的作用以及您是否需要它。
  • https://github.com/pingfu/notes/blob/master/Security%20-%20IIS%20-%20Hardening%20the%20web.config.md 未找到
  • @Kiquenet 不幸的是,作者删除了这个项目。
  • 男孩,这个匿名的 Github 项目听起来确实是一个很好的权威,可以给我建议删除什么。
  • 建议删除的列表显示普遍缺乏对 acceptingrejecting 处理程序之间差异的理解,这已在答案中重复。在可能允许下载 .cshtml 文件的情况下,这会导致潜在的安全漏洞(请注意,ExtensionlessUrlHandler-Integrated-4.0 未被删除)。 Rejecting 处理程序不应在没有合适位置的情况下被删除,例如添加 requestFiltering。

标签: asp.net performance security iis httphandler


【解决方案1】:

如果你真的想要一组最小的处理程序映射,我建议你开始清理,在你的 web.config 中删除所有处理程序并只使用 StaticFile 一个:

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

现在添加你需要的所有处理程序,只是为了你正在运行的位数和模式。

对于基本的 MVC 项目,添加可能就足够了

  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0" />

所有处理程序的作用是什么?

我也找不到任何文档,所以这是我的尝试:

处理程序映射在%SystemRoot%\System32\inetsrv\config\applicationHost.config - system.webServer/handlers中定义

在我的例子中,有 87 个映射。

其中 50 个是 ASP.NET 的 modules="IsapiModule" scriptProcessor="...aspnet_isapi.dll"。这些涵盖了所有各种 asp.net 扩展,并且可能存在于 CLR 版本 2.0 和 4.0 以及 32 位和 64 位。其中大部分用于经典模式。

他们通常处理以下扩展:

 *.       = ExtensionlessUrlHandler-ISAPI
 *.ashx   = SimpleHandlerFactory-ISAPI
 *.asmx   = WebServiceHandlerFactory-ISAPI
 *.aspq   = aspq-ISAPI
 *.aspx   = PageHandlerFactory
 *.axd    = AXD-ISAPI
 *.cshtm  = cshtm-ISAPI
 *.cshtml = cshtml-ISAPI
 *.rem    = HttpRemotingHandlerFactory-rem-ISAPI
 *.rules  = rules-ISAPI
 *.soap   = HttpRemotingHandlerFactory-soap
 *.svc    = svc-ISAPI
 *.vbhtm  = vbhtm-ISAPI
 *.vbhtml = vbhtml-ISAPI
 *.xamlx  = xamlx-ISAPI
 *.xoml   = xoml-ISAPI

如果您的项目不使用某些扩展,您可以删除这些处理程序。

大多数处理程序映射都有一个preCondition,例如在 32 位应用程序池中或在经典模式下应用。如果您只运行 64Big 集成模式,则可以删除所有经典模式和 32 位处理程序映射。

如果我们查看 Razor 视图文件的 *.cshtml,您会发现三个映射,两个用于指向 ASP.NET ISAPI 模块的 32/64 位的 ClassicMode,但第三个仅适用于集成模式和映射到 HttpForbiddenHandler,因为 MVC 路由在集成模式下的工作方式不同,您永远不想允许直接访问查看文件。

可能存在用于经典 asp 或 CGI 的 IsapiModules,例如 ASP.NET 映射,用于处理对具有某些扩展名的文件的请求。

第二大组是type="System. 处理程序,让我们看看它们:

System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory

以集成模式处理 *.rem*.soap 文件。如果您不使用远程处理,可以将其删除。

System.ServiceModel.Activation.HttpHandler、System.ServiceModel.Activation

使用 *.rules,*.xoml,*.svc 扩展处理某些 WCF 请求。

System.Web.Handlers.AssemblyResourceLoader

处理WebResource.axd 请求,这些可能在WebForms 中使用,但通常不在MVC 项目中。

System.Web.Handlers.ScriptResourceHandler、System.Web.Extensions

用于处理ScriptResource.axd,它在 WebForms 中提供 JavaScript 和 CSS 资源。

System.Web.Handlers.TraceHandler

trace.axd 的处理程序以显示 ASP.NET 跟踪信息。在生产站点上,您希望删除此处理程序。

System.Web.Handlers.TransferRequestHandler

用于在集成模式下处理无扩展请求。这会将请求转发给路由引擎以决定如何处理这些请求。 More Info

System.Web.Handlers.WebAdminHandler

处理WebAdmin.axd 以显示ASP.NET Website Administration Toolkit,如果您不使用该内置功能,可以将其删除。

System.Web.HttpForbiddenHandler

允许我们阻止访问具有特定扩展名的任何文件。然而,它返回一个 500 HTTP 状态并且实际上在服务器上抛出一个 System.Web.HttpException 异常。 在我看来,有更好的方法来博客某些扩展,例如 IIS Request Filtering

System.Web.HttpMethodNotAllowedHandler

我认为现代 IIS 中不再使用这个,它返回 405 HTTP 状态并且还会抛出 HttpException

System.Web.HttpNotFoundHandler

另外,在我当前的配置中不再存在。它会引发 404 HTTP 异常。

System.Web.Script.Services.ScriptHandlerFactory、System.Web.Extensions

处理 *.asmx*_AppService.axd 以支持通过 Ajax 调用 Web 服务。

System.Web.Services.Protocols.WebServiceHandlerFactory、System.Web.Services

还在 DOT.NET 2 的集成模式下处理 *.asmx Web 服务请求

System.Web.StaticFileHandler

返回一个静态文件,不再使用?

System.Web.UI.PageHandlerFactory

以集成模式处理 ASP.NET WebForm 页面.aspx

System.Web.UI.SimpleHandlerFactory

在集成模式下处理 ASP.NET 自定义处理程序 .ashx

System.Xaml.Hosting.XamlHttpHandlerFactory、System.Xaml.Hosting

以集成模式处理 Windows Workflow Foundation 服务 .xamlx


更多处理程序:

modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"

这通常是处理任何先前处理程序path="*" verb="*" 未处理的任何请求的最后一个映射。它实际上使用了三个不同的模块。 StaticFileMode 查找与请求的 URL 匹配的物理文件,如果找不到,DefaultDocumentModule 会在与请求的 URL 相同的文件夹中查找默认文档,如果也找不到,DirectoryListingModule 可能会显示目录的内容,如果已启用。

modules="ProtocolSupportModule"

这将处理对 HTTP 动词 TRACEOPTIONS 的所有请求,如果您删除此映射,所有跟踪和选项请求都将返回“405 Method not allowed”

【讨论】:

  • 我不敢相信微软没有关于这个主题的文档。它们通常非常适合文档。可悲的是,这似乎是我们目前能得到的最佳答案。
  • “对于一个基本的 MVC 项目,添加可能就足够了..” 是的,现在您已经授予对“.cshtml”文件的访问权限,而无需进一步工作来限制访问.. .cshtml 处理程序用于阻止访问,而不是提供它。
【解决方案2】:

回答这个问题:

在哪里可以获得所有默认 IIS HTTP 处理程序的列表?

打开 IIS,CMD-->inetmgr,然后点击处理程序映射,见下面的截图。

单击它,它将显示该 Web 服务器的所有默认启用的 HTTP 处理程序。

注意:当您选择一个虚拟目录然后执行此过程时,即单击处理程序映射,并删除其中一个映射,它将在 web.config 中添加该行。

例如我已经删除了aspq-ISAPI-4.0_64bit,所以它已经为那个虚拟目录改变了web.config,也就是说,它在web.config中添加了以下行。

&lt;remove name="aspq-ISAPI-4.0_64bit" /&gt;system.webServer\handlers 下。

更新:当特定文件类型请求到来时调用此处理程序,直到那时它处于空闲状态。所以这些处理程序不会有任何性能问题。

例如,您有removing handler for *.axd will improve security,我对此的回答是,某些 DLL 可能需要这些文件来渲染 js 和 css,如果您删除它,它将无法正常工作。例如。 - HTTP Handler cannot find axd file in nested web application folder: Telerik RadScriptManager cannot find WebResource.axd in ~/admin/ folder

【讨论】:

  • 这告诉我在哪里可以获得它们的列表,但不是每个 HTTP 处理程序的用途。
  • 我想你只是问了那个问题,我已经尽力回答了,但我可以回答你问的问题 - 每个处理程序处理该特定文件类型的请求的目的。
猜你喜欢
  • 1970-01-01
  • 2015-09-30
  • 2011-12-24
  • 2011-01-20
  • 2011-11-29
  • 2021-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多