AWS SecOps P0-07a - S3 PublicAccessBlock Weakening and Sensitive Bucket Burst Read (Single-Source)
P0 07a S3 Publicblock And Anomalous Read Baseline
Query
// REVIEW ONLY. Verify S3 data events (ManagementEvent == false) via discovery/D02 first.
// High-volume alternative: point BurstReads at AWS_S3DataAccess_5m_CL (summary-rules/S01).
let SensitiveBuckets = _GetWatchlist('AWS_SensitiveBuckets')
| where tolower(tostring(column_ifexists("Verified", ""))) == "true"
| project SbAccountId=tostring(column_ifexists("AWSAccountId", "")), BucketNameLower=tolower(tostring(column_ifexists("BucketName", ""))),
DataClassification=tostring(column_ifexists("DataClassification", "")), ExpectedReaders=tostring(column_ifexists("ExpectedReaderArnsJson", "")),
MaxObjectsPer15m=toint(column_ifexists("MaxObjectsPer15m", "")), AllowedRegions=tostring(column_ifexists("AllowedRegionsJson", ""));
let ExposureWeakening = AWSCloudTrail
| where TimeGenerated > ago(1h) and ingestion_time() > ago(15m)
| where EventSource == "s3.amazonaws.com" and isempty(ErrorCode) and isempty(ErrorMessage)
| where EventName in ("DeletePublicAccessBlock", "PutBucketPublicAccessBlock", "PutBucketPolicy")
| extend Req = parse_json(RequestParameters), ReqText = tostring(RequestParameters)
| extend BucketName = tostring(Req.bucketName),
AWSAccountId = coalesce(RecipientAccountId, UserIdentityAccountId)
| extend IsBlockDisabled = (EventName == "DeletePublicAccessBlock"
or (EventName == "PutBucketPublicAccessBlock" and ReqText matches regex @"(?i)(BlockPublicAcls|IgnorePublicAcls|BlockPublicPolicy|RestrictPublicBuckets)""\s*:\s*false")),
ExternalAccountArn = extract(@"arn:aws[a-z-]*:iam::([0-9]{12}):", 1, tostring(Req.bucketPolicy))
| extend IsExternalAccountPolicy = (EventName == "PutBucketPolicy" and isnotempty(ExternalAccountArn) and ExternalAccountArn != AWSAccountId)
| where IsBlockDisabled or IsExternalAccountPolicy
| project TimeGenerated, AwsEventId, AWSAccountId, AWSRegion, BucketName, UserIdentityArn,
SourceIpAddress, UserAgent, DetectionTrigger=iff(IsBlockDisabled, "PublicAccessBlockWeakened", strcat("CrossAccountPolicyTo:", ExternalAccountArn)),
DistinctObjects=0, DataClassification="ControlPlaneExposure";
let BurstReads = AWSCloudTrail
| where TimeGenerated > ago(30m) and ingestion_time() > ago(15m)
| where EventSource == "s3.amazonaws.com" and EventName in ("GetObject", "CopyObject")
| where isempty(ErrorCode) and isempty(ErrorMessage)
| where UserIdentityAccountId !~ "ANONYMOUS_PRINCIPAL" and UserIdentityPrincipalid != "Anonymous"
| extend Req = parse_json(RequestParameters)
| extend BucketName = tostring(Req.bucketName), ObjectKey = tostring(Req.key),
AWSAccountId = coalesce(RecipientAccountId, UserIdentityAccountId)
| extend BucketNameLower = tolower(BucketName)
| join kind=inner SensitiveBuckets on $left.AWSAccountId == $right.SbAccountId and BucketNameLower
| where not(ExpectedReaders has UserIdentityArn)
| summarize TimeGenerated=min(TimeGenerated), AwsEventId=take_any(AwsEventId),
DistinctObjects=dcount(ObjectKey), SamplePrefixes=make_set(tostring(split(ObjectKey, "/")[0]), 10)
by bin(TimeGenerated, 15m), AWSAccountId, AWSRegion, BucketName, UserIdentityArn,
SourceIpAddress, UserAgent, DataClassification, MaxObjectsPer15m, AllowedRegions
| where DistinctObjects >= coalesce(MaxObjectsPer15m, 100) or (isnotempty(AllowedRegions) and not(AllowedRegions has AWSRegion))
| project TimeGenerated, AwsEventId, AWSAccountId, AWSRegion, BucketName, UserIdentityArn,
SourceIpAddress, UserAgent, DetectionTrigger=strcat("AuthenticatedSensitiveBucketBurst(Prefixes=", tostring(SamplePrefixes), ")"),
DistinctObjects, DataClassification;
union ExposureWeakening, BurstReads
| extend AccountName = tostring(split(UserIdentityArn, "/")[-1]),
DistinctObjectsStr = tostring(DistinctObjects)
| project TimeGenerated, AwsEventId, AWSAccountId, AWSRegion, BucketName, AccountName,
UserIdentityArn, SourceIpAddress, UserAgent, DetectionTrigger, DistinctObjectsStr, DataClassificationExplanation
This query is designed to monitor and detect potential security issues related to Amazon S3 buckets in AWS, specifically focusing on two main scenarios:
-
Public Access Block Weakening: The query checks for any changes that might weaken the security settings of S3 buckets. This includes actions like deleting or modifying the public access block settings, or adding bucket policies that allow access to external AWS accounts. Such actions can make the bucket more vulnerable to unauthorized access.
-
Sensitive Bucket Burst Reads: The query also monitors for unusual read activity on sensitive S3 buckets. It looks for bursts of read operations (like
GetObjectorCopyObject) that exceed a predefined threshold within a 15-minute window. It flags these activities if they come from unapproved users or regions, indicating potential data exfiltration attempts.
The query requires that S3 data events are enabled to track these activities effectively. It uses a watchlist of sensitive buckets to focus on high-risk areas and generates alerts if any suspicious activities are detected. The results are then used to create incidents for further investigation, grouping related events to streamline the analysis process.