30 S3data S3 Exposure And Policy Changes
Query
// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: S3Data | Panel: s3-exposure-and-policy-changes | Visualization: table | Mode: All
// Security Question: Were any S3 buckets weakened via PublicAccessBlock changes, ACLs, Replication, or bucket policies?
// Drill-Through: Click UserIdentityArn to set SelectedPrincipal and pivot into Tab 3 or Tab 10.
// Empty/No-Data Contract: No S3 permission, public-access-block, or replication mutations occurred 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 BucketCatalog = union isfuzzy=true
(datatable(SearchKey:string)[]),
(_GetWatchlist('AWS_SensitiveBuckets'))
| where isnotempty(tostring(column_ifexists("SearchKey", "")))
| where tolower(tostring(column_ifexists("Verified", ""))) == "true"
| project SbAccount=tostring(column_ifexists("AWSAccountId", "")),
BucketLower=tolower(tostring(column_ifexists("BucketName", ""))),
DataClassification=tostring(column_ifexists("DataClassification", "")),
Workload=tostring(column_ifexists("Workload", ""));
union isfuzzy=true
(datatable(TimeGenerated:datetime, EventSource:string, RecipientAccountId:string, AWSRegion:string, EventName:string, RequestParameters:string, UserIdentityArn:string, SourceIpAddress:string, ErrorCode:string)[]),
(AWSCloudTrail | where TimeGenerated between (Start .. End)
| project TimeGenerated, EventSource, RecipientAccountId, AWSRegion, EventName, RequestParameters, UserIdentityArn, SourceIpAddress, ErrorCode)
| where EventSource == "s3.amazonaws.com"
| where (AccountFilter == "*" or RecipientAccountId == AccountFilter) and (RegionFilter == "*" or AWSRegion == RegionFilter)
| where EventName in ("PutBucketPublicAccessBlock", "DeletePublicAccessBlock", "PutBucketPolicy", "DeleteBucketPolicy", "PutBucketAcl", "PutBucketReplication", "PutBucketLifecycleConfiguration")
| extend BucketName = tostring(parse_json(RequestParameters).bucketName)
| extend BucketLower = tolower(BucketName)
| join kind=leftouter BucketCatalog on $left.RecipientAccountId == $right.SbAccount and BucketLower
| project TimeGenerated, RecipientAccountId, AWSRegion, BucketName,
DataClassification=coalesce(iff(isnotempty(DataClassification), DataClassification, ""), "Unclassified"),
Workload=coalesce(iff(isnotempty(Workload), Workload, ""), "Unclassified"),
EventName, UserIdentityArn, SourceIpAddress, ErrorCode, RequestParameters
| order by TimeGenerated desc
| take 5000Explanation
This query is designed to monitor and report on changes to Amazon S3 bucket configurations that could potentially weaken security. Here's a simplified breakdown of what the query does:
-
Time Frame and Filters: It sets a time range and decodes several filters related to organization, account, region, environment, workload, severity, source, selected principal, and IP address. These filters help narrow down the data to specific criteria.
-
Bucket Catalog: It creates a catalog of sensitive S3 buckets by combining data from a watchlist and other sources. This catalog includes information like account ID, bucket name, data classification, and workload.
-
Event Data Collection: It collects event data from AWS CloudTrail within the specified time range. The focus is on events related to S3 bucket configurations, such as changes to public access blocks, bucket policies, ACLs, replication, and lifecycle configurations.
-
Filtering and Joining: The query filters events to include only those from the S3 service and further narrows them down based on account and region filters. It then checks for specific event types that indicate potential security changes.
-
Data Processing: It extracts the bucket name from the event data, converts it to lowercase for consistency, and joins this information with the bucket catalog to enrich the data with classification and workload information.
-
Output: The query projects relevant fields such as time generated, account ID, region, bucket name, data classification, workload, event name, user identity, source IP, error code, and request parameters. It orders the results by time and limits the output to the most recent 5000 records.
-
Purpose: The main goal is to identify any S3 buckets that might have been made less secure due to changes in public access settings, policies, or other configurations. If no such changes are detected within the specified time frame, it implies that no security-related mutations occurred.
This query is part of a security operations workbook and is used to visualize potential security risks associated with S3 bucket configurations.