[研究]IIS 10.0 GCB,"要求篩選","允許未列出的副檔名" 不勾選,實測 .axd 檔案(一)
2025-01-20
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2
********************************************************************************
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication1.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<!-- ScriptManager 會產生 ScriptResource.axd -->
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:Label ID="Label1" runat="server" Text="Hello, WebForms!"></asp:Label>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="更新 Label"
OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
|
Default.aspx.cs
using System;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// 首次載入時顯示時間
if (!IsPostBack)
{
Label1.Text = "頁面首次載入:" + DateTime.Now.ToString("HH:mm:ss");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// 更新 Label,這會觸發 UpdatePanel 重新渲染
Label1.Text = "按鈕點擊時間:" + DateTime.Now.ToString("HH:mm:ss");
}
}
}
|
說明
1.ScriptManager:WebForms 核心控制元件,會在頁面生成時自動產生對應的 .axd 檔案,例如:
- ScriptResource.axd?d=xxxx → WebForms 內嵌 JavaScript
- WebResource.axd?d=xxxx → 自訂或第三方嵌入資源
2.UpdatePanel:使用 Ajax 局部更新時,也會向 .axd 發送請求。
3.動態檔案 .axd:
- IIS 並不會在磁碟產生真實檔案。
- 它是 ASP.NET 處理管線 (HTTP Handler) 生成的動態回應。
- FREB(失敗要求追蹤)能夠捕捉這些請求,包括 URL、查詢字串、HTTP Header、狀態碼等。
4/點擊 更新 Label,瀏覽器會發送對 .axd 的請求,且可以在瀏覽器 Network tab 看到,例如:
- http://localhost:1234/WebResource.axd?d=xxxx&t=yyyy
- http://localhost:1234/ScriptResource.axd?d=xxxx
********************************************************************************
Visual Studio 2019 中做 Deploy 到 IIS 網站,
「網站」層級
僅新增 .aspx 允許 (沒允許 .axd),測試網站下圖,按下按鈕後
沒允許 .axd 好像沒關係?
********************************************************************************
- ASP.NET HTTP Handler(例如 ScriptResource.axd、WebResource.axd)
- 由 ASP.NET Runtime 處理,不是由 IIS 當成實體檔案存取
- IIS「要求篩選」的「允許副檔名」主要是管「靜態檔案」
- .axd 屬於「動態處理」 → 不需要列入白名單
- 在 乾淨的 ASP.NET WebForms 專案
- IIS「允許未列出的副檔名」設為 ❌ 不允許
- 沒有手動加 .axd
- 👉 ScriptResource.axd、WebResource.axd 仍然可以正常下載
- ASP.NET 角色服務沒裝
- Application Pool 用錯 .NET CLR
- Handler mapping 被刪掉
- URL Rewrite / Request Filtering 規則強制封鎖所有未明確白名單的 URL
- WAF / 反向代理層阻擋 .axd
- 不要把 .axd 當成一般副檔名管理
- 確保:
- ASP.NET 已正確安裝
- Handler Mappings 存在
- Application Pool 的 .NET CLR 正確
- 為了怕被擋就亂加 .axd
- 把所有「動態副檔名」都加進允許清單
- 副檔名白名單失去意義
- 安全性反而下降
- IIS「允許未列出的副檔名」不勾選時,ASP.NET WebForms 產生的 .axd
- 正常情況下「不需要」加入「允許副檔名」清單
- 若被擋,應檢查 ASP.NET Handler / Pipeline,而不是副檔名白名單
後續
[研究]IIS 10.0 GCB,"要求篩選","允許未列出的副檔名" 不勾選,ASP.NET WebForm 動態生成的檔案,副檔名都不用加入"允許副檔名" 名單嗎?
https://shaurong.blogspot.com/2026/01/iis-100-gcb-aspnet-webform.html
(完)
相關
沒有留言:
張貼留言