Query Details

36 Ueba Behaviors Ueba Aws Network Layer

Query

// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: UebaBehaviors | Panel: ueba-aws-network-layer | Visualization: table | Mode: All
// Security Question: Did AWS CloudTrail UEBA detect anomalous VPC, Security Group, NACL, Gateway, Route, Peering, or Flow Log tampering behaviors?
// Drill-Through: Click Actor to export SelectedPrincipal and pivot into Tab 3 (Identity), Tab 5 (Network), or Tab 10 (Entra/XDR Pivot).
// Empty/No-Data Contract: No AWS UEBA Network-Layer behaviors or mutating EC2/VPC network control-plane events observed 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}");
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 UebaNetBehaviors = union isfuzzy=true
    (datatable(TimeGenerated:datetime, BehaviorId:string, ActionType:string, Title:string, Categories:string, AttackTechniques:string, DataSources:string, Description:string, Insights:string, AdditionalFields:string, AccountUpn:string, AccountObjectId:string)[]),
    (SentinelBehaviorInfo | where TimeGenerated between (Start .. End)
     | project TimeGenerated, BehaviorId, ActionType, Title, Categories, AttackTechniques, DataSources, Description, Insights, AdditionalFields, AccountUpn, AccountObjectId),
    (BehaviorInfo | where TimeGenerated between (Start .. End) and ServiceSource == "Microsoft Sentinel"
     | project TimeGenerated, BehaviorId, ActionType, Title=tostring(column_ifexists("Title", ActionType)), Categories, AttackTechniques, DataSources, Description, Insights=tostring(column_ifexists("Insights", "")), AdditionalFields, AccountUpn, AccountObjectId)
| where DataSources has_any ("AWS", "CloudTrail", "Amazon") or AdditionalFields has "AWSCloudTrail"
| where ActionType in (NetworkBehaviorActions)
    or Title has_any ("VPC", "Security Group", "Network ACL", "Transit Gateway", "Internet Gateway", "Route Table", "Flow Logs", "Network Interface", "Peering", "Traffic Mirroring", "Endpoint")
| extend Enrich = parse_json(AdditionalFields)["ueba.enrichments"]
| extend AnomalyFlags = strcat_delim(",",
    iff(Insights has "FirstSeen", "FirstSeen", ""),
    iff(Insights has "HighVolumeAnomaly", "HighVolumeAnomaly", ""),
    iff(Insights has "UncommonValue", "UncommonValue", ""),
    iff(Insights has "ThreatIntel" or isnotempty(tostring(Enrich.ThreatIntelIndicatorType)), "ThreatIntelMatch", ""))
| project TimeGenerated, SourceLayer="🧠 UEBA Behaviors Layer (SentinelBehaviorInfo)",
    NetworkBehavior=coalesce(iff(isnotempty(Title), Title, ""), ActionType),
    ActionOrApi=ActionType, Actor=coalesce(iff(isnotempty(AccountUpn), AccountUpn, ""), AccountObjectId, "See BehaviorEntities"),
    AWSAccountOrScope="AWSCloudTrail", SourceIpOrIsp=strcat(tostring(Enrich.IPLocation), " ", tostring(Enrich.ISP)),
    MitreMapping=strcat(Categories, " | ", AttackTechniques),
    AnomalyInsights=iff(isnotempty(AnomalyFlags), strcat("🔴 ", AnomalyFlags), "🟢 Neutral Behavior Summary"),
    Summary=Description;
let RawCloudTrailNetFallback = union isfuzzy=true
    (datatable(TimeGenerated:datetime, EventSource:string, EventName:string, RecipientAccountId:string, AWSRegion:string, UserIdentityArn:string, SourceIpAddress:string, ErrorCode:string)[]),
    (AWSCloudTrail | where TimeGenerated between (Start .. End)
     | project TimeGenerated, EventSource, EventName, RecipientAccountId, AWSRegion, UserIdentityArn, SourceIpAddress, ErrorCode)
| where (AccountFilter == "*" or RecipientAccountId == AccountFilter) and EventSource == "ec2.amazonaws.com"
| where EventName in (
    "DeleteFlowLogs", "AuthorizeSecurityGroupIngress", "AuthorizeSecurityGroupEgress", "RevokeSecurityGroupIngress", "RevokeSecurityGroupEgress",
    "CreateNetworkAclEntry", "ReplaceNetworkAclEntry", "CreateInternetGateway", "AttachInternetGateway", "DetachInternetGateway",
    "AcceptVpcPeeringConnection", "CreateVpcPeeringConnection", "ModifyVpcPeeringConnectionOptions",
    "CreateTransitGatewayRoute", "ReplaceTransitGatewayRoute", "CreateRoute", "ReplaceRoute", "DeleteRouteTable",
    "CreateVpcEndpoint", "ModifyVpcEndpoint", "ModifyVpcEndpointServicePermissions", "AttachNetworkInterface",
    "CreateTrafficMirrorSession", "DeleteTrafficMirrorSession")
| summarize LastTime=max(TimeGenerated), Calls=count(), Denied=countif(isnotempty(ErrorCode)), Regions=make_set(AWSRegion, 10)
    by RecipientAccountId, EventName, UserIdentityArn, SourceIpAddress
| extend NetUseCase = case(
    EventName == "DeleteFlowLogs" or EventName has "TrafficMirror", "🔴 Defense Evasion: Flow Log / Traffic Mirror Tampering",
    EventName has "SecurityGroup" or EventName has "NetworkAcl", "🟠 Firewall / Perimeter Rule Modification",
    EventName has "Peering" or EventName == "AttachNetworkInterface", "🟠 Lateral Movement / Cross-VPC Connectivity",
    EventName has "Gateway" or EventName has "Route", "🟡 VPC Routing & Internet/TGW Egress Path Change",
    "🟡 VPC Endpoint / Private Connectivity Modification")
| project TimeGenerated=LastTime, SourceLayer="📡 AWSCloudTrail Network Control-Plane (Live Fallback)",
    NetworkBehavior=NetUseCase, ActionOrApi=EventName, Actor=UserIdentityArn,
    AWSAccountOrScope=RecipientAccountId, SourceIpOrIsp=SourceIpAddress,
    MitreMapping=iff(EventName == "DeleteFlowLogs", "Defense Evasion | T1562.008", "Cloud Network Control Plane | T1578"),
    AnomalyInsights=iff(Denied > 0, strcat("🟠 Calls=", Calls, " Denied=", Denied), strcat("🔵 Calls=", Calls, " Denied=0")),
    Summary=strcat("Regions=", tostring(Regions));
union UebaNetBehaviors, RawCloudTrailNetFallback
| order by SourceLayer desc, TimeGenerated desc
| take 5000

Explanation

This query is designed to analyze AWS CloudTrail logs and detect any unusual or potentially malicious activities related to AWS network components such as VPCs, Security Groups, NACLs, Gateways, Routes, Peering connections, and Flow Logs. Here's a simplified breakdown of what the query does:

  1. Time and Filters Setup: It sets up time range filters and decodes various filters like organization, account, region, environment, workload, severity, source, and selected principal or IP from base64 encoded strings.

  2. Network Behavior Actions: It defines a list of specific network behavior actions that are considered suspicious or noteworthy.

  3. UEBA Network Behaviors: It gathers data from different sources (like SentinelBehaviorInfo and BehaviorInfo) within the specified time range, focusing on AWS-related activities. It filters for actions and titles related to network components and extends the data with additional information like anomaly flags and insights.

  4. Raw CloudTrail Fallback: It also collects raw AWS CloudTrail events related to network control-plane activities (like modifying security groups, creating routes, etc.) and summarizes them by account, event name, and other attributes. It categorizes these events based on their potential security implications.

  5. Union and Output: The query combines the UEBA network behaviors and raw CloudTrail data, orders them by source layer and time, and limits the output to the most recent 5000 entries.

The overall goal is to identify and summarize any anomalous or suspicious network-related activities in AWS environments, providing insights into potential security threats.