You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Rule Tuning][New Rule] AWS S3 Bucket Policy Added to Share with External Account/ to Allow Public Access
AWS S3 Bucket Policy Added to Share with External Account
Low telemetry volume overall, however false positives were seen for cloudfront identity and service accounts being given access to a bucket
- Reduced the scope of this rule to only analyze policy that include account ids or account ARNs (which include an account ID). This eliminates the false positives triggered by sharing buckets with a service account (i.e. cloudtrail.amazonaws.com)
- Excluded cloudfront identity, which should be treated the same way service accounts are being treated and be excluded as they do not include account IDs in their ARN
- This rule wasn't explicitly capturing the use of `Principal: *` which is a public sharing method, often accompanied by a Condition statement (i.e. aws.SourceAccount = OR aws.PrincipalAccount= OR ip.address = ....). The new query will capture Condition statements that include an account id. However there is still a gap for Policies that have explicit `Principal:*` with or without a condition, so another rule was created that will account for these scenarios.
- added highlighted fields
- updated investigation guide and description
- updated Mitre tactics and tags
- `event.type` used in place of `event.category` field
### AWS S3 Bucket Policy Added to Allow Public Access
Rule added to cover gap in public bucket policy added which includes an `Effect=Allow` and `Principal: *`. While an additional condition might be added to this policy which would exclude public access, cases where the condition is not included mean the bucket is publicly accessible. Both cases need to be verified, because even the condition could be giving access to an attacker owned account. There is also the chance that an `Effect=Deny` for `Principal:*` will trigger a false positive for this rule if the same policy also includes an `Effect=Allow` statement. We call this out in the description, false positive and investigation guide sections of the rule.
Identifies an AWS S3 bucket policy change to share permissions with an external account. Adversaries may attempt to
11
-
backdoor an S3 bucket by sharing it with an external account. This can be used to exfiltrate data or to provide access
12
-
to other adversaries. This rule identifies changes to a bucket policy via the `PutBucketPolicy` API call where the
13
-
policy includes an `Effect=Allow` statement that does not contain the AWS account ID of the bucket owner.
10
+
Detects when an Amazon S3 bucket policy is modified to share access with an external AWS account. This rule analyzes
11
+
PutBucketPolicy events and compares the S3 bucket’s account ID to any account IDs referenced in the policy’s
12
+
Effect=Allow statements. If the policy includes principals from accounts other than the bucket owner’s, the rule
13
+
triggers an alert. This behavior may indicate an adversary backdooring a bucket for data exfiltration or cross-account
14
+
persistence. For example, an attacker who compromises credentials could attach a policy allowing access from an external
15
+
AWS account they control, enabling continued access even after credentials are rotated. Note: This rule will not alert
16
+
if the account ID is part of the bucket’s name or appears in the resource ARN. Such cases are common in standardized
17
+
naming conventions (e.g., “mybucket-123456789012”). To ensure full coverage, use complementary rules to monitor for
18
+
suspicious PutBucketPolicy API requests targeting buckets with account IDs embedded in their names or resources.
14
19
"""
20
+
event_category_override = "event.type"
15
21
false_positives = [
16
22
"""
17
-
Legitimate changes to share an S3 bucket with an external account may be identified as false positive but are not
18
-
best practice.
23
+
Legitimate changes to share an S3 bucket with an external account may be identified as false positives.
19
24
""",
20
25
]
21
26
index = ["filebeat-*", "logs-aws.cloudtrail-*"]
22
27
language = "eql"
23
28
license = "Elastic License v2"
24
29
name = "AWS S3 Bucket Policy Added to Share with External Account"
25
-
note = """
26
-
## Triage and analysis
30
+
note = """## Triage and analysis
27
31
28
-
### Investigating AWS S3 Bucket Policy Added to Share with External Account
29
-
30
-
This rule detects when an AWS S3 bucket policy is changed to share permissions with an external account. Adversaries may attempt to backdoor an S3 bucket by sharing it with an external account to exfiltrate data or provide access to other adversaries. This rule identifies changes to a bucket policy via the `PutBucketPolicy` API call where the policy includes an `Effect=Allow` statement that does not contain the AWS account ID of the bucket owner.
31
-
32
-
#### Possible Investigation Steps:
33
-
34
-
- **Identify the Actor**: Review the `aws.cloudtrail.user_identity.arn` and `aws.cloudtrail.user_identity.access_key_id` fields to identify who made the change. Verify if this actor typically performs such actions and if they have the necessary permissions.
35
-
- **Review the Request Details**: Examine the `aws.cloudtrail.request_parameters` to understand the specific changes made to the bucket policy. Look for any unusual parameters that could suggest unauthorized or malicious modifications.
36
-
- **Analyze the Source of the Request**: Investigate the `source.ip` and `source.geo` fields to determine the geographical origin of the request. An external or unexpected location might indicate compromised credentials or unauthorized access.
37
-
- **Contextualize with Timestamp**: Use the `@timestamp` field to check when the change occurred. Modifications during non-business hours or outside regular maintenance windows might require further scrutiny.
38
-
- **Correlate with Other Activities**: Search for related CloudTrail events before and after this change to see if the same actor or IP address engaged in other potentially suspicious activities.
39
-
40
-
### False Positive Analysis:
32
+
> **Disclaimer**:
33
+
> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
41
34
42
-
- **Legitimate Administrative Actions**: Confirm if the bucket policy change aligns with scheduled updates, development activities, or legitimate administrative tasks documented in change management systems.
43
-
- **Consistency Check**: Compare the action against historical data of similar actions performed by the user or within the organization. If the action is consistent with past legitimate activities, it might indicate a false alarm.
44
-
- **Verify through Outcomes**: Check the `aws.cloudtrail.response_elements` and the `event.outcome` to confirm if the change was successful and intended according to policy.
45
-
46
-
### Response and Remediation:
47
-
48
-
- **Immediate Review and Reversal if Necessary**: If the change was unauthorized, update the bucket policy to remove any unauthorized permissions and restore it to its previous state.
49
-
- **Enhance Monitoring and Alerts**: Adjust monitoring systems to alert on similar actions, especially those involving sensitive data or permissions.
50
-
- **Educate and Train**: Provide additional training to users with administrative rights on the importance of security best practices concerning bucket policy management and sharing permissions.
51
-
- **Audit Bucket Policies and Permissions**: Conduct a comprehensive audit of all bucket policies and associated permissions to ensure they adhere to the principle of least privilege.
52
-
- **Incident Response**: If there's an indication of malicious intent or a security breach, initiate the incident response protocol to mitigate any damage and prevent future occurrences.
53
-
54
-
### Additional Information:
35
+
### Investigating AWS S3 Bucket Policy Added to Share with External Account
55
36
56
-
For further guidance on managing S3 bucket policies and securing AWS environments, refer to the [AWS S3 documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-cloudtrail-logging-for-s3.html) and AWS best practices for security.
37
+
This rule detects when an S3 bucket policy is modified using the `PutBucketPolicy` API call to include an external AWS account ID.
38
+
It compares the bucket’s `recipient_account_id` to any account IDs included in the policy’s `Effect=Allow` statement, triggering
39
+
an alert if the two do not match.
40
+
41
+
Adversaries may exploit this to backdoor a bucket and exfiltrate sensitive data by granting permissions to another AWS account
42
+
they control, enabling ongoing access to the bucket’s contents even if IAM credentials are rotated or revoked.
43
+
44
+
This detection specifically focuses on policy-based sharing and does not alert when:
45
+
- The account ID appears within the bucket or object name being shared.
46
+
- The account owner explicitly matches the policy’s condition keys on something other than an ARN or account id (i.e. IP address).
47
+
48
+
To fully monitor for suspicious sharing behavior, use this rule in combination with detections for:
- Review `aws.cloudtrail.user_identity.arn` and `aws.cloudtrail.user_identity.access_key_id` to identify who made the change.
57
+
- Determine if the identity typically manages S3 bucket policies.
58
+
- Examine `aws.cloudtrail.resources.arn` to determine which bucket is being shared.
59
+
60
+
- **Analyze the Policy Change**
61
+
- Review `aws.cloudtrail.request_parameters` to extract the policy JSON and identify the external AWS account ID(s) referenced.
62
+
- Check for `Effect=Allow` statements granting broad permissions such as `"Action": "s3:*"` or `"Resource": "*"`.
63
+
- Verify if the added principals correspond to known partners or external vendors.
64
+
- If AWS account ID(s) were only part of `Effect=Deny` statements, then this rule can be closed as a false positive.
65
+
66
+
- **Review Context and Source**
67
+
- Check `source.ip`, `source.geo`, and `user_agent.original` for anomalies — such as new IP ranges, access from unfamiliar geographies, or use of programmatic clients (`boto3`, `aws-cli`).
68
+
69
+
- **Correlate with Related Activity**
70
+
- Search CloudTrail for subsequent activity by the external AWS account ID(s):
71
+
- `GetObject`, `ListBucket`, or `PutObject` events that indicate data access or exfiltration.
72
+
- Look for additional configuration changes by the same actor, such as:
73
+
- `PutBucketAcl`, `PutBucketVersioning`, or `PutBucketReplication` — often part of a larger bucket compromise chain.
74
+
- Determine if multiple buckets were modified in quick succession.
75
+
76
+
- **Validate Intent**
77
+
- Review internal change requests or documentation to confirm whether this external sharing was approved.
78
+
- If no approval exists, escalate immediately for potential compromise.
79
+
80
+
### False positive analysis
81
+
82
+
- **Authorized Cross-Account Access**
83
+
- Some organizations legitimately share S3 buckets across accounts within a trusted AWS Organization or partner accounts.
84
+
- Validate whether the external account ID belongs to a known entity or service provider and is documented in your allowlist.
85
+
- **Automation or Deployment Pipelines**
86
+
- Continuous integration/deployment pipelines may temporarily attach cross-account policies for replication or staging.
87
+
- Verify the `user_agent.original` or role name — automation often includes identifiable strings.
88
+
- **Naming and Rule Logic Limitations**
89
+
- This rule excludes detections where the account ID appears in the bucket resource ARN (e.g., `mybucket-123456789012`).
90
+
- Such patterns are common in automated provisioning. For those scenarios, rely on complementary rules that directly monitor `PutBucketPolicy` events against those buckets.
91
+
92
+
### Response and remediation
93
+
94
+
- **Immediate Review and Containment**
95
+
- If unauthorized sharing is confirmed, use the AWS CLI or Console to delete or revert the modified policy (`aws s3api delete-bucket-policy` or restore from version control).
96
+
- Remove external principals and reapply the correct bucket policy.
97
+
- Rotate access keys for the actor involved, especially if API access came from unexpected locations or tools.
98
+
99
+
- **Investigation and Scoping**
100
+
- Identify whether data was accessed by the external account via `GetObject` or `ListBucket` operations.
101
+
- Search CloudTrail logs for other buckets modified by the same actor or IP within the same timeframe.
102
+
- Use AWS Config to review version history of affected bucket policies and detect similar cross-account permissions.
103
+
104
+
- **Recovery and Hardening**
105
+
- Restrict `s3:PutBucketPolicy` to a limited set of administrative roles using least privilege.
106
+
- Enable AWS Config rule `s3-bucket-policy-grantee-check` to monitor for unauthorized policy additions.
107
+
- Use AWS GuardDuty or Security Hub findings to correlate policy changes with data exfiltration or credential compromise events.
108
+
- Apply service control policies (SCPs) to block cross-account sharing unless explicitly approved.
109
+
110
+
### Additional information
111
+
- **[AWS IR Playbooks](https://github.com/aws-samples/aws-incident-response-playbooks/blob/c151b0dc091755fffd4d662a8f29e2f6794da52c/playbooks/)**
- **Security Best Practices:** [AWS Knowledge Center – Security Best Practices](https://aws.amazon.com/premiumsupport/knowledge-center/security-best-practices/).
S3 data event types must be collected in the AWS CloudTrail logs. Please refer to [AWS documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-cloudtrail-logging-for-s3.html) for more information.
68
-
"""
69
121
severity = "medium"
70
122
tags = [
71
123
"Domain: Cloud",
@@ -74,17 +126,25 @@ tags = [
74
126
"Data Source: AWS S3",
75
127
"Use Case: Threat Detection",
76
128
"Tactic: Exfiltration",
129
+
"Tactic: Collection",
77
130
"Resources: Investigation Guide",
78
131
]
79
132
timestamp_override = "event.ingested"
80
133
type = "eql"
81
134
82
135
query = '''
83
-
any where event.dataset == "aws.cloudtrail"
136
+
info where event.dataset == "aws.cloudtrail"
84
137
and event.provider == "s3.amazonaws.com"
85
-
and event.action == "PutBucketPolicy" and event.outcome == "success"
138
+
and event.action == "PutBucketPolicy"
86
139
and stringContains(aws.cloudtrail.request_parameters, "Effect=Allow")
87
-
and not stringContains(aws.cloudtrail.request_parameters, aws.cloudtrail.recipient_account_id)
140
+
and (
141
+
stringContains(aws.cloudtrail.request_parameters, "AWS=") or
142
+
stringContains(aws.cloudtrail.request_parameters, "aws:PrincipalAccount=") or
0 commit comments