如何使用 AWS WAF 來允許或封鎖對特定 URI 路徑的存取?
4 分的閱讀內容
0
我想使用 AWS WAF 來允許或封鎖對特定 URI 路徑的存取。
解決方法
若要透過 IP 位址、HTTP 標頭或地理位置來允許或封鎖對特定 URI 路徑的存取,請使用比對規則陳述式。比對陳述式會將網路請求與您的條件進行比對。
首先,請完成以下步驟:
- 開啟 AWS WAF console (AWS WAF 主控台)。
- 在導覽窗格中,選擇 AWS WAF。
- 選擇 Resources & protection packs (資源和防護套件)。
- 選取您的防護套件。
- 在您選取的防護套件中,選取 Rules (規則)。
- 選取規則旁邊的 View and edit (檢視和編輯),檢視或修改與您的防護套件相關的規則。
- 在管理規則的右側窗格中,選擇 Add rules (新增規則)。
- 選擇 Create new rule (建立新規則)。
- 選擇 Custom rule (自訂規則),然後選取 Next (下一步)。
- 在 Rule Type (規則類型),選擇 Custom rule (速自訂規則),然後選取 Next (下一步)。
接著,根據您的需求,請參考相關章節並完成所提供的步驟。
允許或封鎖對特定 URI 路徑的存取
請完成下列步驟:
- 在 Name (名稱) 中,輸入規則的名稱,例如 Block-URI-access。
- 在 Type (類型) 中,選擇 Regular rule (一般規則)。
- 在 If a request (如果請求) 中,選擇 matches the statement (比對陳述式)。
- 在 Statement (陳述式),完成以下步驟:
在 Inspect (檢查) 中,選擇 URI path (URI 路徑)。
在 Match type (比對類型) 中,選擇 Contains string (包含字串)。
在 String to match (要比對的字串):輸入您的 URI 路徑,例如 /admin。
(選用) 在 Text transformation (文字轉換) 中選擇文字轉換,或選擇 None (無)。 - 在 Action (動作),選擇 Allow (允許) 或 Block (封鎖),然後選擇 Add rule (新增規則)。
- (選用) 在 Set Rule Priority (設定規則優先順序) 中選取您的規則,然後設定其優先順序。
- 選擇 Save (儲存)。
依據 IP 位址封鎖對特定 URI 路徑的存取
請完成下列步驟:
- 在 Name (名稱) 中,輸入規則的名稱,例如 Allow-listed-IPs-only。
- 在 Type (類型) 中,選擇 Regular rule (一般規則)。
- 在 If a request (如果請求) 中,選擇 matches all the statements (AND) (符合所有陳述式 (AND))。
- 在 Statement 1 (陳述式 1) 中,完成以下步驟:
在 Inspect (檢查) 中,選擇 URI path (URI 路徑)。
在 Match type (比對類型) 中,選擇 Contains string (包含字串)。
在 String to match (要比對的字串):輸入您的 URI 路徑,例如 /admin。
(選用) 在 Text transformation (文字轉換) 中選擇文字轉換,或選擇 None (無)。 - 在 Statement 2 (陳述式 2) 中,完成以下步驟:
選取 Negate statement results (否定陳述式結果)。
在 Inspect (檢查) 中,選擇 Originates from an IP address in (源自以下位置中的 IP 位址)。
在 IP Set (IP 集),請選擇包含您允許清單 IP 位址的 IP 集,例如 MyTrustedIPs。
在 IP address to use as the originating address (用作原始位址的 IP 位址),選擇 Source IP address (來源 IP 位址)。 - 在 Action (動作),選擇 Block (封鎖),然後選擇 Add rule (新增規則)。
- (選用) 在 Set Rule Priority (設定規則優先順序) 中選取您的規則,然後設定其優先順序。
- 選擇 Save (儲存)。
依據 HTTP 標頭封鎖對特定 URI 路徑的存取
請完成下列步驟:
- 在 Name (名稱) 中,輸入規則的名稱,例如 Allow-specific-referer-only。
- 在 Type (類型) 中,選擇 Regular rule (一般規則)。
- 在 If a request (如果請求) 中,選擇 matches all the statements (AND) (符合所有陳述式 (AND))。
- 在 Statement 1 (陳述式 1) 中,完成以下步驟:
在 Inspect (檢查) 中,選擇 URI path (URI 路徑)。
在 Match type (比對類型) 中,選擇 Contains string (包含字串)。
在 String to match (要比對的字串):輸入您的 URI 路徑,例如 /wp-login。 - 在 Statement 2 (陳述式 2) 中,完成以下步驟:
選取 Negate statement results (否定陳述式結果)。
針對檢查,選擇單一標頭。
在 Header field name (標頭欄位名稱),輸入您的標頭名稱,例如 Referer。
在 Match type (比對類型) 中,選擇 Contains string (包含字串)。
在 String to match (要比對的字串):輸入您的參考值,例如 example.com。 - (選用) 在 Statements 1 and 2 (陳述式 1 和 2) 的 Text transformation (文字轉換) 下,選擇文字轉換,或選擇 None (無)。
- 在 Action (動作),選擇 Block (封鎖),然後選擇 Add rule (新增規則)。
- (選用) 在 Set Rule Priority (設定規則優先順序) 中選取您的規則,然後設定其優先順序。
- 選擇 Save (儲存)。
依據地理位置封鎖對特定 URI 路徑的存取
請完成下列步驟:
- 在 Name (名稱) 中,輸入規則的名稱,例如 LimitAccessByCountry。
- 在 Type (類型) 中,選擇 Regular rule (一般規則)。
- 在 If a request (如果請求) 中,選擇 matches all the statements (AND) (符合所有陳述式 (AND))。
- 在 Statement 1 (陳述式 1) 中,完成以下步驟:
在 Inspect (檢查) 中,選擇 URI path (URI 路徑)。
在 Match type (比對類型) 中,選擇 Contains string (包含字串)。
在 String to match (要比對的字串):輸入您的 URI 路徑,例如 /user/profile。
(選用) 在 Text transformation (文字轉換) 中選擇文字轉換,或選擇 None (無)。 - 在 Statement 2 (陳述式 2) 中,完成以下步驟:
選取 Negate statement results (否定陳述式結果)。
在 Inspect (檢查) 中,選擇 Originates from a country in (源自某個國家/地區)。
在 Country codes (國家代碼),選擇要檢查其請求的國家/地區。
在 IP address to use to determine the country of origin (用於判定來源國家的 IP 位址) 中,選擇 Source IP address (來源 IP 位址)。 - 在 Action (動作),選擇 Block (封鎖),然後選擇 Add rule (新增規則)。
- (選用) 在 Set Rule Priority (設定規則優先順序) 中選取您的規則,然後設定其優先順序。
- 選擇 Save (儲存)。
相關資訊
沒有評論
相關內容
- 已提問 2 年前
- 已提問 10 個月前
