31 S3data S3 Unusual Reads And Guardduty Exfil
Query
// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: S3Data | Panel: s3-unusual-reads-and-guardduty-exfil | Visualization: table | Mode: All
// Security Question: Which principals are reading high distinct-object counts or accessing S3 buckets across AWS accounts?
// Drill-Through: Uses AWS_S3DataAccess_5m_CL (summary-rules/S01) when available with automatic raw AWSCloudTrail fallback.
// Empty/No-Data Contract: Zero S3 GetObject/CopyObject bursts observed (verify CloudTrail S3 Data Events are enabled via discovery/D02).
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 BucketLower=tolower(tostring(column_ifexists("BucketName", ""))),
DataClassification=tostring(column_ifexists("DataClassification", "")),
MaxObjectsPer15m=toint(column_ifexists("MaxObjectsPer15m", ""));
let SummaryS3 = union isfuzzy=true
(datatable(WindowStart:datetime, EventName:string, RecipientAccountId:string, ActorAccountId:string, BucketName:string, AwsPrincipalArn:string, SourceIpAddress:string, SuccessEvents:long, DistinctObjects:long, DeniedEvents:long)[]),
(AWS_S3DataAccess_5m_CL | where WindowStart between (Start .. End)
| project WindowStart, EventName, RecipientAccountId, ActorAccountId, BucketName, AwsPrincipalArn, SourceIpAddress, SuccessEvents, DistinctObjects, DeniedEvents)
| where SummaryPref == "PreferSummary" and EventName in ("GetObject", "CopyObject") and (AccountFilter == "*" or RecipientAccountId == AccountFilter)
| summarize ObjectReads=sum(SuccessEvents), DistinctObjects=max(DistinctObjects), Denied=sum(DeniedEvents)
by RecipientAccountId, ActorAccountId, BucketName, AwsPrincipalArn, SourceIpAddress;
let HasS3Summary = toscalar(SummaryS3 | summarize count() > 0);
let RawS3 = union isfuzzy=true
(datatable(TimeGenerated:datetime, EventSource:string, EventName:string, RecipientAccountId:string, UserIdentityAccountId:string, UserIdentityArn:string, SourceIpAddress:string, RequestParameters:string, ErrorCode:string)[]),
(AWSCloudTrail | where TimeGenerated between (Start .. End)
| project TimeGenerated, EventSource, EventName, RecipientAccountId, UserIdentityAccountId, UserIdentityArn, SourceIpAddress, RequestParameters, ErrorCode)
| where (SummaryPref == "RawOnly" or not(HasS3Summary)) and EventSource == "s3.amazonaws.com" and EventName in ("GetObject", "CopyObject")
| where (AccountFilter == "*" or RecipientAccountId == AccountFilter)
| extend Req = parse_json(RequestParameters)
| extend BucketName = tostring(Req.bucketName), ObjectKey = tostring(Req.key)
| summarize ObjectReads=countif(isempty(ErrorCode)), DistinctObjects=dcountif(ObjectKey, isempty(ErrorCode)), Denied=countif(isnotempty(ErrorCode))
by RecipientAccountId, ActorAccountId=UserIdentityAccountId, BucketName, AwsPrincipalArn=UserIdentityArn, SourceIpAddress;
union SummaryS3, RawS3
| extend BucketLower = tolower(BucketName), IsCrossAccount = (ActorAccountId != RecipientAccountId and isnotempty(ActorAccountId))
| join kind=leftouter BucketCatalog on BucketLower
| where IsCrossAccount or DistinctObjects >= coalesce(MaxObjectsPer15m, 25) or Denied >= 20 or isnotempty(DataClassification)
| order by IsCrossAccount desc, DistinctObjects desc
| take 5000Explanation
This query is designed to identify and summarize unusual access patterns to Amazon S3 buckets, focusing on high-volume reads and potential data exfiltration activities. Here's a simplified breakdown of what the query does:
-
Time Frame and Filters: It starts by defining a time range and several filters (like organization, account, region, environment, workload, severity, source, principal, and IP) to narrow down the data being analyzed.
-
Bucket Catalog: It creates a list of sensitive buckets by checking a watchlist and filters them to include only verified entries. This helps in identifying if the accessed buckets are sensitive.
-
Summary Data: It attempts to use a summarized dataset (
AWS_S3DataAccess_5m_CL) to get information about S3 access events, focusing on "GetObject" and "CopyObject" actions. It summarizes the number of successful reads, distinct objects accessed, and denied events by account and principal. -
Raw Data Fallback: If the summary data is unavailable or if raw data is preferred, it falls back to using raw AWS CloudTrail logs to gather similar information.
-
Cross-Account and Anomalies: It checks if the access was cross-account (i.e., the actor account is different from the recipient account) and identifies anomalies such as high distinct object access, a high number of denied events, or access to sensitive data.
-
Output: The results are sorted to prioritize cross-account access and high distinct object counts, and the query limits the output to 5000 records.
In essence, this query helps security teams monitor and investigate unusual S3 access patterns, particularly those that might indicate data exfiltration or unauthorized access across AWS accounts.