P0 05 Cloudtrail Selector Delivery Evasion
Query
// Standalone KQL for Analytic Rule: AWS SecOps P0-05 - CloudTrail Selector Downgrade and Logging Delivery Tampering
// Rule File: analytics/P0-05-cloudtrail-selector-delivery-evasion.yaml | Rule ID: REPLACE_WITH_RULE_GUID | Severity: High
// Schedule: 15m / Lookback: 1h | REVIEW ONLY - Do not deploy/schedule without approval.
// REVIEW ONLY. Validate AWSCloudTrail schema first via discovery/D02-awscloudtrail-schema-and-dataevents-check.kql
let ProtectedLogging = _GetWatchlist('AWS_ProtectedLoggingAssets')
| where tolower(tostring(column_ifexists("Verified", ""))) == "true"
| project LogAccountId=tostring(column_ifexists("AWSAccountId", "")), AssetIdentifier=tolower(tostring(column_ifexists("AssetIdentifier", ""))),
TrailOrPipelineName=tostring(column_ifexists("TrailOrPipelineName", ""));
AWSCloudTrail
| where TimeGenerated > ago(1h)
| where isempty(ErrorCode) and isempty(ErrorMessage) and isnotempty(AwsEventId)
| where EventSource in ("cloudtrail.amazonaws.com", "s3.amazonaws.com", "kms.amazonaws.com")
| where EventName in (
"PutEventSelectors", "PutInsightSelectors", "DeleteEventDataStore", "StopImport",
"UpdateEventDataStore", "PutBucketPolicy", "DeleteBucketPolicy", "PutBucketLifecycleConfiguration",
"DisableKey", "ScheduleKeyDeletion", "PutKeyPolicy")
| extend Req = parse_json(RequestParameters),
AWSAccountId = coalesce(RecipientAccountId, UserIdentityAccountId)
| extend TargetAsset = tolower(coalesce(
tostring(Req.trailName), tostring(Req.eventDataStore), tostring(Req.bucketName), tostring(Req.keyId), "")),
ReqText = tostring(RequestParameters)
| join kind=leftouter ProtectedLogging on $left.AWSAccountId == $right.LogAccountId and $left.TargetAsset == $right.AssetIdentifier
| extend TamperMode = case(
EventName == "PutEventSelectors" and (ReqText has "\"IncludeManagementEvents\":false" or ReqText has "\"ReadWriteType\":\"WriteOnly\"" or ReqText has "\"DataResources\":[]" or ReqText has "\"AdvancedEventSelectors\":[]"),
"CloudTrailSelectorCoverageReduction",
EventName in ("DeleteEventDataStore", "StopImport"),
"CloudTrailLakeDataStoreHalted",
EventName == "UpdateEventDataStore" and ReqText has "\"TerminationProtectionEnabled\":false",
"CloudTrailLakeProtectionDisabled",
EventSource == "s3.amazonaws.com" and isnotempty(TrailOrPipelineName),
"ProtectedLoggingBucketTampered",
EventSource == "kms.amazonaws.com" and isnotempty(TrailOrPipelineName),
"ProtectedLoggingKmsKeyTampered",
"")
| where isnotempty(TamperMode)
| where ingestion_time() > ago(15m)
| extend AccountName = tostring(split(UserIdentityArn, "/")[-1]),
DynamicSeverity = "Critical",
RequestParamsSummary = tostring(RequestParameters)
| project TimeGenerated, AwsEventId, AWSAccountId, AWSRegion, AccountName, UserIdentityArn,
EventSource, EventName, TargetAsset, TrailOrPipelineName, TamperMode, SourceIpAddress,
UserAgent, RequestParamsSummary, DynamicSeverityExplanation
This KQL query is designed to detect potential tampering or unauthorized changes to AWS CloudTrail logging configurations and related assets. Here's a simplified breakdown of what the query does:
-
Watchlist Setup: It starts by referencing a watchlist called
AWS_ProtectedLoggingAssets, which contains information about protected logging assets. It filters this list to include only verified entries and extracts relevant details like the AWS account ID, asset identifier, and trail or pipeline name. -
CloudTrail Data Filtering: The query then looks at AWS CloudTrail logs from the past hour, focusing on events that have no errors and a valid event ID. It specifically targets events from services like CloudTrail, S3, and KMS.
-
Event Name Filtering: It filters for specific event names that could indicate changes to logging configurations or related assets, such as modifying event selectors, deleting data stores, or altering bucket policies.
-
Request Parsing: The query parses the request parameters to extract details about the target asset being affected and checks if these match any protected assets from the watchlist.
-
Tampering Detection: It identifies potential tampering modes based on the event name and request parameters. For example, it flags events that reduce CloudTrail selector coverage, halt data stores, disable protection, or tamper with protected logging buckets or KMS keys.
-
Recent Activity Check: It ensures that only events ingested in the last 15 minutes are considered, highlighting recent suspicious activities.
-
Result Projection: Finally, it projects a set of relevant details for each detected event, including the time, event ID, AWS account and region, user identity, event source and name, target asset, tampering mode, source IP, user agent, and a summary of request parameters. It also assigns a "Critical" severity level to these events.
This query is part of an analytic rule designed to monitor and alert on high-severity security incidents related to AWS CloudTrail logging configurations.