Query Details

27 Web Edge Cloudfront Edge Anomalies

Query

// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: WebEdge | Panel: cloudfront-edge-anomalies | Visualization: table | Mode: All
// Security Question: Is CloudFront connected, and are signed URLs/cookies being abused or origin paths enumerated?
// Drill-Through: Validate AWSCloudFront_AccessLog_CL schema via discovery/D08 if CloudFront logs are stored in S3.
// Empty/No-Data Contract: AWSCloudFront_AccessLog_CL is not connected in this workspace or zero edge anomalies matched thresholds.
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(HostHeader:string, ClientIp:string, Requests:long, Error4xx5xx:long, DistinctUris:long, SignedRequests:long, SampleUa:string)[]),
    (AWSCloudFront_AccessLog_CL
     | where TimeGenerated between (Start .. End)
     | extend ClientIp = tostring(column_ifexists("c_ip_s", "")),
         HostHeader = tostring(column_ifexists("cs_host_s", "")),
         UriStem = tostring(column_ifexists("cs_uri_stem_s", "")),
         UriQuery = tostring(column_ifexists("cs_uri_query_s", "")),
         StatusCode = toint(column_ifexists("sc_status_d", 0)),
         UserAgent = tostring(column_ifexists("cs_user_agent_s", ""))
     | summarize Requests=count(), Error4xx5xx=countif(StatusCode >= 400), DistinctUris=dcount(UriStem),
         SignedRequests=countif(UriQuery has "Key-Pair-Id="), SampleUa=take_any(UserAgent)
         by HostHeader, ClientIp
     | where Error4xx5xx >= 40 or SignedRequests >= 20 or SampleUa matches regex @"(?i)(artex-enrich/|norma/|sqlmap|nuclei|ffuf)"
     | project HostHeader, ClientIp, Requests, Error4xx5xx, DistinctUris, SignedRequests, SampleUa)
| order by Error4xx5xx desc
| take 5000

Explanation

This query is designed to analyze AWS CloudFront logs to identify potential security anomalies related to CloudFront usage. Here's a simplified breakdown of what the query does:

  1. Time Range and Filters: It sets a time range (Start to End) and decodes several filters (like organization, account, region, environment, workload, severity, source, summary mode, selected principal, and IP) from base64 strings. These filters are likely used to narrow down the data to specific contexts or criteria.

  2. Data Source: The query checks if there are any CloudFront logs (AWSCloudFront_AccessLog_CL) available in the specified workspace.

  3. Data Processing:

    • It extracts relevant fields from the logs, such as ClientIp, HostHeader, UriStem, UriQuery, StatusCode, and UserAgent.
    • It summarizes the data by counting the total requests, the number of requests resulting in 4xx or 5xx errors, distinct URIs accessed, and requests with signed URLs (identified by the presence of "Key-Pair-Id=" in the query string).
    • It also captures a sample user agent string (SampleUa).
  4. Anomaly Detection:

    • The query filters for potential anomalies by looking for:
      • At least 40 requests resulting in 4xx or 5xx errors.
      • At least 20 requests with signed URLs.
      • User agents that match certain patterns indicative of known tools or scripts (e.g., "artex-enrich/", "norma/", "sqlmap", "nuclei", "ffuf").
  5. Output:

    • The results are ordered by the number of 4xx/5xx errors in descending order.
    • It limits the output to the top 5000 entries.

In summary, this query helps identify unusual or potentially malicious activity in CloudFront logs, such as abuse of signed URLs or enumeration of origin paths, by analyzing request patterns and user agent strings.