谓词 <verbs>

概述

<verbs> 元素指定允许或拒绝哪些 HTTP 谓词,从而限制 Web 服务器允许的 HTTP 请求的类型。

注意

当请求筛选因 HTTP 谓词遭拒而阻止 HTTP 请求时,IIS 7 将向客户端返回 HTTP 404 错误,并记录以下 HTTP 唯一子状态,以确定拒绝请求的原因:

HTTP 子状态 说明
404.6 谓词被拒绝

此子状态允许 Web 管理员分析其 IIS 日志并识别潜在威胁。

兼容性

版本 说明
IIS 10.0 <verbs> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <verbs> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <verbs> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <verbs> 元素在 IIS 7.5 中未进行修改。
IIS 7.0 IIS 7.0 中引入了 <requestFiltering> 集合的 <verbs> 元素。
IIS 6.0 <verbs> 元素替代了 IIS 6.0 UrlScan [AllowVerbs][DenyVerbs] 功能。

安装

IIS 7 及更高版本的默认安装包括请求筛选角色服务或功能。 如果卸载请求筛选角色服务或功能,可以使用以下步骤重新安装它。

Windows Server 2012 或 Windows Server 2012 R2

  1. 在任务栏上,单击 “服务器管理器”。
  2. 在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。
  3. 在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。
  4. 在“服务器角色”页上,依次展开“Web 服务器 (IIS)”、“Web 服务器”和“安全性”,然后选择“请求筛选”。 单击 “下一步”
    Screenshot shows Web Server and Security pane expanded with Request filtering highlighted.
  5. 在“选择功能”页上,单击“下一步”
  6. “确认安装选择”页上,单击“安装”
  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

  1. 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”
  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
  3. 依次展开“Internet Information Services”、“万维网服务”和“安全性”,然后选择“请求筛选”。
    Screenshot of World Wide web Services and Security pane expanded with Request Filtering highlighted.
  4. 单击“确定”。
  5. 单击“关闭” 。

Windows Server 2008 或 Windows Server 2008 R2

  1. 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。
  2. 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器 (IIS)”。
  3. 在“Web 服务器 (IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。
  4. 在“添加角色服务向导”的“选择角色服务”页上,选择“请求筛选”,然后单击“下一步”。
    Screenshot displays Security pane expanded in Select Role services page and Request Filtering selected.
  5. “确认安装选择”页中,单击“安装”
  6. 在“结果” 页面中单击“关闭”

Windows Vista 或 Windows 7

  1. 在任务栏上,单击“开始”,然后单击“控制面板”。
  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
  3. 扩展“Internet Information Services”,展开“万维网服务”,然后展开“安全性”。
  4. 选择“请求筛选”,然后单击“确定”。
    Screenshot of Internet Information Services and World Wide Web Service node expanded. Request Filtering is selected.

操作方式

IIS 7.0 用户请注意:本节中的某些步骤可能需要安装 Microsoft Administration Pack for IIS 7.0,其中包括请求筛选用户界面。 若要安装 Microsoft Administration Pack for IIS 7.0,请参阅以下 URL:

如何拒绝 HTTP 谓词

  1. 打开 Internet Information Services (IIS) 管理器:

    • 如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:

      • 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows 8 或 Windows 8.1:

      • 按住 Windows 键,按字母 X,然后单击“控制面板”。
      • 单击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
    • 如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:

      • 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows Vista 或 Windows 7:

      • 在任务栏上,单击“开始”,然后单击“控制面板”。
      • 双击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
  2. 在“连接”窗格中,转到要为其修改请求筛选设置的连接、站点、应用程序或目录。

  3. 在“主页”窗格中,双击“请求过滤”。
    Screenshot of Default Web Site Home pane showing Request Filtering selected.

  4. 在“请求筛选”窗格中,单击“HTTP 谓词”选项卡,然后在“操作”窗格中单击“拒绝谓词...”。
    Screenshot shows Request Filtering pane with H T T P verbs tab and Deny Verb option in Actions pane.

  5. 在“拒绝谓词”对话框中,输入要阻止的 HTTP 谓词,然后单击“确定”。
    Screenshot of Deny Verb dialog box showing H T T P verb box.

    例如,要防止向服务器发出 HTTP TRACE 请求,请在对话框中输入“TRACE”。

配置

特性

属性 说明
allowUnlisted 可选布尔属性。

指定 Web 服务器是否应处理未列出的谓词。 如果将此属性设置为 true,则必须列出要拒绝的所有谓词。 如果将此属性设置为 false,则必须列出要允许的所有谓词。

默认值为 true
applyToWebDAV 可选布尔属性。

指定是否还应将这些设置应用于 WebDAV 请求。

子元素

元素 说明
add 可选元素。

将谓词添加到谓词集合。
clear 可选元素。

从谓词集合中移除对多个谓词的所有引用。
remove 可选元素。

从谓词集合中移除对一个谓词的引用。

配置示例

以下示例 Web.config 文件将配置两个选项:它将配置 IIS 以拒绝 HTTP PUT 请求,并将配置请求筛选以允许 WebDAV 访问所有 HTTP 谓词。

<configuration>
   <system.webServer>
      <security>
         <requestFiltering>
            <verbs applyToWebDAV="false">
               <add verb="PUT" allowed="false" />
            </verbs>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>

代码示例

以下代码示例将配置两个选项:将 IIS 配置为拒绝对“默认网站”的 HTTP PUT 请求访问,并将配置请求筛选以允许 WebDAV 访问所有 HTTP 谓词。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /verbs.applyToWebDAV:"False"

appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /+"verbs.[verb='PUT',allowed='False']"

PowerShell

Start-IISCommitDelay

$verbs = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering' | Get-IISConfigCollection -CollectionName 'verbs'

Set-IISConfigAttributeValue -ConfigElement $verbs -AttributeName 'applyToWebDAV' -AttributeValue $false

New-IISConfigCollectionElement -ConfigCollection $verbs -ConfigAttribute @{ 'verb'='PUT';'allowed'=$false }

Stop-IISCommitDelay

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");
         ConfigurationSection requestFilteringSection = config.GetSection("system.webServer/security/requestFiltering");

         ConfigurationElement verbsElement = requestFilteringSection.GetChildElement("verbs");
         verbsElement["applyToWebDAV"] = false;
         ConfigurationElementCollection verbsCollection = verbsElement.GetCollection();

         ConfigurationElement addElement = verbsCollection.CreateElement("add");
         addElement["verb"] = @"PUT";
         addElement["allowed"] = false;
         verbsCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Default Web Site")
      Dim requestFilteringSection As ConfigurationSection = config.GetSection("system.webServer/security/requestFiltering")

      Dim verbsElement As ConfigurationElement = requestFilteringSection.GetChildElement("verbs")
      verbsElement("applyToWebDAV") = False
      Dim verbsCollection As ConfigurationElementCollection = verbsElement.GetCollection

      Dim addElement As ConfigurationElement = verbsCollection.CreateElement("add")
      addElement("verb") = "PUT"
      addElement("allowed") = False
      verbsCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";
var requestFilteringSection = adminManager.GetAdminSection("system.webServer/security/requestFiltering", "MACHINE/WEBROOT/APPHOST/Default Web Site");

var verbsElement = requestFilteringSection.ChildElements.Item("verbs");
verbsElement.Properties.Item("applyToWebDAV").Value = false;
var verbsCollection = verbsElement.Collection;

var addElement = verbsCollection.CreateNewElement("add");
addElement.Properties.Item("verb").Value = "PUT";
addElement.Properties.Item("allowed").Value = false;
verbsCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"
Set requestFilteringSection = adminManager.GetAdminSection("system.webServer/security/requestFiltering", "MACHINE/WEBROOT/APPHOST/Default Web Site")

Set verbsElement = requestFilteringSection.ChildElements.Item("verbs")
verbsElement.Properties.Item("applyToWebDAV").Value = False
Set verbsCollection = verbsElement.Collection

Set addElement = verbsCollection.CreateNewElement("add")
addElement.Properties.Item("verb").Value = "PUT"
addElement.Properties.Item("allowed").Value = False
verbsCollection.AddElement(addElement)

adminManager.CommitChanges()