共用方式為


FTP 隱藏區段 < hiddenSegments>

概觀

元素 <hiddenSegments> 包含專案集合 <add> ,可識別 FTP 7 將無法存取 FTP 用戶端的特定 URL。

例如,在裝載 ASP.NET 內容的 FTP 伺服器上,您可以封鎖 ASP.NET 相關路徑,例如 bin、App_Code等。封鎖這些 URL 區段可減少有人上傳不受信任程式碼的機會。

注意

當要求篩選因隱藏 URL 區段而封鎖 FTP 要求時,FTP 7 會將 FTP 錯誤傳回給用戶端,並記錄下列 FTP 子狀態,以識別要求遭到拒絕的原因:

FTP 子狀態 描述
8 在要求的路徑中偵測到隱藏區段。

此子狀態可讓 FTP 系統管理員分析其 IIS 記錄,並識別潛在的威脅。

相容性

版本 備註
IIS 10.0 <hiddenSegments> IIS 10.0 中未修改專案。
IIS 8.5 <hiddenSegments> 在 IIS 8.5 中修改專案。
IIS 8.0 在 IIS 8.0 中未修改專案 <hiddenSegments>
IIS 7.5 元素 <hiddenSegments><requestFiltering> 元素會隨附為 IIS 7.5 的功能。
IIS 7.0 元素 <hiddenSegments><requestFiltering> 元素是在 FTP 7.0 中引進,這是 IIS 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 伺服器]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,除了FTP 服務之外,您還需要選取FTP 擴充性
    [伺服器角色] 頁面的螢幕擷取畫面。F T P 擴充性已醒目提示並選取。 .

  5. [下一步],然後在 [ 選取功能 ] 頁面上,再次按 [ 下一步 ]。

  6. 在 [確認安裝選項] 頁面上,按一下 [安裝]

  7. 在 [結果] 頁面上,按一下 [關閉]

Windows 8 或Windows 8.1

  1. 在 [開始] 畫面上,將指標全部移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。

  2. 主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。

  3. 展開 [Internet Information Services],然後選取 [FTP 伺服器]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    [程式和功能] 頁面的螢幕擷取畫面。F T P 擴充性已醒目提示並選取。

  4. 按一下 [確定]。

  5. 按一下 [關閉] 。

Windows Server 2008 R2

  1. 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。

  2. [伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS)

  3. [Web 服務器 (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。

  4. 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,展開[FTP 伺服器]。

  5. 選取 [FTP 服務]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    [新增角色服務精靈] 之 [選取角色服務] 頁面的螢幕擷取畫面。F T P 服務已醒目提示並選取。

  6. 按一下 [下一步] 。

  7. 在 [確認安裝選項] 頁面上,按一下 [安裝]

  8. 在 [結果] 頁面上,按一下 [關閉]

Windows 7

  1. 在工作列上,按一下 [開始],然後按一下[主控台]。

  2. 主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。

  3. 展開 [Internet Information Services],然後展開 [FTP 伺服器]。

  4. 選取 [FTP 服務]。

    注意

    支援 ASP。FTP 服務的成員資格驗證或 IIS 管理員驗證,您也必須選取 [FTP 擴充性]。
    [程式和功能] 頁面的螢幕擷取畫面。F T P 伺服器已展開,並已選取 F T P 服務。

  5. 按一下 [確定]。

Windows Server 2008 或 Windows Vista

  1. 從下列 URL 下載安裝套件:

  2. 請遵循下列逐步解說中的指示來安裝 FTP 服務:

作法

注意

FTP 要求篩選在 FTP 7.0 版本中沒有使用者介面;FTP 要求篩選 UI 已在 FTP 7.5 版本中新增。

如何新增 FTP 隱藏區段

  1. (IIS) 管理員開啟 Internet Information Services

    • 如果您使用 Windows Server 2012 或 Windows Server 2012 R2:

      • 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services] ([IIS) 管理員]。
    • 如果您使用 Windows 8 或 Windows 8.1:

      • 按住Windows鍵,按字母X,然後按一下[主控台]。
      • 按一下 [ 系統管理工具],然後按兩下 [Internet Information Services] ([IIS) 管理員]。
    • 如果您使用 Windows Server 2008 或 Windows Server 2008 R2:

      • 在工作列上,按一下 [ 開始],指向 [ 系統管理工具],然後按一下 [ Internet Information Services (IIS) 管理員]。
    • 如果您使用 Windows Vista 或 Windows 7:

      • 在工作列上,按一下 [開始],然後按一下[主控台]。
      • 按兩下 [ 系統管理工具],然後按兩下 [Internet Information Services] ([IIS) 管理員]。
  2. 在 [ 連線 ] 窗格中,移至您要修改要求篩選設定的月臺或目錄。

  3. 在 [ 首頁] 窗格中,按兩下 [FTP 要求篩選]。

  4. [FTP 要求篩選] 窗格中,按一下 [ 隱藏區段] 索引標籤
    F T P 要求篩選頁面的螢幕擷取畫面。已選取 [隱藏區段] 索引標籤。

  5. 按一下 [動作] 窗格中的 [新增隱藏區段...]。
    [新增隱藏區段] 對話方塊的螢幕擷取畫面。底線私用會寫入 [隱藏區段] 方塊中。

  6. 在 [ 新增隱藏區段 ] 對話方塊中,輸入您想要隱藏的路徑。

  7. 按一下 [確定]。

組態

元素 <hiddenSegments><requestFiltering> 元素是在全域、網站或 URL 層級設定。

屬性

無。

子元素

元素 描述
add 選擇性項目。

將區段新增至隱藏區段的集合。
clear 選擇性項目。

從集合中移除區段 <hiddenSegments> 的所有參考。
remove 選擇性項目。

從集合中移除區段的 <hiddenSegments> 參考。

組態範例

下列範例說明 FTP 月臺元素中的 <system.ftpServer> 數個安全性相關組態設定。 更具體來說, <location> 此範例中的設定會示範如何:

  • 為系統管理員群組指定讀取和寫入權限的 FTP 授權規則。
  • 指定 FTP 要求篩選選項,拒絕 *.exe、*.bat和 *.cmd 檔案。
  • 指定最大內容長度為 1000000 個位元組的 FTP 要求限制,以及 URL 長度上限為 1024 個位元組。
  • 封鎖對_vti_bin虛擬目錄的 FTP 存取,此目錄會與 FrontPage Server Extensions 搭配使用。
  • 指定 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 隱藏區段新增至預設網站;第一個隱藏區段會拒絕存取 「bin」 路徑,而第二個區段會拒絕存取 「App_Code」 路徑。

AppCmd.exe

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

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

注意

當您使用 AppCmd.exe 來設定這些設定時,請務必將 認可 參數 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 hiddenSegmentsCollection = requestFilteringSection.GetCollection("hiddenSegments");

         ConfigurationElement addElement = hiddenSegmentsCollection.CreateElement("add");
         addElement["segment"] = @"bin";
         hiddenSegmentsCollection.Add(addElement);

         ConfigurationElement addElement1 = hiddenSegmentsCollection.CreateElement("add");
         addElement1["segment"] = @"App_Code";
         hiddenSegmentsCollection.Add(addElement1);

         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 hiddenSegmentsCollection As ConfigurationElementCollection = requestFilteringSection.GetCollection("hiddenSegments")

      Dim addElement As ConfigurationElement = hiddenSegmentsCollection.CreateElement("add")
      addElement("segment") = "bin"
      hiddenSegmentsCollection.Add(addElement)

      Dim addElement1 As ConfigurationElement = hiddenSegmentsCollection.CreateElement("add")
      addElement1("segment") = "App_Code"
      hiddenSegmentsCollection.Add(addElement1)

      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 hiddenSegmentsCollection = requestFilteringSection.ChildElements.Item("hiddenSegments").Collection;

var addElement = hiddenSegmentsCollection.CreateNewElement("add");
addElement.Properties.Item("segment").Value = "bin";
hiddenSegmentsCollection.AddElement(addElement);

var addElement1 = hiddenSegmentsCollection.CreateNewElement("add");
addElement1.Properties.Item("segment").Value = "App_Code";
hiddenSegmentsCollection.AddElement(addElement1);

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 hiddenSegmentsCollection = requestFilteringSection.ChildElements.Item("hiddenSegments").Collection

Set addElement = hiddenSegmentsCollection.CreateNewElement("add")
addElement.Properties.Item("segment").Value = "bin"
hiddenSegmentsCollection.AddElement(addElement)

Set addElement1 = hiddenSegmentsCollection.CreateNewElement("add")
addElement1.Properties.Item("segment").Value = "App_Code"
hiddenSegmentsCollection.AddElement(addElement1)

adminManager.CommitChanges()