AWS announces preview of AWS Interconnect - multicloud
AWS announces AWS Interconnect – multicloud (preview), providing simple, resilient, high-speed private connections to other cloud service providers. AWS Interconnect - multicloud is easy to configure and provides high-speed, resilient connectivity with dedicated bandwidth, enabling customers to interconnect AWS networking services such as AWS Transit Gateway, AWS Cloud WAN, and Amazon VPC to other cloud service providers with ease.
如何在 AWS WAF 中從 HTTP 請求的 XSS 或 SQLi 檢查中排除特定 URI?
當我使用 AWS WAF 時,某些 HTTP 請求出現 SQL 隱碼攻擊 (SQLi) 或跨網站指令碼 (XSS) 的誤報。我想從 HTTP 請求的 XSS 或 SQLi 檢查中排除特定 URI。
簡短描述
在對 AWS 受管規則和自訂規則進行 XSS 和 SQLi 規則檢查期間,有時會發生誤報。為避免誤報,請從 XSS 和 SQLi 檢查中排除特定的 URI 路徑。為此,請使用巢狀陳述式撰寫含有例外狀況的封鎖規則,以便 AWS WAF 根據所有其他規則評估請求。
解決方法
範例 HTTP 或 HTTPS 請求
http://www.amazon.com/path/string1?xss=%3Cscript%3E%3Cscript%3E&sql=UNION%20ALL%20SELECT%201
在上一個請求中,URI 路徑為 ** /路徑/字符串 1**。問號 (?) 後面的字串是查詢字串。在此範例中,查詢字串是 xss=%3Cscript%3E%3Cscript%3E&sql=UNION%20ALL%20SELECT%201。
範例規則允許來自 XSS 或 SQLi 檢查的特定 URI
**注意:**下列範例規則組態僅供參考。自訂這些規則,以取得 PositionalConstraint、SearchString 和 TextTransformations 等資訊。您可以使用類似的邏輯來允許特定標頭和查詢參數等組態。
案例 1: 使用 AWS 受管規則
AWS 受管規則群組 AWSManagedRulesCommonRuleSet 包含下列規則:
- CrossSiteScripting_COOKIE
- CrossSiteScripting_QUERYARGUMENTS
- CrossSiteScripting_BODY
- CrossSiteScripting_URIPATH
AWSManagedRulesCommonRuleSet 規則群組具有 BLOCK 動作,會檢查請求對應部分中是否有 XSS 攻擊字串。如需詳細資訊,請參閱核心規則集 (CRS) 受管規則群組。
同樣地,規則群組 AWSManagedRulesSQLiRuleSet 具有用於檢查查詢參數、主體、URI 路徑和 SQL 隱碼攻擊模式的 Cookie 的規則。如需詳細資訊,請參閱使用案例特定規則群組。
當請求符合這些規則時,AWS WAF 會產生對應的標籤。然後,WEB ACL 中的自訂規則可以使用這些 AWS 受管規則標籤,選擇性地從符合的規則簽章中排除特定請求。
若要允許特定 URI,請完成下列步驟:
- 將 AWSManagedRulesCommonRuleSet 規則群組中的下列規則保持在計數模式:
CrossSiteScripting_COOKIE
CrossSiteScripting_QUERYARGUMENTS
CrossSiteScripting_BODY
CrossSiteScripting_URIPATH - 建立包含封鎖動作的規則,URI 路徑除外。設定優先順序低於 AWSManagedRulesCommonRuleSet 優先順序的規則。若要在 AWS WAF 主控台中設定較低優先順序,請將規則放在清單的下方。若要在 JSON 中設定較低優先順序,請使用較大的優先順序值。
此規則使用下列邏輯: (XSS_URIPATH or XSS_Cookie or XSS_Body or XSS_QueryArguments) AND (NOT allowlisted URIString) = BLOCK
使用下列組態:
**注意:**在此範例中,OrStatement 從 Web 要求的所有標籤和部分中排除特定的 URI:主體、標頭、URI 路徑和查詢參數。此範例假設您在 Web 請求的所有部分中遇到相同 URI 的誤報。但是,您可能只在 Web 請求的一部分中遇到誤報,例如在查詢參數中。在此情況下,只針對 Web 請求的一部分及其相符標籤建立個別規則是安全性最佳實務。對於此個別規則,請勿從 Web 請求的所有部分中排除特定的 URI 路徑。{ "Name": "whitelist-xss", "Priority": 10, "Statement": { "AndStatement": { "Statements": [ { "OrStatement": { "Statements": [ { "LabelMatchStatement": { "Scope": "LABEL", "Key": "awswaf:managed:aws:core-rule-set:CrossSiteScripting_URIPath" } }, { "LabelMatchStatement": { "Scope": "LABEL", "Key": "awswaf:managed:aws:core-rule-set:CrossSiteScripting_Cookie" } }, { "LabelMatchStatement": { "Scope": "LABEL", "Key": "awswaf:managed:aws:core-rule-set:CrossSiteScripting_Body" } }, { "LabelMatchStatement": { "Scope": "LABEL", "Key": "awswaf:managed:aws:core-rule-set:CrossSiteScripting_QueryArguments" } } ] } }, { "NotStatement": { "Statement": { "ByteMatchStatement": { "SearchString": "/path/string1", "FieldToMatch": { "UriPath": {} }, "TextTransformations": [ { "Priority": 0, "Type": "NONE" } ], "PositionalConstraint": "CONTAINS" } } } } ] } }, "Action": { "Block": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "whitelist-xss" } }
對於 AWSManagedRulesSQLiRuleSet,請使用相同的步驟,但將標籤取代為 AWSManagedRulesSQLiRuleSet 產生的標籤。
如果您有多個要從檢查中排除的 URI,請在 NotStatement 中使用 OrStatement。例如,若要排除 /path/string1 和 /path/string2,請使用下列 NotStatement:
{ "NotStatement": { "Statement": { "OrStatement": { "Statements": [ { "ByteMatchStatement": { "SearchString": "/path/string1", "FieldToMatch": { "UriPath": {} }, "TextTransformations": [ { "Priority": 0, "Type": "NONE" } ], "PositionalConstraint": "CONTAINS" } }, { "ByteMatchStatement": { "SearchString": "/path/string2", "FieldToMatch": { "UriPath": {} }, "TextTransformations": [ { "Priority": 0, "Type": "NONE" } ], PositionalConstraint": "CONTAINS" } } ] } } } }
案例 2: 使用自訂 XSS 和 SQLi 規則
此規則使用下列邏輯:
(XSS_URIPATH or XSS_Cookie or XSS_Body or XSS_QueryArguments) AND (NOT allowlisted URIString) = BLOCK
使用下列規則組態檢查請求的 XSS 攻擊字串,但也可以選擇性排除特定 URI_PATH:
{ "Name": "xss-URI", "Priority": 10, "Action": { "Block": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "xss-URI" }, "Statement": { "AndStatement": { "Statements": [ { "OrStatement": { "Statements": [ { "XssMatchStatement": { "FieldToMatch": { "UriPath": {} }, "TextTransformations": [ { "Priority": 0, "Type": "NONE" } ] } }, { "XssMatchStatement": { "FieldToMatch": { "Cookies": { "MatchPattern": { "All": {} }, "MatchScope": "ALL", "OversizeHandling": "CONTINUE" } }, "TextTransformations": [ { "Priority": 0, "Type": "NONE" } ] } }, { "XssMatchStatement": { "FieldToMatch": { "Body": { "OversizeHandling": "CONTINUE" } }, "TextTransformations": [ { "Priority": 0, "Type": "NONE" } ] } }, { "XssMatchStatement": { "FieldToMatch": { "AllQueryArguments": {} }, "TextTransformations": [ { "Priority": 0, "Type": "NONE" } ] } } ] } }, { "NotStatement": { "Statement": { "ByteMatchStatement": { "FieldToMatch": { "UriPath": {} }, "PositionalConstraint": "CONTAINS", "SearchString": "/path/string1", "TextTransformations": [ { "Type": "NONE", "Priority": 0 } ] } } } } ] } } }
使用 SQLi 陳述式時遵循此程序。
**注意:**擁有較高優先順序、只允許 URI 的規則並不是最佳做法。此最佳做法會阻止針對 Web ACL 中定義的所有其他規則評估含有允許 URI\ _PATH 的請求。
