AWS SecOps P0-06b - GuardDuty Correlated with CloudTrail Mutations, VPC Egress and Entra Bridge
P0 06b Guardduty Multitable Correlated
Query
// REVIEW ONLY. Validate AWSGuardDuty, AWSCloudTrail, and AWSVPCFlow schemas first via D02-D04.
let IdentityMap = _GetWatchlist('AWS_EntraIdentityMap')
| where tolower(tostring(column_ifexists("Verified", ""))) == "true" and isnotempty(tostring(column_ifexists("MappingEvidence", "")))
| project AwsAccessKeyId=tostring(column_ifexists("AwsAccessKeyId", "")), AWSAccountId=tostring(column_ifexists("AWSAccountId", "")),
EntraTenantId=tolower(tostring(column_ifexists("EntraTenantId", ""))), EntraObjectId=tolower(tostring(column_ifexists("EntraObjectId", ""))),
EntraUPN=tostring(column_ifexists("EntraUPN", ""));
let Findings = AWSGuardDuty
| where TimeGenerated > ago(1h)
| summarize arg_max(TimeGenerated, *) by Id
| where ingestion_time() > ago(15m)
| where tobool(ServiceDetails.archived) != true and Severity >= 7
| extend ActionBlock = ServiceDetails.action,
AwsAccessKeyId = tostring(ResourceDetails.accessKeyDetails.accessKeyId),
PrincipalName = tostring(ResourceDetails.accessKeyDetails.userName),
InstanceId = tostring(ResourceDetails.instanceDetails.instanceId)
| extend RemoteIpAddress = coalesce(
tostring(ActionBlock.awsApiCallAction.remoteIpDetails.ipAddressV4),
tostring(ActionBlock.networkConnectionAction.remoteIpDetails.ipAddressV4), "")
| project FindingTime=TimeGenerated, FindingId=Id, AWSAccountId=AccountId, AWSRegion=Region,
Severity, ActivityType, Title, AwsAccessKeyId, PrincipalName, InstanceId, RemoteIpAddress;
let RecentMutations = AWSCloudTrail
| where TimeGenerated > ago(2h) and ReadOnly == false and isempty(ErrorCode)
| summarize ControlPlaneChanges=make_set(EventName, 20), MutationCount=count()
by AWSAccountId=RecipientAccountId, AwsAccessKeyId=UserIdentityAccessKeyId;
let InstanceFlows = AWSVPCFlow
| where TimeGenerated > ago(2h) and Action == "ACCEPT" and isnotempty(InstanceId)
| summarize VpcAcceptedBytes=sum(Bytes), DistinctRemotePeers=dcount(DstAddr)
by AWSAccountId=AccountId, InstanceId;
Findings
| join kind=leftouter RecentMutations on AWSAccountId, AwsAccessKeyId
| join kind=leftouter InstanceFlows on AWSAccountId, InstanceId
| join kind=leftouter IdentityMap on AWSAccountId, AwsAccessKeyId
| where coalesce(MutationCount, 0) > 0 or coalesce(VpcAcceptedBytes, 0) > 10485760 or isnotempty(EntraObjectId)
| extend ControlPlaneSummary = tostring(coalesce(ControlPlaneChanges, dynamic([]))),
VpcBytesStr = tostring(coalesce(VpcAcceptedBytes, 0))
| project TimeGenerated=FindingTime, FindingId, AWSAccountId, AWSRegion, Severity, ActivityType,
Title, PrincipalName, AwsAccessKeyId, InstanceId, RemoteIpAddress, MutationCount=coalesce(MutationCount, 0),
ControlPlaneSummary, VpcBytesStr, EntraTenantId=coalesce(EntraTenantId, ""),
EntraObjectId=coalesce(EntraObjectId, ""), EntraUPN=coalesce(EntraUPN, "")Explanation
This query is a scheduled rule designed to identify and correlate security events in AWS environments. Here's a simplified breakdown:
-
Purpose: The rule aims to detect and enrich high or critical security findings from AWS GuardDuty by correlating them with specific activities in AWS CloudTrail and AWS VPC Flow logs, as well as verifying identity context through Entra identity mapping.
-
Data Sources: It uses data from AWS GuardDuty, AWS CloudTrail, and AWS VPC Flow logs, all accessed via an AWS S3 connector.
-
Frequency and Period: The query runs every 15 minutes and looks back over the past 2 hours of data.
-
Severity and Tactics: The rule is classified as high severity and is associated with tactics like Initial Access, Privilege Escalation, Collection, and Exfiltration, which are common in cybersecurity threat models.
-
Process:
- Identity Mapping: It first checks a watchlist for verified Entra identity mappings.
- Findings: It retrieves recent high-severity findings from AWS GuardDuty that are not archived.
- Mutations: It looks for recent non-read-only changes in AWS CloudTrail logs.
- VPC Flows: It examines VPC Flow logs for significant data transfers from EC2 instances.
- Correlation: It correlates these findings with identity mappings, CloudTrail mutations, and VPC data transfers.
-
Conditions for Alerts: An alert is generated if there are any significant CloudTrail mutations, large data transfers (over 10 MB), or verified identity contexts.
-
Output: The query outputs a set of fields including time, finding ID, AWS account and region, severity, activity type, and identity details.
-
Incident Management: If a match is found, an incident is created, and related events are grouped together for easier management. The system can reopen closed incidents if new related events are detected within a 7-day window.
-
Version and Configuration: The rule is version 1.0.0 and is configured to create incidents based on the results.
Overall, this rule helps security teams monitor and respond to potential security threats by correlating various AWS logs and identity data to detect suspicious activities.