URL シーケンスの拒否 <denyUrlSequences>

概要

<denyUrlSequences> 要素には、IIS が拒否する URL 文字のシーケンスを指定する <add> 要素のコレクションが含まれます。これは、Web サーバーでの URL ベースの攻撃を防ぐのに役立ちます。

たとえば、URL で 2 つのピリオド ("..") を使用すると、次の上位のディレクトリで URL を処理するようにサーバーに指示されますが、この処理は、攻撃者がコンテンツ領域の外部の領域へのアクセスを得ようとしていることを示す可能性もあります。 そのパターンの文字をブロックすると、攻撃者がこの URL シーケンスを悪用する可能性が排除されます。

Note

要求のフィルタリングが URL シーケンスが拒否されたために HTTP 要求をブロックすると、IIS 7 は HTTP 404 エラーをクライアントに返し、要求が拒否された理由を識別する一意のサブ状態で次の HTTP 状態をログに記録します。

HTTP サブ状態 説明
404.5 URL シーケンスの拒否

このサブ状態によって、Web 管理者は IIS ログを分析し、潜在的な脅威を特定できます。

Note

IIS 7.5 以降では、<alwaysAllowedUrls> コレクションに URL シーケンスを追加することで、<denyUrlSequences> コレクション内の URL シーケンスをオーバーライドできます。

互換性

バージョン メモ
IIS 10.0 <denyUrlSequences> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <denyUrlSequences> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <denyUrlSequences> 要素は IIS 8.0 では変更されませんでした。
IIS 7.5 <denyUrlSequences> 要素は、IIS 7.5 では変更されませんでした。

注意: IIS 7.5 では、URL シーケンスを <alwaysAllowedUrls> コレクションに追加することで、<denyUrlSequences> 要素内の URL シーケンスをオーバーライドできます。
IIS 7.0 <requestFiltering> コレクションの <denyUrlSequences> 要素は IIS 7.0 で導入されました。
IIS 6.0 <denyUrlSequences> 要素は、IIS 6.0 UrlScan [DenyUrlSequences] 機能を置き換えます。

段取り

IIS 7 以降の既定のインストールには、要求のフィルタリングの役割サービスまたは機能が含まれます。 要求のフィルタリングの役割サービスまたは機能がアンインストールされている場合は、次の手順を使用して再インストールできます。

Windows Server 2012 または Windows Server 2012 R2

  1. タスク バーで [サーバー マネージャー]をクリックします。
  2. [サーバー マネージャー] で、[管理] メニューを選択し、[役割と機能の追加] を選択します。
  3. [役割と機能の追加] ウィザードで、[次へ] をクリックします。 インストールの種類を選択し、[次へ] をクリックします。 対象サーバーを選択し、[次へ] を選択します。
  4. [サーバーの役割] ページで [Web サーバー (IIS)] を展開し、[Web サーバー][セキュリティ][要求のフィルタリング] の順に展開します。 次へ をクリックします。
    Windows Server 2012 または 2012 R 2 の展開されたセキュリティ (インストール済み) の一覧を示すスクリーンショット。要求フィルター処理 (インストール済み) が強調表示されています。 .
  5. [機能の選択] ページで、[次へ] をクリックします。
  6. [インストール オプションの確認] ページで、[インストール] をクリックします。
  7. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] をクリックします。
  2. [コントロール パネル][プログラムと機能] を選択し、[Windows の機能の有効化または無効化] を選択します。
  3. [インターネット インフォメーション サービス]を展開し、[World Wide Web サービス] を展開し、[セキュリティ] を展開して、[要求のフィルタリング] を選択します。
    Windows 8 または 8.1 の [機能] ダイアログのスクリーンショット。要求のフィルター処理が強調表示されています。
  4. OK をクリックします。
  5. 閉じるをクリックします。

Windows Server 2008 または Windows Server 2008 R2

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして、[サーバー マネージャ] をクリックします。
  2. [サーバー マネージャ] 階層ウィンドウで [役割] を展開し、[Web サーバー (IIS)] をクリックします。
  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] を選択します。
  4. 役割サービスの追加ウィザード[役割サービスの選択] ページで、[要求のフィルタリング] を選択し、[次へ] を選択します。
    Windows Server 2008 または 2008 R 2 の [役割サービスの追加] ウィンドウのスクリーンショット。要求のフィルター処理が強調表示されています。
  5. [インストール オプションの確認] ページで、[インストール] をクリックします。
  6. [結果] ページで、 [閉じる]をクリックします。

Windows Vista または Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順にクリックします。
  2. [コントロール パネル][プログラムと機能] を選択し、[Windows の機能の有効化または無効化] を選択します。
  3. [インターネット インフォメーション サービス][World Wide Web サービス][セキュリティ] の順に展開します。
  4. [要求のフィルタリング] を選択し、[OK] を選択します。
    Windows Vista または Windows 7 の [機能] ダイアログのスクリーンショット。要求のフィルター処理が強調表示されています。

操作方法

IIS 7.0 ユーザーの場合の注意: このセクションの一部の手順では、要求のフィルタリング用のユーザー インターフェイスを含む IIS 7.0 用 Microsoft 管理パックをインストールする必要がある場合があります。 IIS 7.0 用 Microsoft 管理パックをインストールするには、次の URL を参照してください。

URL シーケンスを拒否する方法

  1. インターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー] をクリックし、[ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
      • [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーで、[スタート] ボタンをクリックし、[管理ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順にクリックします。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウで、要求のフィルタリング設定を変更する接続、サイト、アプリケーション、またはディレクトリに移動します。

  3. [ホーム] ウィンドウで、[要求のフィルタリング] をダブルクリックします。
    [I I S マネージャー] ウィンドウのスクリーンショット。[要求フィルター] アイコンが強調表示されています。

  4. [要求のフィルタリング] ウィンドウで、[URL シーケンスの拒否] タブを選択し、[操作] ウィンドウの [URL シーケンスの追加] を選択します。
    メイン ウィンドウに [要求のフィルター処理] が表示されている [I I S マネージャー] ウィンドウのスクリーンショット。

  5. [拒否するシーケンスの追加] ダイアログ ボックスで、ブロックする URL シーケンスを入力し、[OK] を選択します。
    [拒否シーケンスの追加] ダイアログのスクリーンショット。
    たとえば、サーバー上のディレクトリ トラバーサルを防ぐには、ダイアログ ボックスに 2 つのピリオド ("..") を入力します。

構成

<requestFiltering> 要素の <denyUrlSequences> 要素は、サイト、アプリケーション、またはディレクトリ レベルで構成されます。

属性

なし。

子要素

要素 説明
add 省略可能な要素です。

拒否された URL シーケンスのコレクションにシーケンスを追加します。
clear 省略可能な要素です。

<denyUrlSequences> コレクションからシーケンスへのすべての参照を削除します。
remove 省略可能な要素です。

<denyUrlSequences> コレクションからシーケンスへの参照を削除します。

構成サンプル

次の Web.config ファイルの例では、3 つの URL シーケンスへのアクセスが拒否されます。 最初のシーケンスはディレクトリ トラバーサルを防ぎ、2 番目のシーケンスは代替データ ストリームへのアクセスを禁止し、3 番目のシーケンスは URL でバックスラッシュが使用されないようにします。

<configuration>
   <system.webServer>
      <security>
         <requestFiltering>
            <denyUrlSequences>
               <add sequence=".." />
               <add sequence=":" />
               <add sequence="\" />
            </denyUrlSequences>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>

次の例では、2 つの特定の文字シーケンスのいずれかが含まれている場合に URL を拒否する <denyUrlSequences> 要素と <alwaysAllowedUrls> 要素の組み合わせを示しますが、これらの 2 つの特定の文字シーケンスの両方を特定の順序で含む特定の URL が常に許可されます。

<system.webServer>
   <security>
      <requestFiltering>
         <denyUrlSequences>
            <add sequence="bad" />
            <add sequence="sequence" />
         </denyUrlSequences>
         <alwaysAllowedUrls>
            <add url="/bad_sequence.txt" />
         </alwaysAllowedUrls>
      </requestFiltering>
   </security>
</system.webServer>

サンプル コード

次のコード サンプルは、既定の Web サイトの 3 つの URL シーケンスへのアクセスを拒否する方法 (ディレクトリ トラバーサル ("..")、代替データ ストリーム (":")、円記号 ("")) を示しています。

AppCmd.exe

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

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

appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /+"denyUrlSequences.[sequence='\']"

PowerShell

Start-IISCommitDelay

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

New-IISConfigCollectionElement -ConfigCollection $denyUrlSequences -ConfigAttribute @{ 'sequence' = '..' }
New-IISConfigCollectionElement -ConfigCollection $denyUrlSequences -ConfigAttribute @{ 'sequence' = ':' }
New-IISConfigCollectionElement -ConfigCollection $denyUrlSequences -ConfigAttribute @{ 'sequence' = '\' }

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");

         ConfigurationElementCollection denyUrlSequencesCollection = requestFilteringSection.GetCollection("denyUrlSequences");

         ConfigurationElement addElement = denyUrlSequencesCollection.CreateElement("add");
         addElement["sequence"] = @"..";
         denyUrlSequencesCollection.Add(addElement);

         ConfigurationElement addElement1 = denyUrlSequencesCollection.CreateElement("add");
         addElement1["sequence"] = @":";
         denyUrlSequencesCollection.Add(addElement1);

         ConfigurationElement addElement2 = denyUrlSequencesCollection.CreateElement("add");
         addElement2["sequence"] = @"\";
         denyUrlSequencesCollection.Add(addElement2);

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

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

      Dim addElement1 As ConfigurationElement = denyUrlSequencesCollection.CreateElement("add")
      addElement1("sequence") = ":"
      denyUrlSequencesCollection.Add(addElement1)

      Dim addElement2 As ConfigurationElement = denyUrlSequencesCollection.CreateElement("add")
      addElement2("sequence") = "\"
      denyUrlSequencesCollection.Add(addElement2)

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

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

var addElement1 = denyUrlSequencesCollection.CreateNewElement("add");
addElement1.Properties.Item("sequence").Value = ":";
denyUrlSequencesCollection.AddElement(addElement1);

var addElement2 = denyUrlSequencesCollection.CreateNewElement("add");
addElement2.Properties.Item("sequence").Value = "\\";
denyUrlSequencesCollection.AddElement(addElement2);

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

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

Set addElement1 = denyUrlSequencesCollection.CreateNewElement("add")
addElement1.Properties.Item("sequence").Value = ":"
denyUrlSequencesCollection.AddElement(addElement1)

Set addElement2 = denyUrlSequencesCollection.CreateNewElement("add")
addElement2.Properties.Item("sequence").Value = "\"
denyUrlSequencesCollection.AddElement(addElement2)

adminManager.CommitChanges()