共用方式為


隱藏區段 < hiddenSegments>

概觀

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

例如,在裝載 ASP.NET 內容的 Web 服務器上,IIS 7 會為您封鎖數個 ASP.NET 相關路徑;Web.config、bin、App_Code等。封鎖這些 URL 區段可降低攻擊者能夠利用這些 URL 取得資訊的機會。

注意

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

HTTP 子狀態 描述
404.8 隱藏命名空間

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

相容性

版本 備註
IIS 10.0 未在 IIS 10.0 中修改專案 <hiddenSegments>
IIS 8.5 未在 IIS 8.5 中修改專案 <hiddenSegments>
IIS 8.0 未在 IIS 8.0 中修改專案 <hiddenSegments>
IIS 7.5 未在 IIS 7.5 中修改專案 <hiddenSegments>
IIS 7.0 <hiddenSegments>集合的 <requestFiltering> 元素是在 IIS 7.0 中引進。
IIS 6.0 元素 <hiddenSegments> 會取代 IIS 6.0 UrlScan [DenyUrlSequences] 功能。

安裝程式

IIS 7 和更新版本的預設安裝包含要求篩選角色服務或功能。 如果卸載要求篩選角色服務或功能,您可以使用下列步驟重新安裝它。

Windows Server 2012 或 Windows Server 2012 R2

  1. 在工作列上,按一下 [伺服器管理員]
  2. [伺服器管理員] 中,按一下 [管理] 功能表,然後按一下 [新增角色及功能]。
  3. 在 [ 新增角色及功能精 靈] 中,按 [ 下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
  4. 在 [ 伺服器角色] 頁面上,依序展開 [ Web 服務器] ([IIS) ]、[ Web 服務器]、[ 安全性],然後選取 [ 要求篩選]。 按一下 [下一步] 。
    顯示針對 Windows Server 2012 選取 [要求篩選] 的螢幕擷取畫面。 .
  5. 在 [選取功能] 頁面上,按 [下一步]
  6. 在 [確認安裝選項] 頁面上,按一下 [安裝]
  7. 在 [結果] 頁面上,按一下 [關閉]

Windows 8 或 Windows 8.1

  1. 在 [開始] 畫面上,將指標一路移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
  2. 主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
  3. 序展開 [Internet Information Services]、[ 萬維網服務]、[ 安全性],然後選取 [ 要求篩選]。
    顯示針對 Windows 8 選取 [要求篩選] 的螢幕擷取畫面。
  4. 按一下 [確定]。
  5. 按一下 [關閉] 。

Windows Server 2008 或 Windows Server 2008 R2

  1. 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
  2. [伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS)
  3. 在 [ Web Server (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
  4. 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取 [要求篩選],然後按 [下一步]。
    顯示針對 Windows Server 2008 選取 [要求篩選] 的螢幕擷取畫面。
  5. 在 [確認安裝選項] 頁面上,按一下 [安裝]
  6. 在 [結果] 頁面上,按一下 [關閉]

Windows Vista 或 Windows 7

  1. 在工作列上,按一下 [開始],然後按一下[主控台]。
  2. 主控台中,按一下 [程式和功能],然後按一下[開啟或關閉 Windows 功能]。
  3. 依序展開 [Internet Information Services]、[ World Wide Web 服務] 和 [ 安全性]。
  4. 選取 [ 要求篩選],然後按一下 [ 確定]。
    顯示針對 Windows Vista 或 Windows 7 選取 [要求篩選] 的螢幕擷取畫面。

作法

IIS 7.0 使用者的注意事項:本節中的某些步驟可能需要您安裝適用于 IIS 7.0 的 Microsoft 系統管理元件,其中包含用於要求篩選的使用者介面。 若要安裝適用于 IIS 7.0 的 Microsoft 系統管理元件,請參閱下列 URL:

如何新增隱藏區段

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

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

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

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

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

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

  3. 在 [ 首頁] 窗格中,按兩下 [ 要求篩選]。
    顯示 [預設網站首頁] 窗格的螢幕擷取畫面。已選取 [要求篩選]。

  4. 在 [要求篩選] 窗格中,按一下 [隱藏區段] 索引標籤,然後按一下 [動作] 窗格中的 [新增隱藏區段...]。
    顯示 [要求篩選] 窗格的螢幕擷取畫面。

  5. 在 [ 新增隱藏區段 ] 對話方塊中,輸入您想要隱藏的相對路徑,然後按一下 [ 確定]。
    顯示 [新增隱藏區段] 對話方塊的螢幕擷取畫面。[隱藏區段] 文字方塊中會輸入底線私用。

組態

屬性

屬性 描述
applyToWebDAV 選擇性的 Boolean 屬性。

指定這些設定是否也應該套用至 WebDAV 要求。

子元素

元素 描述
add 選擇性項目。

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

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

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

組態範例

下列範例Web.config檔案會設定兩個選項:它會將 IIS 設定為拒絕存取 「_private」 資料夾的要求,並將設定要求篩選以允許 WebDAV 存取隱藏區段。

<configuration>
   <system.webServer>
      <security>
         <requestFiltering>
            <hiddenSegments applyToWebDAV="false">
               <add segment="_private" />
            </hiddenSegments>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>

範例程式碼

下列程式碼範例會設定兩個選項:他們會將 IIS 設定為拒絕存取 「Default Web Site」 中 「_private」 資料夾的要求,並設定要求篩選以允許 WebDAV 存取隱藏區段。

AppCmd.exe

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

appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /+"hiddenSegments.[segment='_private']"

PowerShell

$hiddenSegments = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering' | Get-IISConfigElement -ChildElementName 'hiddenSegments'
Set-IISConfigAttributeValue -ConfigElement $hiddenSegments -AttributeName 'applyToWebDAV' -AttributeValue $false

$hiddenSegments = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering' | Get-IISConfigCollection -CollectionName 'hiddenSegments'
New-IISConfigCollectionElement -ConfigCollection $hiddenSegments -ConfigAttribute @{ 'segment' = '_private' }

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 hiddenSegmentsElement = requestFilteringSection.GetChildElement("hiddenSegments");
         hiddenSegmentsElement["applyToWebDAV"] = false;
         ConfigurationElementCollection hiddenSegmentsCollection = hiddenSegmentsElement.GetCollection();

         ConfigurationElement addElement = hiddenSegmentsCollection.CreateElement("add");
         addElement["segment"] = @"_private";
         hiddenSegmentsCollection.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 hiddenSegmentsElement As ConfigurationElement = requestFilteringSection.GetChildElement("hiddenSegments")
      hiddenSegmentsElement("applyToWebDAV") = False
      Dim hiddenSegmentsCollection As ConfigurationElementCollection = hiddenSegmentsElement.GetCollection

      Dim addElement As ConfigurationElement = hiddenSegmentsCollection.CreateElement("add")
      addElement("segment") = "_private"
      hiddenSegmentsCollection.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 hiddenSegmentsElement = requestFilteringSection.ChildElements.Item("hiddenSegments");
hiddenSegmentsElement.Properties.Item("applyToWebDAV").Value = false;

var hiddenSegmentsCollection = hiddenSegmentsElement.Collection;

var addElement = hiddenSegmentsCollection.CreateNewElement("add");
addElement.Properties.Item("segment").Value = "_private";
hiddenSegmentsCollection.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 hiddenSegmentsElement = requestFilteringSection.ChildElements.Item("hiddenSegments")
hiddenSegmentsElement.Properties.Item("applyToWebDAV").Value = False

Set hiddenSegmentsCollection = hiddenSegmentsElement.Collection

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

adminManager.CommitChanges()