Query Details

D06 Awswaf Schema Check

Query

// REVIEW ONLY - Mandatory Step 1: AWSWAF Schema, Header Casing & RuleGroupList Structure Discovery
// Validates how Host/User-Agent appear inside Headers dynamic array and whether NonTerminatingMatchingRules
// / Labels / Ja3Fingerprint are populated in the current AWS S3 WAF CCF connector version.
AWSWAF
| where TimeGenerated > ago(24h)
| extend HttpReqKeys = bag_keys(HttpRequest),
    TermRuleKeys = bag_keys(TerminatingRule),
    HeaderSample = iff(array_length(Headers) > 0, bag_keys(Headers[0]), dynamic([]))
| summarize
    Requests = count(),
    Actions = make_set(Action, 10),
    SourceTypes = make_set(HttpSourceName, 10),
    HasJa3Pct = round(100.0 * countif(isnotempty(column_ifexists("Ja3Fingerprint", ""))) / count(), 1),
    HasLabelsPct = round(100.0 * countif(array_length(Labels) > 0) / count(), 1),
    ObservedHttpReqKeys = make_set(HttpReqKeys, 30),
    ObservedHeaderObjKeys = make_set(HeaderSample, 10),
    ObservedTermRuleKeys = make_set(TermRuleKeys, 20)
    by WebAclId, HttpSourceId
| order by Requests desc
| take 200

Explanation

This KQL query is designed to analyze data from AWS WAF logs over the past 24 hours. Here's a simple breakdown of what it does:

  1. Data Source: It pulls data from the AWSWAF table, focusing on entries generated in the last 24 hours.

  2. Data Extraction:

    • It extracts keys from the HttpRequest and TerminatingRule fields.
    • It also samples keys from the Headers array if it contains any elements.
  3. Data Aggregation:

    • It counts the total number of requests.
    • It creates sets of unique actions taken (Action) and source types (HttpSourceName), limiting each to 10 unique values.
    • It calculates the percentage of requests that have a non-empty Ja3Fingerprint.
    • It calculates the percentage of requests that have labels (Labels).
  4. Key Observation:

    • It collects up to 30 unique keys observed in HttpRequest.
    • It collects up to 10 unique keys from the first element of Headers.
    • It collects up to 20 unique keys from TerminatingRule.
  5. Grouping and Sorting:

    • The results are grouped by WebAclId and HttpSourceId.
    • The groups are sorted in descending order based on the number of requests.
  6. Result Limitation:

    • It limits the output to the top 200 results.

Overall, this query is used to review and validate the structure and content of AWS WAF logs, focusing on the presence of certain fields and the diversity of request attributes.