Full Report
S3 buckets are file storage on AWS. AWS eats its own dogfood a lot, meaning that many of the AWS services will use S3 under the hood. In Cloud Formation (infrastructure as a service), an S3 bucket was created that was per region when CF was turned on in the region. This was a contains all of the user defined templates. S3 is a global AWS service, unlike most things at Amazon. So, there is a classic vulnerability called bucket sniping. This is all about registering the bucket before someone else does, then having access to it once the service starts using it. By creating the bucket in account B, when account A setup CF in that region, account A would use the user controlled bucket. To make this viable, the public must be made public and have a very generous resource policy that allows account A access. At this point, the template can be modified to add resources in the account! The authors mention a TOCTOU issue on Cloud Formation from previous research to add in the resource but not strictly needed. To exploit this, do the following: Claim the bucket with the predictable name of the victim. Create a lambda function to execute upon bucket access from the victims account. This Wait for them to start using CF in that region. In the lambda function, modify the CF template that was written before execution. Run the backdoor templated file. This will create an admin role controlled by the attacker that can be assumed by them, giving them admin access to the account. To do this, the executor of the CF template must have IAM permissions. The bucket has a random value associated with it. For whatever reason, they were unable to figure it out. Via OSINT on Github, it seems feasible to expose the hash. From there, they wanted to find other services vulnerable to the same issue. They found AWS Glue, EMR, SageMaker, CodeStar and Service Catalog vulnerable to the same attack. In terms of impact, sometimes it was RCE on the service itself or data manipulation. Many AWS services run with the execution of the user itself. Since this is the case and the bucket permissions are open, this exploit makes sense. However, I'm fairly confident this is a standard thing that AWS engineers should test for, making it surprising how many cases of this were found, especially in such big services. Overall, great post though!
Analysis Summary
# Vulnerability: AWS "Bucket Monopoly" Shadow Resource Squatting
## CVE Details
* **CVE ID:** N/A (AWS-specific service vulnerabilities typically do not receive standard CVE IDs; however, these are tracked as critical service-side flaws).
* **CVSS Score:** Estimated **9.0 - 9.9** (**Critical**)
* **CWE:** CWE-342: Predictable Exact Value / CWE-667: Improper Locking (Resource Squatting)
## Affected Systems
* **Products:**
* AWS CloudFormation
* AWS Glue
* AWS EMR (Elastic MapReduce)
* AWS SageMaker
* AWS Service Catalog
* AWS CodeStar (Deprecated)
* **Versions:** All versions prior to the February–June 2024 patch cycle.
* **Configurations:** Vulnerable when a user enables these services in a new AWS region for the first time, where the service relies on an S3 bucket with a predictable naming convention.
## Vulnerability Description
The flaw resides in the "Shadow Resource" creation process. Several AWS services automatically create S3 buckets to store templates, assets, or scripts when a service is initialized in a specific region. Because S3 bucket names are globally unique across all AWS accounts and followed a predictable pattern (e.g., `cf-templates-{hash}-{region}`), an attacker could "squat" or "snip" these names by creating the buckets in their own account (Account B) before the victim (Account A) initialized the service in that region.
When the victim eventually activates the service, the service defaults to using the attacker’s bucket. If the attacker applies a permissive resource policy, the victim's service will unknowingly read/write to the attacker's bucket.
## Exploitation
* **Status:** PoC available (Demonstrated by Aqua Security researchers at Black Hat USA/DEF CON 32).
* **Complexity:** Medium (Requires OSINT to identify the hash used in the predictable naming convention).
* **Attack Vector:** Network (Cross-account S3 interaction).
### Attack Steps:
1. **Predict:** Use OSINT (e.g., GitHub leaks) to find the account-specific hash used in the bucket name.
2. **Claim:** Register the bucket name in the attacker’s account across all unused AWS regions.
3. **Monitor:** Set up a Lambda function triggered by `s3:PutObject` to detect when a victim starts using the service.
4. **Inject:** Use a Time-of-Check to Time-of-Use (TOCTOU) race condition or direct modification to replace legitimate CloudFormation templates/Glue scripts with malicious versions.
5. **Escalate:** The injected code executes with the victim's service role permissions, often resulting in Administrative IAM access or RCE.
## Impact
* **Confidentiality:** **Total** (Attacker can exfiltrate data processed by Glue, SageMaker, or EMR).
* **Integrity:** **Total** (Attacker can modify CloudFormation templates to create admin backdoors).
* **Availability:** **High** (Attacker can delete templates or cause service failures/DoS).
## Remediation
### Patches
* AWS has implemented service-side fixes for the six mentioned services. They now verify bucket ownership before use or use randomized naming conventions that are not predictable.
* **CloudFormation/EMR:** Fixed March 16, 2024.
* **Glue/SageMaker:** Fixed March 25, 2024.
* **ServiceCatalog:** Fixed June 26, 2024.
### Workarounds
* **Verify Ownership:** Use the `--expected-bucket-owner` flag in AWS CLI when interacting with buckets programmatically to ensure the bucket belongs to your Account ID.
* **Pre-emptive Claiming:** Manually create required service buckets in all supported regions before the service does, ensuring you retain ownership.
## Detection
* **Indicators of Compromise:** Check S3 bucket permissions for unknown cross-account Resource Policies. Review CloudTrail logs for `CreateBucket` failures or `PutObject` calls originating from or directed to unrecognized accounts.
* **Verification Command:**
`aws s3api get-bucket-acl --bucket [bucket-name] --expected-bucket-owner [Your-Account-ID]`
*If this returns "Access Denied," you do not own the bucket despite the service attempting to use it.*
## References
* Aqua Security Research: hxxps[://]www[.]aquasec[.]com/blog/aws-bucket-monopoly-vulnerability/
* AWS Security Bulletins: (Users are advised to check their AWS Health Dashboard for direct notifications).