Query Details

33 Ueba All Aws Behaviors And Insights

Query

// REVIEW ONLY workbook query: 9.5 All AWS CloudTrail UEBA Behaviors & Explainable Anomaly Insights (`SentinelBehaviorInfo` + `Entities`)
let Start = {TimeRange:start};
let End = {TimeRange:end};
let AwsBehaviors = union isfuzzy=true
    (datatable(TimeGenerated:datetime, BehaviorId:string, Title:string, ActionType:string, Categories:string, AttackTechniques:string, DataSources:string, Description:string, Insights:string, AdditionalFields:string, AccountUpn:string)[]),
    (SentinelBehaviorInfo | where TimeGenerated between (Start .. End)
     | project TimeGenerated, BehaviorId, Title, ActionType, Categories, AttackTechniques, DataSources, Description, Insights, AdditionalFields, AccountUpn),
    (BehaviorInfo | where TimeGenerated between (Start .. End) and ServiceSource == "Microsoft Sentinel"
     | project TimeGenerated, BehaviorId, Title=tostring(column_ifexists("Title", ActionType)), ActionType, Categories, AttackTechniques, DataSources, Description, Insights=tostring(column_ifexists("Insights", "")), AdditionalFields, AccountUpn)
| where DataSources has_any ("AWS", "CloudTrail", "Amazon") or AdditionalFields has "AWSCloudTrail";
let AwsEntities = union isfuzzy=true
    (datatable(BehaviorId:string, EntityType:string, EntityRole:string, CloudPlatform:string, CloudResource:string, CloudResourceType:string, CloudSubscriptionId:string, AccountName:string, RemoteIP:string)[]),
    (SentinelBehaviorEntities | where TimeGenerated between (Start .. End)
     | project BehaviorId, EntityType, EntityRole, CloudPlatform, CloudResource, CloudResourceType, CloudSubscriptionId, AccountName, RemoteIP),
    (BehaviorEntities | where TimeGenerated between (Start .. End) and ServiceSource == "Microsoft Sentinel"
     | project BehaviorId, EntityType, EntityRole, CloudPlatform="Amazon Web Services", CloudResource="", CloudResourceType="", CloudSubscriptionId="", AccountName, RemoteIP)
| summarize InvolvedEntities=make_set_if(strcat(EntityType, ":", coalesce(iff(isnotempty(CloudResource), CloudResource, ""), iff(isnotempty(AccountName), AccountName, ""), RemoteIP)), isnotempty(EntityType), 10),
    AwsAccountIds=make_set_if(CloudSubscriptionId, isnotempty(CloudSubscriptionId), 5),
    RemoteIps=make_set_if(RemoteIP, isnotempty(RemoteIP), 5)
    by BehaviorId;
AwsBehaviors
| join kind=leftouter AwsEntities on BehaviorId
| extend Enrich = parse_json(AdditionalFields)["ueba.enrichments"]
| extend ServiceLayer = case(
    ActionType has_any ("Vpc", "Gateway", "Route", "Network", "Mirror", "Subnet", "Peering", "FlowLogs", "RuleChange", "RemoteAccess"), "EC2 / VPC Network Layer",
    ActionType has_any ("S3", "StorageLens", "ObjectLock"), "Amazon S3 Storage Layer",
    ActionType has_any ("Secret", "Kms"), "Secrets Manager & KMS Layer",
    ActionType has "EKS", "Amazon EKS Container Layer",
    "AWS IAM, STS & Compute Layer"),
    ExplainabilityBadges = strcat_delim(",",
        iff(Insights has "FirstSeen", "FirstSeen", ""),
        iff(Insights has "HighVolumeAnomaly", "HighVolumeAnomaly", ""),
        iff(Insights has "UncommonValue", "UncommonValue", ""),
        iff(Insights has "ThreatIntel", "ThreatIntel", ""))
| project TimeGenerated, ServiceLayer, Title, ActionType, ExplainabilityBadges,
    Categories, AttackTechniques, AccountUpn, AwsAccountIds, RemoteIps,
    IPLocation=tostring(Enrich.IPLocation), ISP=tostring(Enrich.ISP),
    ThreatIntelType=tostring(Enrich.ThreatIntelIndicatorType),
    InvolvedEntities, Description, BehaviorId
| order by isnotempty(ExplainabilityBadges) desc, TimeGenerated desc
| take 5000

Explanation

This query is designed to analyze and summarize AWS CloudTrail user and entity behavior analytics (UEBA) data, focusing on identifying and explaining anomalies. Here's a simplified breakdown of what the query does:

  1. Time Range Setup: It defines a time range (Start and End) for the data to be analyzed.

  2. Data Collection:

    • It gathers behavior data from two sources: SentinelBehaviorInfo and BehaviorInfo, filtering for events related to AWS services (like CloudTrail).
    • It also collects related entity data from SentinelBehaviorEntities and BehaviorEntities, focusing on AWS-related entities.
  3. Data Filtering:

    • The query filters the behavior data to include only those with data sources or additional fields related to AWS, CloudTrail, or Amazon.
  4. Entity Summarization:

    • It summarizes the entities involved in each behavior, capturing details like entity types, cloud resources, account names, and remote IPs.
  5. Data Enrichment:

    • It enriches the behavior data with additional information, such as service layers (e.g., network, storage, secrets management) and explainability badges (e.g., first seen, high volume anomaly).
  6. Output Preparation:

    • The query prepares the final output by projecting relevant fields, such as time generated, service layer, action type, and explainability badges.
    • It orders the results by the presence of explainability badges and time, showing the most recent and significant anomalies first.
  7. Result Limitation:

    • Finally, it limits the output to the top 5000 records for performance and manageability.

In essence, this query is used to identify and explain unusual behaviors in AWS CloudTrail logs, providing insights into potential security threats or anomalies within a specified time frame.