Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

IIS 安全設定清單:從原則制定到模組、權限、記錄、更新五大面向

編輯:系統常見問題解答

IIS 作為對外服務入口,安全設定必須系統化、文件化、自動化驗證。以下五大面向建立基線:

1. 制定資安政策與分級

  • 定義資產等級 (核心/重要/一般)、可接受風險、基線合規標準 (CIS Microsoft IIS Benchmark)。
  • 政策文件納入變更管理、稽核追蹤、例外申請流程,獲高層簽核並定期審視。

2. 作業系統與 IIS 核心強化

  • Windows Update 自動化:WSUS/SCCM/Intune 推送 → 測試環境驗證 → 生產環境部署,關鍵性更新 72 小時內上線。
  • 僅安裝必要角色服務:移除 FTP、WebDAV、CGI、ISAPI 擴充、Server Side Includes 等未使用模組。PowerShell 驗證:
    Get-WindowsFeature Web-* | Where Installed
  • 停用預設網站:避免自動化掃描鎖定 inetpub\wwwroot。建立專用網站指向非系統磁碟 (如 D:\WebApps),套用 NTFS 最小權限 (IIS_IUSRS: 讀取/執行;寫入僅限 App_Data/Uploads)。
  • 啟用 IIS 要求篩選:
    • 封鎖副檔名 .aspx/.ashx/.asmx/.config/.resx/.cs/.vb/.sql/.bak/.log
    • 限制最大內容長度 (預設 30MB,視業務調整)
    • 封鎖雙重編碼、高位元組序列、SQL 關鍵字模式
    • 隱藏伺服器標頭:<system.webServer><security><requestFiltering removeServerHeader="true" /></security></system.webServer>

3. 應用程式集區與進程隔離

  • 每網站獨立 AppPool,身分識別使用 ApplicationPoolIdentity (虛擬帳號,無密碼、自動 SPN)。
  • .NET CLR 版本隔離:Legacy 2.0 / Modern 4.0 不共用集區。
  • 啟用快速失敗保護:rapidFailProtection="true" maxFailures="5" failureInterval="00:05:00"。
  • 設定私用記憶體/CPU 限制防止單一網站耗盡資源。

4. 驗證、授權與加密

  • 停用匿名驗證 (除公開靜態內容),啟用 Windows 驗證 / ASP.NET Core Identity / OpenID Connect / SAML。
  • 強制 HTTPS:
    • 取得有效憑證 (Let's Encrypt/內部 CA/商業憑證)
    • URL Rewrite 規則導向 HTTPS
    • HSTS: <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains; preload" />
    • TLS 1.2/1.3 僅支援,停用 SSL 3.0/TLS 1.0/1.1 (登錄表 SchUseStrongCrypto = 1)。
  • 應用程式層授權:[Authorize]、Policy-based、Resource-based,永不信任用戶端傳入的角色/權限參數。

5. 記錄、監控與事件回應

  • W3C 擴充記錄欄位完整:date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken。
  • 記錄每日輪替、壓縮、保留 ≥ 90 天、轉送至 SIEM (Windows Event Forwarding / Log Analytics / Splunk / ELK)。
  • 關鍵事件告警:
    • 4xx/5xx 突增、sc-status=401/403/500
    • 要求篩選封鎖事件 (事件 ID 2268/2269)
    • 應用程式集區異常終止 (事件 ID 5002/5011/5013/5036)
    • 憑證即將到期 (CertUtil/ACME 自動續簽監控)
  • 事件回應手冊:
    1. 隔離受影響網站 (停用 AppPool/停用網站)
    2. 保留記憶體傾印 (procdump -ma -e 1 -f \"\" w3wp.exe)
    3. 分析日誌、判斷攻擊向量
    4. 修補/封鎖/還原
    5. 事後複盤、更新規則

自動化驗證腳本 (PowerShell 片段)

# 檢查必要模組
$required = @('Web-WebServer','Web-AppInit','Web-Asp-Net45','Web-Mgmt-Console','Web-Request-Filtering')
$installed = Get-WindowsFeature $required | Where Installed
$missing = $required | Where { $_ -notin $installed.Name }
if ($missing) { Write-Warning "缺少模組: $missing" }

# 檢查 requestFiltering removeServerHeader
$cfg = Get-WebConfigurationProperty -Filter 'system.webServer/security/requestFiltering' -Name 'removeServerHeader'
if (-not $cfg) { Write-Warning "未隱藏 Server 標頭" }

將清單納入基線合規掃描 (SCAP/Ansible/DSC),每日自動檢測、差異報警,確保 IIS 永遠處於已知安全狀態。

Copyright © Windows教程網 All Rights Reserved