FTP 拒绝 URL 序列 <denyUrlSequences>

概述

<denyUrlSequences> 元素包含一组 <add> 元素,这些元素指定 IIS 将拒绝的 URL 字符序列,这有助于防止 Web 服务器上的基于 URL 的攻击。

注意

当请求筛选因 URL 序列遭拒而阻止 FTP 请求时,FTP 7 将向客户端返回 FTP 错误,并记录以下 FTP 子状态,以确定拒绝请求的原因:

FTP 子状态 说明
9 在请求的路径中检测到拒绝的 URL 序列。

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

兼容性

版本 说明
IIS 10.0 <denyUrlSequences> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <denyUrlSequences> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <denyUrlSequences> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <requestFiltering> 元素的 <denyUrlSequences> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <requestFiltering> 元素的 <denyUrlSequences> 元素是在 IIS 7.0 的独立下载项 FTP 7.0 中引入的。
IIS 6.0 IIS 6.0 中的 FTP 服务不支持请求筛选。

注意

FTP 7.0 和 FTP 7.5 服务是 IIS 7.0 带外提供的,需要从以下 URL 下载和安装模块:

https://www.iis.net/expand/FTP

在 Windows 7 和 Windows Server 2008 R2 中,FTP 7.5 服务作为 IIS 7.5 的功能提供,因此无需再下载 FTP 服务。

安装

若要支持 Web 服务器的 FTP 发布,必须安装 FTP 服务。 为此,请按照以下步骤操作。

Windows Server 2012 或 Windows Server 2012 R2

  1. 在任务栏上,单击 “服务器管理器”。

  2. 在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。

  3. 在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。

  4. 在“服务器角色”页上,展开“Web 服务器(IIS)”,然后选择“FTP 服务器”

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,除“FTP 服务”外还需选择“FTP 扩展性”
    Screenshot of the Server Roles page. Web Server I I S is expanded. F T P Server is expanded. F T P Extensibility is highlighted and selected.

  5. 单击“下一步”,然后在“选择功能”页上,再次单击“下一步”

  6. “确认安装选择”页上,单击“安装”

  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

  1. 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”

  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。

  3. 展开“Internet Information Services”,然后选择“FTP 服务器”

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”
    Screenshot of the Programs and Features navigation tree. F T P Extensibility is highlighted and selected.

  4. 单击“确定”。

  5. 单击“关闭” 。

Windows Server 2008 R2

  1. 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。

  2. 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器(IIS)”。

  3. 在“Web 服务器 (IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。

  4. 在“添加角色服务向导”的“选择角色服务”页,展开“FTP 服务器”。

  5. 选择“FTP 服务”。

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”
    Screenshot of the Select Role Services page. F T P Server is expanded and F T P Service is highlighted and selected.

  6. 单击 “下一步”

  7. “确认安装选择”页中,单击“安装”

  8. 在“结果” 页面中单击“关闭”

Windows 7

  1. 在任务栏上,单击“开始”,然后单击“控制面板”。

  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。

  3. 展开“Internet Information Services”,然后展开“FTP 服务器”

  4. 选择“FTP 服务”。

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”
    Screenshot of the Programs and Features navigation tree. The Internet Information Services node is expanded and the F T P Server node is also expanded. F T P Service is selected.

  5. 单击“确定”。

Windows Server 2008 或 Windows Vista

  1. 从以下 URL 下载安装包:

  2. 按照以下演练中的说明安装 FTP 服务:

操作方式

注意

FTP 请求筛选在 FTP 7.0 版本中没有用户界面;在 FTP 7.5 版本中增加了 FTP 请求筛选 UI。

如何拒绝 FTP URL 序列

  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. 在“主页”窗格中,双击“FTP 请求过滤”。
    Screenshot of the contoso dot com home pane. The F T P Request icon is highlighted.

  4. 在“FTP 请求筛选”窗格中,单击“拒绝的 URL 序列”选项卡。
    Screenshot of the F T P Request Filtering pane. The Denied U R L Sequences tab is selected.

  5. 在“操作”窗格中,单击“添加 URL 序列...”

  6. 在“添加拒绝序列”对话框中,输入要阻止的 URL 序列
    Screenshot of the Add Deny Sequence dialog box. The U R L sequence box is shown.

  7. 单击“确定”。

配置

<requestFiltering> 元素的 <denyUrlSequences> 元素在全局、站点或 URL 级别配置。

特性

无。

子元素

元素 说明
add 可选元素。

将序列添加到遭拒 URL 序列的集合中。
clear 可选元素。

<denyUrlSequences> 集合中移除对序列的所有引用。
remove 可选元素。

<denyUrlSequences> 集合中删除对序列的引用。

配置示例

以下示例演示 FTP 站点的 <system.ftpServer> 元素中的多个安全相关配置设置。 更具体而言,此示例中的 <location> 设置演示如何:

  • 为管理员组指定读取和写入访问权限的 FTP 授权规则。
  • 指定拒绝 *.exe、*.bat 和 *.cmd 文件的 FTP 请求筛选选项。
  • 指定最大内容长度为 1000000 字节且最大 URL 长度为 1024 字节的 FTP 请求限制。
  • 阻止 FTP 访问 _vti_bin 虚拟目录,此目录与 FrontPage 服务器扩展一起使用。
  • 指定 FTP IP 筛选选项,这些选项允许从 127.0.0.1 进行访问,但拒绝从 169.254.0.0/255.255.0.0 范围的 IP 地址进行访问。
<location path="ftp.example.com">
  <system.ftpServer>
    <security>
      <authorization>
        <add accessType="Allow" roles="administrators" permissions="Read, Write" />
      </authorization>
      <requestFiltering>
        <fileExtensions allowUnlisted="true">
          <add fileExtension=".exe" allowed="false" />
          <add fileExtension=".bat" allowed="false" />
          <add fileExtension=".cmd" allowed="false" />
        </fileExtensions>
        <requestLimits maxAllowedContentLength="1000000" maxUrl="1024" />
        <hiddenSegments>
          <add segment="_vti_bin" />
        </hiddenSegments>
      </requestFiltering>
      <ipSecurity enableReverseDns="false" allowUnlisted="true">
        <add ipAddress="127.0.0.1" allowed="true" />
        <add ipAddress="169.254.0.0" subnetMask="255.255.0.0" allowed="false" />
      </ipSecurity>
    </security>
  </system.ftpServer>
</location>

代码示例

以下示例将拒绝 FTP 的 URL 序列“bin”,这将阻止访问“bin”、“_vti_bin”或“cgi-bin”路径,并阻止上传文件扩展名为“.bin”的文件。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.ftpServer/security/requestFiltering /+"denyUrlSequences.[sequence='bin']" /commit:apphost

注意

使用 AppCmd.exe 配置这些设置时,必须确保将 commit 参数设置为 apphost。 这会将配置设置提交到 ApplicationHost.config 文件中的相应位置部分。

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.GetApplicationHostConfiguration();
         ConfigurationSection requestFilteringSection = config.GetSection("system.ftpServer/security/requestFiltering", "Default Web Site");
         ConfigurationElementCollection denyUrlSequencesCollection = requestFilteringSection.GetCollection("denyUrlSequences");

         ConfigurationElement addElement = denyUrlSequencesCollection.CreateElement("add");
         addElement["sequence"] = @"bin";
         denyUrlSequencesCollection.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.GetApplicationHostConfiguration
      Dim requestFilteringSection As ConfigurationSection = config.GetSection("system.ftpServer/security/requestFiltering", "Default Web Site")
      Dim denyUrlSequencesCollection As ConfigurationElementCollection = requestFilteringSection.GetCollection("denyUrlSequences")

      Dim addElement As ConfigurationElement = denyUrlSequencesCollection.CreateElement("add")
      addElement("sequence") = "bin"
      denyUrlSequencesCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

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

var addElement = denyUrlSequencesCollection.CreateNewElement("add");
addElement.Properties.Item("sequence").Value = "bin";
denyUrlSequencesCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set requestFilteringSection = adminManager.GetAdminSection("system.ftpServer/security/requestFiltering", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set denyUrlSequencesCollection = requestFilteringSection.ChildElements.Item("denyUrlSequences").Collection

Set addElement = denyUrlSequencesCollection.CreateNewElement("add")
addElement.Properties.Item("sequence").Value = "bin"
denyUrlSequencesCollection.AddElement(addElement)

adminManager.CommitChanges()