ISAPI/CGI 限制 < isapiCgiRestriction>
概觀
安全性元素的 元素可讓您指定可在 Internet Information Services (IIS) 7 上執行的 Common Gateway Interface (CGI) (和 Internet Server Application Programming Interface (ISAPI) 應用程式清單。<><isapiCgiRestriction>
此元素可讓您確保惡意使用者無法將未經授權的 CGI 和 ISAPI 二進位檔複製到您的 Web 服務器,然後執行它們。
只有當網站或應用程式使用以傳統模式執行的應用程式集區時,才需要使用這個專案來設定網頁伺服器。 您在 元素中 <isapiCgiRestriction>
設定的限制僅適用于 ISAPI 和 CGI 程式碼。
專案 <isapiCgiRestriction>
包含專案的 <add>
集合。 每個 <add>
元素都會定義無法在傳統模式的 IIS 7 伺服器上執行的相異二進位檔。
例如,如果您建立 ASP.NET 2.0 應用程式,並將應用程式設定為使用傳統模式執行的應用程式集區,則 ASP.NET 應用程式的任何要求都必須經過要處理的aspnet_isapi.dll。 為了確保 IIS 處理 ASP.NET 要求,IIS 會將 <isapiCgiRestriction>
<add>
包含允許屬性的專案填入元素,其值設定為 true。
如果您將允許的屬性變更為 false ,並將應用程式集區保留在傳統模式中,ASP.NET 要求將會失敗。 不過,如果您將應用程式集區變更為整合模式,IIS 會使用整合式要求管線來處理 ASP.NET 要求,這會略過您設定的 ISAPI 和 CGI 限制。
元素 <isapiCgiRestriction>
會與applicationDependencies > 元素搭配運作, <以定義哪些應用程式相依于一或多個 CGI 或 ISAPI 擴充限制。
相容性
版本 | 備註 |
---|---|
IIS 10.0 | 未在 IIS 10.0 中修改專案 <isapiCgiRestriction> 。 |
IIS 8.5 | 未在 IIS 8.5 中修改專案 <isapiCgiRestriction> 。 |
IIS 8.0 | 未在 IIS 8.0 中修改專案 <isapiCgiRestriction> 。 |
IIS 7.5 | 未在 IIS 7.5 中修改專案 <isapiCgiRestriction> 。 |
IIS 7.0 | 元素 <isapiCgiRestriction> 是在 IIS 7.0 中引進。 |
IIS 6.0 | 集合 <isapiCgiRestriction> 會取代 IIS 6.0 IIsWebService Metabase 物件的WebSvcExtRestrictionList屬性。 |
安裝程式
<isapiCgiRestriction>
只有在您在 IIS 7 和更新版本伺服器上安裝 CGI 或 ISAPI 擴充模組之後,才能使用集合。 您無法將它與這些功能無關安裝。
Windows Server 2012 或 Windows Server 2012 R2
- 在工作列上,按一下 [伺服器管理員]。
- 在[伺服器管理員] 中,按一下 [管理] 功能表,然後按一下 [新增角色及功能]。
- 在 [ 新增角色及功能精 靈] 中,按 [ 下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
- 在 [ 伺服器角色] 頁面上,依 序展開 [Web 服務器] ([IIS) ]、[ Web 服務器]、[ 應用程式刪除],然後選取 [CGI ] 或 [ ISAPI 擴充功能]。 按一下 [下一步] 。
.
- 在 [選取功能] 頁面上,按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows 8 或 Windows 8.1
- 在 [開始] 畫面上,將指標一路移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 依序展開 [Internet Information Services]、[ 萬維網服務]、[ 應用程式開發功能],然後選取 [CGI ] 或 [ ISAPI 擴充功能]。
- 按一下 [確定]。
- 按一下 [關閉] 。
Windows Server 2008 或 Windows Server 2008 R2
- 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
- 在[伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS) 。
- 在 [ Web Server (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
- 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取[CGI] 或[ISAPI 擴充功能]。
- 如果出現 [ 新增角色服務 ] 對話方塊,請按一下 [ 新增必要的角色服務]。 (只有在您尚未在 server 上安裝任何必要條件角色服務時,才會顯示此頁面。)
- 在 [選取角色服務] 頁面上,按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows Vista 或 Windows 7
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下[開啟或關閉 Windows 功能]。
- 在 [Windows 功能] 對話方塊中,依序展開 [ Internet Information Services]、[ World Wide Web 服務] 和 [ 應用程式開發功能]。
- 選取 [CGI ] 或 [ISAPI 擴充功能],然後按一下 [ 確定]。
作法
如何新增 ISAPI 或 CGI 限制
開啟 [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。
在 [ 連線] 窗格中,按一下伺服器名稱。
在 [ 首頁] 窗格中,按兩下 [ISAPI] 和 [CGI 限制]。
在 [ 動作 ] 窗格中,按一下 [ 新增...]
在 [ 新增 ISAPI 或 CGI 限制 ] 對話方塊中,于 [ISAPI 或 CGI 路徑 ] 方塊中輸入要新增之二進位檔的路徑,在 [ 描述 ] 方塊中輸入二進位檔的描述,選取 [ 允許延伸模組路徑] 選項執行 核取方塊,以允許二進位檔在伺服器上執行,然後按一下 [ 確定]。
組態
<isapiCgiRestriction>
集合只能在 ApplicationHost.config 檔案的伺服器層級設定。
屬性
屬性 | 描述 |
---|---|
notListedIsapisAllowed |
選擇性的 Boolean 屬性。 指定是否允許在此伺服器上執行未列出的 ISAPI 模組。 預設值是 false 。 |
notListedCgisAllowed |
選擇性的 Boolean 屬性。 指定是否允許在此伺服器上執行未列出的 CGI 程式。 預設值是 false 。 |
子元素
元素 | 描述 |
---|---|
add |
選擇性項目。 將限制新增至 ISAPI 和 CGI 限制的集合。 |
remove |
選擇性項目。 從 isapiCgiRestriction 集合中移除限制的參考。 |
clear |
選擇性項目。 從 isapiCgiRestriction 集合中移除限制的所有參考。 |
組態範例
下列組態範例是 <isapiCgiRestriction>
安裝 ASP 和 ASP.NET 2.0 版之後,IIS 7.0 的專案組態。
<security>
<isapiCgiRestriction>
<add allowed="true" groupId="ASP"
path="%windir%\system32\inetsrv\asp.dll"
description="Active Server Pages" />
<add allowed="true" groupId="ASP.NET v2.0.50727"
path="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
description="ASP.NET v2.0.50727" />
</isapiCgiRestriction>
</security>
範例程式碼
下列範例會針對位於 C:\Inetpub\www.contoso.com\wwwroot 的網站內容資料夾中的自訂 ISAPI 延伸模組新增 ISAPI/CGI 限制。 這些範例會指定 ISAPI 擴充功能的名稱、路徑和群組,並啟用擴充功能。
AppCmd.exe
appcmd.exe set config -section:system.webServer/security/isapiCgiRestriction /+"[path='C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll',allowed='True',groupId='ContosoGroup',description='Contoso Extension']" /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 isapiCgiRestrictionSection = config.GetSection("system.webServer/security/isapiCgiRestriction");
ConfigurationElementCollection isapiCgiRestrictionCollection = isapiCgiRestrictionSection.GetCollection();
ConfigurationElement addElement = isapiCgiRestrictionCollection.CreateElement("add");
addElement["path"] = @"C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll";
addElement["allowed"] = true;
addElement["groupId"] = @"ContosoGroup";
addElement["description"] = @"Contoso Extension";
isapiCgiRestrictionCollection.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 isapiCgiRestrictionSection As ConfigurationSection = config.GetSection("system.webServer/security/isapiCgiRestriction")
Dim isapiCgiRestrictionCollection As ConfigurationElementCollection = isapiCgiRestrictionSection.GetCollection
Dim addElement As ConfigurationElement = isapiCgiRestrictionCollection.CreateElement("add")
addElement("path") = "C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll"
addElement("allowed") = True
addElement("groupId") = "ContosoGroup"
addElement("description") = "Contoso Extension"
isapiCgiRestrictionCollection.Add(addElement)
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var isapiCgiRestrictionSection = adminManager.GetAdminSection("system.webServer/security/isapiCgiRestriction", "MACHINE/WEBROOT/APPHOST");
var isapiCgiRestrictionCollection = isapiCgiRestrictionSection.Collection;
var addElement = isapiCgiRestrictionCollection.CreateNewElement("add");
addElement.Properties.Item("path").Value = "C:\\Inetpub\\www.contoso.com\\wwwroot\\isapi\\custom.dll";
addElement.Properties.Item("allowed").Value = true;
addElement.Properties.Item("groupId").Value = "ContosoGroup";
addElement.Properties.Item("description").Value = "Contoso Extension";
isapiCgiRestrictionCollection.AddElement(addElement);
adminManager.CommitChanges();
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set isapiCgiRestrictionSection = adminManager.GetAdminSection("system.webServer/security/isapiCgiRestriction", "MACHINE/WEBROOT/APPHOST")
Set isapiCgiRestrictionCollection = isapiCgiRestrictionSection.Collection
Set addElement = isapiCgiRestrictionCollection.CreateNewElement("add")
addElement.Properties.Item("path").Value = "C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll"
addElement.Properties.Item("allowed").Value = True
addElement.Properties.Item("groupId").Value = "ContosoGroup"
addElement.Properties.Item("description").Value = "Contoso Extension"
isapiCgiRestrictionCollection.AddElement(addElement)
adminManager.CommitChanges()