H15 Aws Ueba Behaviors Network And Anomalies Hunt
Query
// REVIEW ONLY - Do not deploy, run, or schedule automatically.
// Hunting H15: AWS CloudTrail UEBA Network-Layer Behaviors, GuardDuty/CloudTrail UEBA Priority & ML Anomalies
// Purpose: Correlates AWS CloudTrail UEBA Behaviors Layer (VPC/SG/NACL/IGW/TGW/Peering/Endpoint/FlowLog network layer + IAM/S3/EKS/Secrets),
// Classic UEBA (BehaviorAnalytics InvestigationPriority), and AWS CloudTrail/GuardDuty Anomalies (Anomalies table).
let Lookback = 7d;
let NetworkBehaviorActions = dynamic([
"BehaviorAwsVpnVpcEnumeration", "BehaviorBulkRouteTableReassignment", "BehaviorCloudCidrAllocation",
"BehaviorCloudIPAMEnumeration", "BehaviorCloudPermissionDiscovery", "BehaviorCloudTopologyEnumeration",
"BehaviorConcentratedRouteChanges", "BehaviorCrossAccountInterfaceAttach", "BehaviorEc2AclTerraformBurst",
"BehaviorEc2InterfacePermissionDiscovery", "BehaviorEc2NetworkEnumeration", "BehaviorEndpointCreationEnumeration",
"BehaviorEphemeralS3Endpoint", "BehaviorGatewayAttach", "BehaviorGatewayEnumerationBurst",
"BehaviorGatewayEnumerationModification", "BehaviorGatewayPropagationToggle", "BehaviorIaCSecurityGroupManagement",
"BehaviorIpv6PoolAssignment", "BehaviorMulticastGroupEnumeration", "BehaviorNetworkEnumerationBlocked",
"BehaviorNetworkInterfaceRapidReattach", "BehaviorNetworkVisibilityEnumeration", "BehaviorPrivateConnectivityEnumeration",
"BehaviorPrivateEndpointEnumeration", "BehaviorRapidNetworkInsightsDeletion", "BehaviorRapidRuleChange",
"BehaviorRemoteAccessExposure", "BehaviorRepeatedEC2PolicyUnauthorized", "BehaviorRepeatedFlowLogsDeletion",
"BehaviorRepeatedMirrorSessionFailures", "BehaviorRepeatedNetworkAnalysisAdmin", "BehaviorRepeatedNetworkInterfaceModificationFailures",
"BehaviorSubnetEIPReconfig", "BehaviorTransitGatewayConfigBurst", "BehaviorTransitGatewayEnumeration",
"BehaviorTransitGatewayRouteManipulation", "BehaviorTransitGatewayRouteModification", "BehaviorVPCDefaultRouteTableDeletion",
"BehaviorVPCPeeringDNSResolution", "BehaviorVpcBlockAccessEnumeration", "BehaviorVpcBulkDeletion",
"BehaviorVpcCidrReassignment", "BehaviorVpcEndpointAdminActivity", "BehaviorVpcEndpointPermissionChange",
"BehaviorVpcEndpointServiceCreation", "BehaviorVpcGatewayAttachment", "BehaviorVpcSubnetDeletion"
]);
let BehaviorsLayer = SentinelBehaviorInfo
| where TimeGenerated > ago(Lookback)
| where DataSources has_any ("AWS", "CloudTrail", "Amazon") or AdditionalFields has "AWSCloudTrail"
| extend Layer = iff(ActionType in (NetworkBehaviorActions) or Title has_any ("VPC", "Security Group", "Network ACL", "Transit Gateway", "Internet Gateway", "Route Table", "Flow Logs", "Network Interface", "Peering"),
"UEBA_Behaviors:AWS_NetworkLayer", "UEBA_Behaviors:AWS_ControlAndDataPlane"),
Enrich = parse_json(AdditionalFields)["ueba.enrichments"]
| project TimeGenerated, SignalFamily=Layer, SignalName=coalesce(Title, ActionType),
Actor=coalesce(AccountUpn, AccountObjectId), SourceIp="",
PriorityOrScore=iff(Insights has_any ("ThreatIntel", "HighVolumeAnomaly", "FirstSeen", "UncommonValue"), 8.0, 4.0),
MitreContext=strcat(Categories, " | ", AttackTechniques),
Explanation=strcat(Description, " | Insights=", Insights, " | ISP=", tostring(Enrich.ISP), " | TI=", tostring(Enrich.ThreatIntelIndicatorType));
let ClassicUeba = BehaviorAnalytics
| where TimeGenerated > ago(Lookback)
| where (NativeTableName in ("AWSCloudTrail", "AWSGuardDuty") or EventSource has_any ("AWS", "CloudTrail", "GuardDuty") or EventVendor has_any ("AWS", "Amazon"))
and InvestigationPriority >= 1
| project TimeGenerated, SignalFamily=strcat("Classic_UEBA:", coalesce(NativeTableName, EventSource)),
SignalName=coalesce(ActivityType, ActionType),
Actor=coalesce(UserPrincipalName, ActorPrincipalName, UserName, ActorName),
SourceIp=SourceIPAddress, PriorityOrScore=todouble(InvestigationPriority),
MitreContext=SourceIPLocation, Explanation=strcat("ActivityInsights=", tostring(ActivityInsights), " UsersInsights=", tostring(UsersInsights));
let AwsAnomalies = Anomalies
| where TimeGenerated > ago(Lookback)
| where AnomalyTemplateName has_any ("AwsCloudTrail", "AWS", "GuardDuty") or RuleName has_any ("AwsCloudTrail", "AWS", "GuardDuty")
| project TimeGenerated, SignalFamily=strcat("UEBA_ML_Anomaly:", RuleStatus),
SignalName=coalesce(AnomalyTemplateName, RuleName),
Actor=coalesce(UserPrincipalName, UserName), SourceIp=SourceIpAddress,
PriorityOrScore=Score, MitreContext=strcat(Tactics, " | ", Techniques),
Explanation=strcat(Description, " | Reasons=", tostring(AnomalyReasons));
union BehaviorsLayer, ClassicUeba, AwsAnomalies
| order by PriorityOrScore desc, TimeGenerated desc
| take 500Explanation
This query is designed for security analysis and monitoring in AWS environments. It focuses on identifying unusual or potentially malicious network behaviors and anomalies using AWS CloudTrail and GuardDuty data. Here's a simplified breakdown:
-
Purpose: The query aims to correlate different types of user and entity behavior analytics (UEBA) data, including network-layer behaviors, classic UEBA data, and machine learning-based anomalies, to identify potential security threats.
-
Lookback Period: The query examines data from the last 7 days.
-
Network Behavior Actions: A list of specific network-related actions that are considered unusual or noteworthy is defined. These actions include things like route changes, network interface modifications, and endpoint creations.
-
Data Sources:
- Behaviors Layer: This part of the query looks for network-layer behaviors in AWS CloudTrail logs. It identifies actions related to network components like VPCs, security groups, and gateways. It assigns a priority score based on certain insights and enriches the data with additional context.
- Classic UEBA: This section focuses on traditional UEBA data from AWS CloudTrail and GuardDuty. It filters events with a certain investigation priority and extracts relevant information like the actor, source IP, and priority score.
- AWS Anomalies: This part identifies anomalies detected by machine learning models in AWS CloudTrail and GuardDuty data. It captures details about the anomaly, including the actor, source IP, and reasons for the anomaly.
-
Data Union and Sorting: The query combines the results from the three data sources, sorts them by priority score and time, and limits the output to the top 500 entries.
Overall, this query helps security analysts detect and investigate potential security incidents by correlating different types of behavior and anomaly data in AWS environments.