Full Report
Bucket Snipping is a class of AWS integration vulnerabilities that stems from S3 buckets being globally scoped. The idea is to possess readable and writable access to an S3 bucket used by another account then use this control to perform malicious things in the account. The AWS Cloud Development Kit (CDK) is a framework for infrastructure as code. This allows using programming languages like Python to translate into configurations in AWS. CDK has a one time initialization step called bootstrap. This one time command creates the necessary roles for CloudFormation and CDK in the account, an S3 bucket and other resources. The bucket named can be changed but has a default format of cdk-{qualifier}-assets-{account-ID}-{Region}. The qualifier has a default value of hnb659fds, the region is guessable and the account Id is the only somewhat secret value but may be learned through other means. Because the bucket is somewhat predictable and S3 is global, it can be registered ahead of time. They call this out as a DoS which to me is BS - this is like saying that me frontrunning the creation of a domain is a DoS! You can literally just change the name slightly and it's fine. Sometimes, resources get deleted from AWS accounts, especially with quota limits. If this happens, another user can create the S3 bucket because it's global. By default, the CloudFormationExecuteRole used by CDK has admin privileges to the account, making the ability to overwrite a template very, very bad. Does this work? Yes it does! The attack assumes that the user has CDK initialized in their account, deleted the S3 bucket and has a predictable qualifier: Attacker recreates the deleted S3 bucket in the account using the predictable name. On this bucket, the attacker sets a permissive resource-level policy. On the S3 bucket, configure a Lambda function to inject the malicious admin role into any CloudFormation template that gets loaded. There are hooks for S3 bucket operations that make this possible. User runs cdk deploy in their account. Upon triggering the build, the template gets written to the attackers S3 bucket, which gets backdoored. Since the template has been updated, it will deploy the resources that the attacker specifies. What does an attacker do with this? They crate a Backdoor IAM role that can be assumed by an account that they control! At this point, they have admin rights in the account. How likely is this to happen though? This is where I find the article interesting! First, they checked if a particular IAM account existed using a known technique which is surprising to me that it works. They created a scanner that looked for the existence of the S3 bucket name for 38,000 known accounts. If the role existed but the S3 bucket didn't, the attack was on! From the 38K accounts analyzed, 2% of them used CDK. Of these accounts, 10% of the accounts were found to be vulnerable to this attack vector. According to AWS, about 1% of CDK users were affected by this issue. An account takeover in AWS from simply deleting a bucket is pretty bad news! To remediate the vulnerability, newer versions of CDK ensure bucket ownership by the account. Additionally, AWS added some docs to not use the default qualifier. Since previously bootstrapped users are still potentially vulnerable to this attack, AWS added messages in the CLI terminal with a big error message that this still affected them. Overall, a good writeup on a classic AWS bucket snipping vulnerability. It amazes me that these are still being found in AWS products after all of these years.
Analysis Summary
# Vulnerability: AWS CDK S3 Bucket Snipping / Account Takeover
## CVE Details
- **CVE ID**: Not explicitly assigned in the provided text (often referred to as the "AWS CDK Bucket Snipping" vulnerability).
- **CVSS Score**: Not provided (however, the impact is characterized as **Critical/High** due to full account takeover).
- **CWE**: CWE-94: Improper Control of Generation of Code ('Code Injection') / CWE-284: Improper Access Control.
## Affected Systems
- **Products**: AWS Cloud Development Kit (CDK).
- **Versions**: CDK version **v2.148.1 and earlier**.
- **Configurations**:
- Environments that have been "bootstrapped" using the default configuration.
- Accounts where the default bootstrapped S3 bucket has been deleted (due to manual intervention or quota management).
- Usage of the default qualifier (`hnb659fds`).
## Vulnerability Description
This is a "Bucket Snipping" flaw stemming from the predictable naming convention of S3 buckets used by the AWS CDK for deployment assets. The default naming format is `cdk-{qualifier}-assets-{account-ID}-{Region}`.
Because S3 bucket names are globally unique across all AWS accounts, an attacker who knows a target's Account ID, Region, and Qualifier can pre-emptively create (or "snip") that bucket if it does not currently exist. When a user runs `cdk deploy`, the `FilePublishingRole` attempts to upload CloudFormation templates to this bucket. If an attacker controls the bucket, they can use S3 event triggers (e.g., Lambda) to intercept and inject malicious resources—such as a backdoor IAM admin role—into the CloudFormation template before it is executed by the `CloudFormationExecuteRole`, which typically has administrative privileges.
## Exploitation
- **Status**: PoC available / Research-validated (Approximately 1% of all CDK users were found to be vulnerable).
- **Complexity**: Medium (Requires knowledge of the target Account ID).
- **Attack Vector**: Network (Cloud-based resource pre-emption).
## Impact
- **Confidentiality**: Total (Full administrative access to the AWS account).
- **Integrity**: Total (Ability to modify any infrastructure via backdoored CloudFormation templates).
- **Availability**: High (Ability to delete all resources in the account).
## Remediation
### Patches
- **Upgrade to AWS CDK v2.149.0 or later**: The updated version includes a condition in the `FilePublishingRole` that ensures it only trusts buckets residing within the user’s own account.
### Workarounds
- **Re-bootstrap**: Run `cdk bootstrap` again after upgrading the CLI to update the IAM roles and S3 bucket policies.
- **Custom Qualifiers**: Use a unique, non-default qualifier during the bootstrap process to make the bucket name unpredictable.
- **Bucket Ownership**: Ensure the S3 bucket exists and is owned by your account.
## Detection
- **Indicators of Compromise**:
- Presence of an S3 bucket in the account's naming format that is *not* owned by the local account.
- Unexpected IAM roles or modified CloudFormation templates in deployment history.
- **Detection Tools**:
- **cdk-bucket-takeover-scanner**: An open-source tool released to scan accounts for this specific risk.
- Check for CLI terminal warnings: AWS added specific error messages in the CDK CLI to alert users with vulnerable bootstrap stacks.
## References
- **Vendor Advisory**: [AWS Documentation: Troubleshooting Bootstrapping](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping-troubleshoot.html)
- **Original Research**: [Aqua Security Blog - AWS CDK Risk](https://www.aquasec[.]com/blog/aws-cdk-risk-exploiting-a-missing-s3-bucket-allowed-account-takeover/)
- **Fix Commit**: [AWS CDK GitHub - Ensure Bucket Account Ownership](https://github[.]com/aws/aws-cdk/commit/5ef3be5b5da8653614c75613337429c2a85b86fb)