Query Details

26 Web Edge Waf Targeted Hosts And Bypass Candidates

Query

// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: WebEdge | Panel: waf-targeted-hosts-and-bypass-candidates | Visualization: table | Mode: All
// Security Question: Which attacker IPs triggered >= 10 WAF blocks and also achieved HTTP 2xx/3xx ALLOW responses on the same host?
// Drill-Through: Click ClientIp to set SelectedIp and inspect downstream VPC/Entra/XDR activity.
// Empty/No-Data Contract: No ClientIp exhibited both repeated WAF blocks (>=10) and allowed 2xx/3xx responses in window.
let Start = {TimeRange:start};
let End = {TimeRange:end};
let OrgFilter = base64_decode_tostring("{Organization:base64}");
let AccountFilter = base64_decode_tostring("{AwsAccount:base64}");
let RegionFilter = base64_decode_tostring("{AwsRegion:base64}");
let EnvFilter = base64_decode_tostring("{Environment:base64}");
let WorkloadFilter = base64_decode_tostring("{Workload:base64}");
let SeverityFilter = base64_decode_tostring("{Severity:base64}");
let SourceFilter = base64_decode_tostring("{SourceTable:base64}");
let SummaryPref = base64_decode_tostring("{SummaryMode:base64}");
let SelectedPrincipalFilter = base64_decode_tostring("{SelectedPrincipal:base64}");
let SelectedIpFilter = base64_decode_tostring("{SelectedIp:base64}");
union isfuzzy=true
    (datatable(TimeGenerated:datetime, WebAclId:string, HttpSourceName:string, Headers:dynamic, Uri:string, Action:string, ResponseCodeSent:int, NonTerminatingMatchingRules:dynamic, TerminatingRuleId:string, ClientIp:string, Country:string, Ja3Fingerprint:string)[]),
    (AWSWAF | where TimeGenerated between (Start .. End)
     | project TimeGenerated, WebAclId, HttpSourceName, Headers=todynamic(Headers), Uri, Action, ResponseCodeSent, NonTerminatingMatchingRules=todynamic(NonTerminatingMatchingRules), TerminatingRuleId, ClientIp, Country, Ja3Fingerprint)
| mv-apply Hdr = Headers on (
    summarize HostHeader = take_anyif(tostring(Hdr.value), tolower(tostring(Hdr.name)) == "host")
)
| extend CleanUri = tostring(split(Uri, "?")[0])
| summarize TotalReqs=count(), BlockedReqs=countif(Action == "BLOCK"),
    Allowed2xx3xx=countif(Action == "ALLOW" and ResponseCodeSent between (200 .. 399)),
    CountModeMatches=countif(array_length(NonTerminatingMatchingRules) > 0),
    MatchedRules=make_set(TerminatingRuleId, 10), TargetedUris=make_set(CleanUri, 10)
    by WebAclId, HttpSourceName, HostHeader=coalesce(iff(isnotempty(HostHeader), HostHeader, ""), "UnknownHost"), ClientIp, Country, Ja3Fingerprint
| where BlockedReqs >= 10 and (Allowed2xx3xx > 0 or CountModeMatches > 0)
| order by Allowed2xx3xx desc, BlockedReqs desc
| take 5000

Explanation

This query is designed to identify potentially suspicious activity by examining web traffic data. It focuses on finding attacker IP addresses that have triggered a significant number of Web Application Firewall (WAF) blocks (10 or more) and have also managed to receive HTTP 2xx or 3xx responses, which indicate successful or redirected requests, on the same host. Here's a simplified breakdown of what the query does:

  1. Time Frame and Filters: It starts by setting a time range and applying various filters based on organization, account, region, environment, workload, severity, source table, and selected principal or IP.

  2. Data Collection: It gathers data from AWS WAF logs, focusing on specific fields like time, web ACL ID, HTTP source name, headers, URI, action taken, response code, matching rules, terminating rule ID, client IP, country, and JA3 fingerprint.

  3. Header Analysis: It extracts the "host" header from the HTTP request headers.

  4. URI Cleaning: It cleans up the URI by removing query parameters for easier analysis.

  5. Summarization: It summarizes the data by counting the total requests, blocked requests, allowed 2xx/3xx responses, and requests that matched certain rules. It also collects unique terminating rule IDs and targeted URIs.

  6. Filtering: It filters the results to only include IPs that have 10 or more blocked requests and at least one allowed 2xx/3xx response or a match with non-terminating rules.

  7. Ordering and Limiting: It orders the results by the number of allowed 2xx/3xx responses and blocked requests, and limits the output to the top 5000 entries.

The goal is to identify IP addresses that might be attempting to bypass security measures by triggering multiple blocks while still managing to get some requests through successfully. This information can be used for further investigation into potential security threats.