Query Details

38 Ueba Behaviors Ueba Aws Anomalies Detected

Query

// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: UebaBehaviors | Panel: ueba-aws-anomalies-detected | Visualization: table | Mode: All
// Security Question: Which AWS identities triggered statistical or UEBA baseline anomalies across CloudTrail and GuardDuty?
// Drill-Through: Click Actor to populate SelectedPrincipal and correlate with deterministic alerts in Tab 10.
// Empty/No-Data Contract: No AWS anomalies fired in the Anomalies table during the selected 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, RuleStatus:string, Score:real, AnomalyTemplateName:string, RuleName:string, UserPrincipalName:string, UserName:string, SourceIpAddress:string, SourceLocation:dynamic, Tactics:string, Techniques:string, Description:string, AnomalyReasons:dynamic, AnomalyDetails:dynamic, Entities:dynamic)[]),
    (Anomalies | where TimeGenerated between (Start .. End)
     | project TimeGenerated, RuleStatus, Score=todouble(Score), AnomalyTemplateName, RuleName, UserPrincipalName, UserName, SourceIpAddress, SourceLocation=todynamic(SourceLocation), Tactics, Techniques, Description, AnomalyReasons=todynamic(AnomalyReasons), AnomalyDetails=todynamic(AnomalyDetails), Entities=todynamic(Entities))
| where AnomalyTemplateName has_any ("AwsCloudTrail", "AWS", "GuardDuty")
    or RuleName has_any ("AwsCloudTrail", "AWS", "GuardDuty")
    or Description has_any ("AWS CloudTrail", "AWS GuardDuty", "AWS Security Token Service", "AWS Secrets Manager")
| extend AwsAnomalyDomain = case(
    AnomalyTemplateName has "GuardDuty" or RuleName has "GuardDuty", "🔴 AWS GuardDuty UEBA Anomaly",
    AnomalyTemplateName has "AssumeRole", "🟠 AWS STS AssumeRole UEBA Anomaly",
    AnomalyTemplateName has "Secret" or AnomalyTemplateName has "KMS", "🔴 AWS Secrets/KMS UEBA Anomaly",
    AnomalyTemplateName has "Privilege" or AnomalyTemplateName has "IAM", "🔴 AWS IAM Privilege UEBA Anomaly",
    AnomalyTemplateName has "Federated" or AnomalyTemplateName has "SAML", "🟠 AWS Federated/SAML UEBA Anomaly",
    AnomalyTemplateName has "Logon", "🟠 AWS ConsoleLogin UEBA Anomaly",
    "🟡 AWS 21-Day ML Volume Anomaly"),
    Actor = coalesce(iff(isnotempty(UserPrincipalName), UserPrincipalName, ""), UserName)
| project TimeGenerated, AwsAnomalyDomain, RuleStatus, Score=round(Score, 2),
    AnomalyName=coalesce(iff(isnotempty(AnomalyTemplateName), AnomalyTemplateName, ""), RuleName),
    Actor, SourceIpAddress, SourceLocation, Tactics, Techniques, Description, AnomalyReasons, Entities
| order by Score desc, TimeGenerated desc
| take 5000

Explanation

This query is designed to identify AWS identities that have triggered unusual or unexpected activities, known as anomalies, within AWS services like CloudTrail and GuardDuty. Here's a simplified breakdown of what the query does:

  1. Time and Filters Setup: It sets up a time range and various filters (like organization, account, region, environment, workload, severity, source, selected principal, and IP) to narrow down the data being analyzed.

  2. Data Union: It combines data from a predefined empty table and an "Anomalies" table, focusing on entries within the specified time range.

  3. Anomaly Filtering: It filters the data to include only those anomalies related to AWS services like CloudTrail and GuardDuty, or those described as such.

  4. Anomaly Categorization: It categorizes anomalies into specific domains (e.g., GuardDuty, AssumeRole, Secrets/KMS, IAM Privilege, Federated/SAML, ConsoleLogin) based on certain keywords in the anomaly template or rule name.

  5. Actor Identification: It identifies the AWS identity (Actor) responsible for the anomaly, using either the UserPrincipalName or UserName.

  6. Data Projection: It selects specific fields to include in the final output, such as the time of the anomaly, anomaly domain, rule status, score, anomaly name, actor, source IP address, source location, tactics, techniques, description, anomaly reasons, and entities involved.

  7. Sorting and Limiting: It sorts the results by the anomaly score (descending) and time generated (descending), and limits the output to the top 5000 entries.

  8. Output: The final result is a table that lists AWS identities and their associated anomalies, providing insights into potential security issues.

In essence, this query helps security teams identify and analyze unusual activities by AWS identities, aiding in the detection of potential security threats.