S03 Waf Traffic 5m Summary
Query
// REVIEW ONLY - Summary Rule KQL Spec: S03 -> Target Table: AWS_WAF_5m_CL
// Schedule: Every 5m over AWSWAF. Extracts Host/User-Agent from Headers once and aggregates by
// WebAclId, Host, URI prefix, ClientIp, Country, Action, and TerminatingRuleId.
AWSWAF
| where TimeGenerated > ago(15m)
| mv-apply Hdr = Headers on (
summarize
HostHeader = take_anyif(tostring(Hdr.value), tolower(tostring(Hdr.name)) == "host"),
UserAgent = take_anyif(tostring(Hdr.value), tolower(tostring(Hdr.name)) == "user-agent")
)
| extend UriPrefix = tostring(split(Uri, "?")[0])
| extend UriSegment = strcat("/", tostring(split(trim_start("/", UriPrefix), "/")[0]))
| summarize
TotalRequests = count(),
AllowedCount = countif(Action =~ "ALLOW"),
BlockedCount = countif(Action =~ "BLOCK"),
ChallengeOrCaptchaCount = countif(Action in~ ("CAPTCHA", "Challenge")),
Success2xx3xxAllowed = countif(Action =~ "ALLOW" and ResponseCodeSent between (200 .. 399)),
Error4xx5xxCount = countif(ResponseCodeSent >= 400),
DistinctUris = dcount(UriPrefix),
SampleRules = make_set(TerminatingRuleId, 15),
SampleUserAgents = make_set(UserAgent, 5)
by WindowStart=bin(TimeGenerated, 5m), WebAclId, HttpSourceName, HttpSourceId,
HostHeader=coalesce(HostHeader, "UnknownHost"), UriSegment, ClientIp, Country,
Action, TerminatingRuleId, Ja3Fingerprint
| take 10000Explanation
This KQL query is designed to analyze AWS WAF (Web Application Firewall) logs every 5 minutes. Here's a simplified breakdown of what it does:
-
Time Filter: It looks at logs generated in the last 15 minutes.
-
Header Extraction: From the HTTP headers, it extracts the "Host" and "User-Agent" values.
-
URI Processing: It processes the URI to get the prefix (everything before the query parameters) and the first segment of the path.
-
Aggregation: It aggregates the data by several fields including WebAclId, Host, URI segment, Client IP, Country, Action, and TerminatingRuleId. For each group, it calculates:
- Total number of requests.
- Number of requests allowed, blocked, or challenged (CAPTCHA/Challenge).
- Number of successful requests (HTTP status codes 200-399) that were allowed.
- Number of error responses (HTTP status codes 400 and above).
- Number of distinct URIs accessed.
- A sample set of up to 15 terminating rule IDs.
- A sample set of up to 5 user agents.
-
Time Binning: It groups the data into 5-minute intervals.
-
Result Limitation: It limits the output to the first 10,000 records.
Overall, this query helps in monitoring and analyzing the traffic patterns and actions taken by AWS WAF, providing insights into request handling and potential security issues.