AWS SecOps P2-01b - AWS Network Firewall Correlated with VPC Flow, GuardDuty and IAM Changes
P2 01b Network Firewall Vpc Guardduty Iam Correlated
Query
// REVIEW ONLY. Validate AWSNetworkFirewallAlert, AWSVPCFlow, AWSGuardDuty, AWSCloudTrail via D01-D08.
let CriticalAssets = _GetWatchlist('AWS_CriticalAssets')
| where tolower(tostring(column_ifexists("Verified", ""))) == "true"
| project AssetAccountId=tostring(column_ifexists("AWSAccountId", "")), ResourceKey=tolower(tostring(column_ifexists("ResourceIdOrName", ""))),
AssetCriticality=tostring(column_ifexists("Criticality", ""));
let NetFwAlerts = AWSNetworkFirewallAlert
| where TimeGenerated > ago(1h) and ingestion_time() > ago(15m)
| extend InternalIp = iff(ipv4_is_private(SrcIp), SrcIp, iff(ipv4_is_private(DestIp), DestIp, "")),
ExternalIp = iff(ipv4_is_private(SrcIp) == false, SrcIp, iff(ipv4_is_private(DestIp) == false, DestIp, ""))
| where isnotempty(InternalIp)
| summarize AlertTime=min(TimeGenerated), FwHits=count(), Signatures=make_set(Signature, 10),
SignatureIds=make_set(SignatureId, 10), Verdicts=make_set(VerdictAction, 5), SampleSni=take_any(Sni)
by FirewallName, AvailabilityZone, InternalIp, ExternalIp, DestPort, Proto;
let VpcContext = AWSVPCFlow
| where TimeGenerated > ago(2h) and LogStatus == "OK"
| extend OrigSrc = iff(isnotempty(PktSrcAddr), PktSrcAddr, SrcAddr)
| where ipv4_is_private(OrigSrc)
| summarize VpcBytes=sum(Bytes), AWSAccountId=take_any(AccountId), VpcId=take_any(VpcId),
InstanceId=take_any(InstanceId), InterfaceId=take_any(InterfaceId)
by InternalIp=OrigSrc;
let GdIpFindings = AWSGuardDuty
| where TimeGenerated > ago(2h)
| summarize arg_max(TimeGenerated, *) by Id
| extend InstanceId = tostring(ResourceDetails.instanceDetails.instanceId)
| where isnotempty(InstanceId)
| summarize GdTypes=make_set(ActivityType, 10) by AWSAccountId=AccountId, InstanceId;
let NetOrIamChanges = AWSCloudTrail
| where TimeGenerated > ago(2h) and ReadOnly == false and isempty(ErrorCode)
| where EventSource in ("ec2.amazonaws.com", "network-firewall.amazonaws.com", "iam.amazonaws.com")
| summarize ControlChanges=make_set(EventName, 10) by AWSAccountId=RecipientAccountId;
NetFwAlerts
| join kind=inner VpcContext on InternalIp
| extend InstanceKey = tolower(InstanceId)
| join kind=leftouter CriticalAssets on $left.AWSAccountId == $right.AssetAccountId and $left.InstanceKey == $right.ResourceKey
| join kind=leftouter GdIpFindings on AWSAccountId, InstanceId
| join kind=leftouter NetOrIamChanges on AWSAccountId
| where array_length(GdTypes) > 0 or array_length(ControlChanges) > 0 or AssetCriticality in~ ("Critical", "High") or VpcBytes >= 20971520
| extend SignatureSummary = tostring(Signatures),
GdSummary = tostring(coalesce(GdTypes, dynamic([]))),
ControlChangeSummary = tostring(coalesce(ControlChanges, dynamic([]))),
VpcBytesStr = tostring(VpcBytes)
| project TimeGenerated=AlertTime, AWSAccountId, VpcId, InstanceId, InterfaceId,
AssetCriticality=coalesce(AssetCriticality, "Standard"), FirewallName,
SourceIpAddress=InternalIp, DestinationIpAddress=ExternalIp, DestPort, Proto,
SignatureSummary, SampleSni, VpcBytesStr, GdSummary, ControlChangeSummaryExplanation
This query is designed to enhance security monitoring by correlating data from multiple AWS sources to identify potential security threats. Here's a simplified breakdown:
-
Purpose: The query aims to detect and prioritize potential security incidents by correlating alerts from AWS Network Firewall with data from VPC Flow Logs, GuardDuty findings, and recent IAM or network changes recorded in CloudTrail.
-
Data Sources: It uses data from AWS Network Firewall alerts, VPC Flow Logs, GuardDuty, and CloudTrail logs.
-
Frequency and Duration: The query runs every 15 minutes and looks back over the past 2 hours of data.
-
Severity and Tactics: The severity is marked as "High," focusing on tactics like Command and Control, Lateral Movement, and Exfiltration.
-
Process:
- Critical Assets: Identifies critical assets from a watchlist to prioritize them.
- Network Firewall Alerts: Filters recent alerts to identify internal and external IPs involved in suspicious activities.
- VPC Context: Gathers context about the network traffic, such as bytes transferred and associated AWS resources.
- GuardDuty Findings: Checks for any GuardDuty findings related to the instances.
- IAM/Network Changes: Looks for recent changes in IAM or network configurations that might indicate suspicious activity.
-
Correlation: The query joins data from these sources to identify incidents where:
- There are GuardDuty findings or recent IAM/network changes.
- The asset is critical or has high data transfer volumes.
-
Output: It generates a summary of the incident, including details like IP addresses, AWS account, instance ID, firewall name, and summaries of signatures, GuardDuty findings, and control changes.
-
Incident Management: If a potential threat is identified, it creates an incident and groups related alerts to manage them effectively.
This query helps security teams quickly identify and respond to potential threats by providing a comprehensive view of suspicious activities across multiple AWS services.