次の方法で共有


FTP コマンド フィルター <commandFiltering>

概要

<commandFiltering> 要素は、FTP サービスが許可または拒否する FTP コマンドのコレクションを指定します。 <commandFiltering> 要素には、特定の FTP コマンドを許可するか拒否するかを個別に指定する <add> ステートメントのコレクションが含まれます。

Note

どの FTP コマンドを許可または拒否するかと、一覧に含まれていないコマンドを拒否するかどうかを構成するときは、特別な注意が必要です。 たとえば、USER、PASS、PASV、PORT などの多くのコマンドを拒否すると、FTP サイトが機能不可になります。 同様に、一覧に含まれていないコマンドを既定で拒否すると、おそらく制限が厳しくなりすぎて、多くの FTP クライアントが FTP サイトにアクセスできなくなります。

<commandFiltering> 要素内のコレクションは、<requestFiltering> の設定に関連しています。ただし、要求のフィルター処理はファイルとディレクトリに適用され、URL ごとに構成できますが、<commandFiltering> 要素の下の設定はプロトコル レベルの処理を適用し、サイト レベルでのみ構成できます。

<commandFiltering> 要素の追加の属性は maxCommandLineallowUnlisted です。 これらは、コマンド ラインの最大長と、一覧に含まれていないコマンドを許可するかどうかをそれぞれ構成します。

互換性

バージョン メモ
IIS 10.0 <commandFiltering> 要素は IIS 10.0 では変更されませんでした。
IIS 8.5 <commandFiltering> 要素は IIS 8.5 では変更されませんでした。
IIS 8.0 <commandFiltering> 要素は IIS 8.0 では変更されませんでした。
IIS 7.5 <security> 要素の <commandFiltering> 要素は、IIS 7.5 の機能として付属しています。
IIS 7.0 <security> 要素の <commandFiltering> 要素が、IIS 7.0 用の別個のダウンロードとして FTP 7.0 で導入されました。
IIS 6.0 IIS 6.0 の FTP サービスは、コマンドのフィルター処理をサポートしていませんでした。

Note

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 サーバー] を選びます。

    Note

    FTP サービスに対して ASP.NET メンバーシップ認証または IIS マネージャー認証をサポートするには、[FTP Service] に加えて[FTP 拡張] も選択する必要があります。
    Screenshot of Web Server I I S and F T P Server expanded with F T P Extensibility highlighted.

  5. [次へ] をクリックし、[機能の選択] ページで再度 [次へ] をクリックします。

  6. [インストール オプションの確認] ページで、[インストール] をクリックします。

  7. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] をクリックします。

  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。

  3. [インターネット インフォメーション サービス] を展開し、[FTP サーバー] を展開します。

    Note

    FTP サービスに対して ASP.NET メンバーシップ認証または IIS マネージャー認証をサポートするには、[FTP 拡張] も選択する必要があります。
    Screenshot of Internet Information Services and F T P Server pane expanded with F T P Extensibility highlighted.

  4. OK をクリックします。

  5. 閉じるをクリックします。

Windows Server 2008 R2

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして、[サーバー マネージャ] をクリックします。

  2. [サーバー マネージャ] 階層ウィンドウで [役割] を展開し、[Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] をクリックします。

  4. [役割サービスの追加] ウィザード[役割サービスの選択] ページで [FTP サーバー] を展開します。

  5. [FTP Service] を選択します。

    Note

    FTP サービスに対して ASP.NET メンバーシップ認証または IIS マネージャー認証をサポートするには、[FTP 拡張] も選択する必要があります。
    Screenshot of F T P Server pane expanded in Select Role Service page with F T P Service selected.

  6. 次へ をクリックします。

  7. [インストール オプションの確認] ページで、[インストール] をクリックします。

  8. [結果] ページで、 [閉じる]をクリックします。

Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順にクリックします。

  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。

  3. [インターネット インフォメーション サービス][FTP サーバー] の順に展開します。

  4. [FTP Service] を選択します。

    Note

    FTP サービスに対して ASP.NET メンバーシップ認証または IIS マネージャー認証をサポートするには、[FTP 拡張] も選択する必要があります。
    Screenshot of Internet Information Services and F T P Server pane expanded with both F T P Service and F T P Extensibility selected.

  5. OK をクリックします。

Windows Server 2008 または Windows Vista

  1. 次の URL からインストール パッケージをダウンロードします。

  2. 次のチュートリアルの手順に従って、FTP サービスをインストールします。

操作方法

コマンドのフィルター処理を使用して FTP サイトに対する FTP コマンドを拒否する方法

Note

次の手順は、FTP 7.5 で導入された FTP 要求フィルター ユーザー インターフェイスを使用します。FTP 7.0 を使用している場合、これらの手順は機能しません。

  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. サイトの [ホーム] ウィンドウで、[FTP 要求フィルター] 機能をダブルクリックします。

  4. [コマンド] タブをクリックします。
    Screenshot of the Commands tab in sites Home pane.

  5. [操作] ウィンドウで [コマンドの拒否...] をクリックします。

  6. 拒否する FTP コマンドを入力します。 次に例を示します。

    • 多くの FTP クライアントは、オペレーティング システムに関する情報を公開する可能性がある SYST コマンドを送信せず、必要としていません。
    • FTP 7.0 および FTP 7.5 は、ACCT コマンドを実装していないため、ブロックしても問題ないと考えられます。
  7. OK をクリックします。
    Screenshot of Deny Command dialog box with S Y S T command populating the Command field.

構成

<commandFiltering> 要素は、サイト レベルで構成されます。

属性

属性 説明
maxCommandLine 省略可能な uint 属性。

コマンド ラインの最大長を指定します。 これにはコマンドとパラメーターが含まれます。 構成された制限より長い行は処理されません。

既定値は 4096 です。
allowUnlisted 省略可能で、 Boolean 型の属性。

一覧に含まれていないコマンドを許可するかどうかを指定します。

既定値は true です。

子要素

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

FTP コマンドのコレクションにエントリを追加します。
clear 省略可能な要素です。

FTP コマンドのコレクションをクリアします。
remove 省略可能な要素です。

FTP コマンドのコレクションからエントリを削除します。

構成サンプル

次のサンプルは、FTP サイトの <ftpServer> 要素のいくつかの構成設定を示しています。 具体的には、この例の <site> 設定は、次の方法を示します。

  • FTP サイトを作成し、ポート 21 に FTP プロトコルのバインドを追加します。
  • 証明書を使用して、コントロール チャネルとデータ チャネルの両方でセキュリティで保護されたアクセスを許可するように FTP SSL オプションを構成します。
  • FTP に対して [匿名認証] を無効にして、[基本認証] を有効にします。
  • FTP SYST コマンドのアクセスを拒否します。
  • UNIX のディレクトリの一覧形式を指定します。
  • ログのオプションを構成します。
  • カスタマイズされたウェルカム メッセージを指定し、ローカルの詳細なエラー メッセージを有効にします。
  • 開始時にログイン名に基づくホーム ディレクトリをユーザーに表示するように指定します。ただし、そのディレクトリが存在する場合に限ります。
<site name="ftp.example.com" id="5">
  <application path="/">
    <virtualDirectory path="/" physicalPath="c:\inetpub\www.example.com" />
  </application>
  <bindings>
    <binding protocol="ftp" bindingInformation="*:21:" />
  </bindings>
  <ftpServer>
    <security>
      <ssl controlChannelPolicy="SslAllow"
         dataChannelPolicy="SslAllow"
         serverCertHash="57686f6120447564652c2049495320526f636b73" />
      <authentication>
        <basicAuthentication enabled="true" />
        <anonymousAuthentication enabled="false" />
      </authentication>
      <commandFiltering maxCommandLine="4096" allowUnlisted="true">
        <add command="SYST" allowed="false" />
      </commandFiltering>
    </security>
    <directoryBrowse showFlags="StyleUnix" />
    <logFile logExtFileFlags="Date, Time, ClientIP, UserName, ServerIP, Method, UriStem, FtpStatus, Win32Status, ServerPort, FtpSubStatus, Session, FullPath, Info" />
    <messages expandVariables="true"
       greetingMessage="Welcome %UserName%!"
       allowLocalDetailedErrors="true" />
    <userIsolation mode="StartInUsersDirectory" />
  </ftpServer>
</site>

サンプル コード

次の例は、一覧に含まれていない FTP コマンドを許可し、SYST コマンドを拒否するように Default Web Site を構成します。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites /[name='Default Web Site'].ftpServer.security.commandFiltering.allowUnlisted:"True" /commit:apphost

appcmd.exe set config -section:system.applicationHost/sites /+"[name='Default Web Site'].ftpServer.security.commandFiltering.[command='SYST',allowed='False']" /commit:apphost

Note

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 sitesSection = config.GetSection("system.applicationHost/sites");
         ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();

         ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"Default Web Site");
         if (siteElement == null) throw new InvalidOperationException("Element not found!");

         ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer");
         ConfigurationElement securityElement = ftpServerElement.GetChildElement("security");
         ConfigurationElement commandFilteringElement = securityElement.GetChildElement("commandFiltering");
         ConfigurationElementCollection commandFilteringCollection = commandFilteringElement.GetCollection();

         commandFilteringElement["allowUnlisted"] = true;

         ConfigurationElement addElement = commandFilteringCollection.CreateElement("add");
         addElement["command"] = @"SYST";
         addElement["allowed"] = false;
         commandFilteringCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }

   private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
   {
      foreach (ConfigurationElement element in collection)
      {
         if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
         {
            bool matches = true;
            for (int i = 0; i < keyValues.Length; i += 2)
            {
               object o = element.GetAttributeValue(keyValues[i]);
               string value = null;
               if (o != null)
               {
                  value = o.ToString();
               }
               if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
               {
                  matches = false;
                  break;
               }
            }
            if (matches)
            {
               return element;
            }
         }
      }
      return null;
   }
}

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 sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
      Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection
      Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "Default Web Site")

      If (siteElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If

      Dim ftpServerElement As ConfigurationElement = siteElement.GetChildElement("ftpServer")
      Dim securityElement As ConfigurationElement = ftpServerElement.GetChildElement("security")
      Dim commandFilteringElement As ConfigurationElement = securityElement.GetChildElement("commandFiltering")
      Dim commandFilteringCollection As ConfigurationElementCollection = commandFilteringElement.GetCollection

      commandFilteringElement("allowUnlisted") = True

      Dim addElement As ConfigurationElement = commandFilteringCollection.CreateElement("add")
      addElement("command") = "SYST"
      addElement("allowed") = False
      commandFilteringCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub

   Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
      For Each element As ConfigurationElement In collection
         If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
            Dim matches As Boolean = True
            Dim i As Integer
            For i = 0 To keyValues.Length - 1 Step 2
               Dim o As Object = element.GetAttributeValue(keyValues(i))
               Dim value As String = Nothing
               If (Not (o) Is Nothing) Then
                  value = o.ToString
               End If
               If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
                  matches = False
                  Exit For
               End If
            Next
            If matches Then
               Return element
            End If
         End If
      Next
      Return Nothing
   End Function


End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");
var sitesCollection = sitesSection.Collection;

var siteElementPos = FindElement(sitesCollection, "site", ["name", "Default Web Site"]);
if (siteElementPos == -1) throw "Element not found!";

var siteElement = sitesCollection.Item(siteElementPos);

var ftpServerElement = siteElement.ChildElements.Item("ftpServer");
var securityElement = ftpServerElement.ChildElements.Item("security");
var commandFilteringElement = securityElement.ChildElements.Item("commandFiltering");

commandFilteringElement.Properties.Item("allowUnlisted").Value = true;

var commandFilteringCollection = commandFilteringElement.Collection;

var addElement = commandFilteringCollection.CreateNewElement("add");
addElement.Properties.Item("command").Value = "SYST";
addElement.Properties.Item("allowed").Value = false;
commandFilteringCollection.AddElement(addElement);

adminManager.CommitChanges();

function FindElement(collection, elementTagName, valuesToMatch) {
   for (var i = 0; i < collection.Count; i++) {
      var element = collection.Item(i);
      if (element.Name == elementTagName) {
         var matches = true;
         for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
            var property = element.GetPropertyByName(valuesToMatch[iVal]);
            var value = property.Value;
            if (value != null) {
               value = value.toString();
            }
            if (value != valuesToMatch[iVal + 1]) {
               matches = false;
               break;
            }
         }
         if (matches) {
            return i;
         }
      }
   }
   return -1;
}

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")
Set sitesCollection = sitesSection.Collection

siteElementPos = FindElement(sitesCollection, "site", Array("name", "Default Web Site"))
If siteElementPos = -1 Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If

Set siteElement = sitesCollection.Item(siteElementPos)
Set ftpServerElement = siteElement.ChildElements.Item("ftpServer")
Set securityElement = ftpServerElement.ChildElements.Item("security")
Set commandFilteringElement = securityElement.ChildElements.Item("commandFiltering")

commandFilteringElement.Properties.Item("allowUnlisted").Value = True

Set commandFilteringCollection = commandFilteringElement.Collection

Set addElement = commandFilteringCollection.CreateNewElement("add")
addElement.Properties.Item("command").Value = "SYST"
addElement.Properties.Item("allowed").Value = False
commandFilteringCollection.AddElement(addElement)

adminManager.CommitChanges()

Function FindElement(collection, elementTagName, valuesToMatch)
   For i = 0 To CInt(collection.Count) - 1
      Set element = collection.Item(i)
      If element.Name = elementTagName Then
         matches = True
         For iVal = 0 To UBound(valuesToMatch) Step 2
            Set property = element.GetPropertyByName(valuesToMatch(iVal))
            value = property.Value
            If Not IsNull(value) Then
               value = CStr(value)
            End If
            If Not value = CStr(valuesToMatch(iVal + 1)) Then
               matches = False
               Exit For
            End If
         Next
         If matches Then
            Exit For
         End If
      End If
   Next
   If matches Then
      FindElement = i
   Else
      FindElement = -1
   End If
End Function