首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >删除未使用的HTTP处理程序以提高性能和安全性

删除未使用的HTTP处理程序以提高性能和安全性
EN

Stack Overflow用户
提问于 2015-03-04 14:28:49
回答 3查看 11.9K关注 0票数 13

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

例如,建议删除TraceHandler-和TraceHandler-Integrated4.0,因为否则导航到/trace.axd会导致500个内部服务器错误,而不是在生产环境中找不到一个404,并且不应该有跟踪。

GitHub项目(现在删除了)建议手动删除一个庞大的列表:

代码语言:javascript
运行
复制
<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>
EN

回答 3

Stack Overflow用户

发布于 2015-03-15 11:20:26

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

代码语言:javascript
运行
复制
<system.webServer>
    <handlers>
        <clear />
         <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    </handlers>
</system.webServer>

现在,添加您需要返回的所有处理程序,只用于正在运行的bitness和模式。

对于基本的MVC项目,只需添加

代码语言:javascript
运行
复制
  <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个是modules="IsapiModule" scriptProcessor="...aspnet_isapi.dll" for ASP.NET,涵盖了所有的asp.net扩展,并且可能存在于CLR2.0和4.0以及32位和64位。大多数都是经典模式。

它们通常处理以下扩展:

代码语言:javascript
运行
复制
 *.       = 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位ApplicationPools中应用,或者在经典模式下应用。如果您只运行64 all集成模式,则可以删除所有经典模式和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

用于处理集成模式下的无扩展请求。这会将请求转发给路由引擎,以决定如何处理这些请求。更多信息

System.Web.Handlers.WebAdminHandler

处理WebAdmin.axd以显示ASP.NET Website Administration Toolkit,如果不使用内置特性,则可以删除它。

System.Web.HttpForbiddenHandler

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

System.Web.HttpMethodNotAllowedHandler

我认为这个已不再在现代IIS中使用,它返回一个405 HTTP状态,还抛出和HttpException

System.Web.HttpNotFoundHandler

而且,在我当前的配置中不再是这样。它引发404 HTTP异常。

System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions

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

System.Web.Services.Protocols.WebServiceHandlerFactory,System.Web.Services

还以集成模式处理*.asmx DOT.NET 2的web服务请求。

System.Web.StaticFileHandler

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

System.Web.UI.PageHandlerFactory

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

System.Web.UI.SimpleHandlerFactory

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

System.Xaml.Hosting.XamlHttpHandlerFactory,System.Xaml.Hosting

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

更多处理程序:

modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"

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

modules="ProtocolSupportModule"

这将处理对HTTP谓词TRACEOPTIONS的所有请求,如果删除此映射,所有跟踪和选项请求将返回“不允许的405方法”。

票数 24
EN

Stack Overflow用户

发布于 2015-03-12 16:00:09

对此的答复:

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

打开IIS,CMD->inetmgr,然后单击处理程序映射,见下面的屏幕快照。

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

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

例如,我已经删除了aspq-ISAPI-4.0_64bit,因此它更改了该虚拟目录的web.config,即它在web.config中添加了下面一行。

<remove name="aspq-ISAPI-4.0_64bit" />system.webServer\handlers下。

Update:当特定的文件类型请求出现时,将调用此处理程序,直到该处理程序处于空闲状态。因此,这些处理程序不会出现任何性能问题。

例如,您有removing handler for *.axd will improve security (我对此的回答),一些DLL可能需要那些文件来呈现js和css,如果您删除了这些文件,它将无法工作。例如- HTTP Handler无法在嵌套的web应用程序文件夹中找到axd文件: Telerik RadScriptManager无法在~/admin/文件夹中找到WebResource.axd

票数 0
EN

Stack Overflow用户

发布于 2022-07-18 20:57:42

我上周也在回答同样的问题,经过大量的研究,我认为我在GitHub中发现了类似的东西:

“不安全处理程序”列表:https://gist.github.com/marcbarry/47644b4a43fbfb63ef54

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28856991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档