跳至內容

如何識別 AWS WAF 中 SQLi 和 XSS 規則調用的流量模式?

2 分的閱讀內容
0

我想識別 AWS WAF 中的 SQL injection 隱碼攻擊 (SQLi) 和跨網站指令碼 (XSS) 規則調用的流量模式。

簡短描述

若要識別 SQLi 和 XSS 規則調用的流量模式,您可以建立 AWS WAF 規則啟用 AWS WAF 記錄。您可以將 AWS 日誌從 Amazon CloudWatch LogsAmazon Simple Storage Service (Amazon S3) 儲存貯體傳送至日誌群組。

解決方法

AWS WAF 日誌在 terminatingRuleMatchDetails 日誌欄位中包含觸發 SQLi 和 XSS 規則的模式。這有助於對 SQLi 和 XSS 規則的誤判問題進行疑難排解。如需詳細資訊,請參閱日誌欄位日誌範例

CloudWatch Logs Insights 查詢

如果您的 AWS WAF 日誌儲存在 Amazon CloudWatch Logs 中,您可以使用 CloudWatch Logs Insights 執行查詢來識別流量模式。

使用 terminatingRuleMatchDetails 日誌欄位執行 CloudWatch Logs Insights 查詢,以識別流量模式。以下查詢會傳回時間戳記、用戶端 IP 位址、來源國家/地區、相符的詳細資訊和請求 ID:

 fields @timestamp
| parse @message ',"terminatingRuleMatchDetails":[*],' as terminatingRuleMatchData
| filter (terminatingRuleMatchData like /XSS/ or terminatingRuleMatchData like /SQL/)
| display @timestamp, httpRequest.clientIp, httpRequest.country, terminatingRuleMatchData, httpRequest.requestId
| limit 100

Amazon Athena 查詢

如果您的 AWS WAF 日誌儲存在 Amazon S3 中,您可以使用 Amazon Athena 查詢來識別流量模式。

使用 terminatingRuleMatchDetails 日誌欄位執行 Amazon Athena 查詢,以識別流量模式。以下查詢會傳回時間戳記、用戶端 IP 位址、來源國家/地區、相符的詳細資訊和請求 ID:

SELECT
to_iso8601(from_unixtime(timestamp / 1000)) as timestamp,
terminatingRuleId,
action,
httpRequest.requestId as RequestID,
httpRequest.clientIp as ClientIP,
httpRequest.country as Country,
termmatchrules.conditionType as ConditionType,
termmatchrules.location as Location,
termmatchrules.matchedData as MatchedData
FROM waf_logs
CROSS JOIN UNNEST(terminatingRuleMatchDetails) as t(termmatchrules)
WHERE termmatchrules.conditionType in ('XSS', 'SQL_INJECTION')

如需了解更多資訊,請參閱如何在 CloudWatch 中分析 AWS WAF 日誌?

相關資訊

在 Amazon CloudWatch Logs 中分析 AWS WAF 日誌

如何在 Amazon Athena 中分析 AWS WAF 日誌?

如何在 AWS WAF 中從 HTTP 請求的 XSS 或 SQLi 檢查中排除特定 URI?

AWS 官方已更新 1 年前