AWS Penetration Testing Part - 1: S3 Buckets: Techniques, Tools, and Exploits
π‘οΈ Pentesting AWS S3 Buckets: Techniques, Tools, and Exploits
Amazon S3 (Simple Storage Service) is a widely used storage service on AWS and one of the most exploited attack surfaces due to frequent misconfigurations. In this blog post, weβll explore how attackers find and exploit S3 vulnerabilities, how to test your own infrastructure, and what tools and techniques are used in real world scenarios.
π¦ Understanding S3 Permissions and Policies
S3 buckets use two permission models:
- Access Control Policies (ACPs): Simplified, often used via Web UI.
- IAM Access Policies: JSON based, granular control over permissions.
π§± Bucket vs Object Permissions
- Bucket permissions act as a "master key" users need access to the bucket before they can interact with its contents.
- Object permissions can then further restrict access at the file level.
π§° CLI Access to S3 Buckets
To interact with buckets via the AWS CLI:
π§ Setup
1sudo apt install awscli
2aws configureEnter your Access Key ID and Secret Key (from your AWS Console).
π Listing Contents
1aws s3 ls s3://bucket
2aws s3 ls s3://bucket/newπ€ Uploading Files
1aws s3 cp abc.txt s3://bucket/new/abc.txtποΈ Deleting Files
1aws s3 rm s3://bucket/new/abc.txtπ Access Control Lists (ACLs)
ACLs provide fine grained permissions
- read β View objects and metadata
- write β Upload and delete
- read-acp β View ACLs
- write-acp β Modify ACLs
Each grantee (user or group) can have up to 20 ACL rules per object.
Note: IAM users are not considered grantees.
π Bucket & IAM Policies
Policies define who can access what, using JSON:
π§Ύ Sample Bucket Policy
1{
2"Version": "2008-02-27",
3"Statement": [{
4 "Effect": "Allow",
5 "Principal": {
6 "AWS": "arn:aws:iam::Account-ID:user/username"
7 },
8 "Action": ["s3:GetBucketLocation", "s3:ListBucket", "s3:GetObject"],
9 "Resource": ["arn:aws:s3:::bucket"]
10}]
11}Use bucket policies for broader control, and IAM policies when assigning access to specific users across multiple buckets.
π΅οΈ Enumerating and Dumping S3 Buckets with AWSBucketDump
π Installing AWSBucketDump
1git clone https://github.com/jordanpotti/AWSBucketDump
2cd AWSBucketDump
3pip install -r requirements.txtπ Configure Wordlist
Add organization specific prefixes
1vim BucketNames.txt
2:%s/^/<prefix>-/g
3:wqπ§ͺ Run AWSBucketDump
1touch found.txt
2python AWSBucketDump.py -D -l BucketNames.txt -g interesting_Keywords.txtThis tool brute forces S3 bucket names and searches for sensitive files using a keyword list.
β οΈ JavaScript Injection in S3 Buckets
If a web app loads JS from a publicly writeable S3 bucket, an attacker can replace legitimate files.
π£ Demo Attack
1// vulnscript.js
2alert("XSS");Upload malicious script
1aws s3 cp vulnscript.js s3://bucket/vulnscript.js --acl public-readWhen a user loads the site, the script runs as if itβs part of the application.
𧬠Backdooring with Unclaimed S3 Buckets
Sometimes, apps request files from non existent S3 buckets, especially when subdomains point to deleted buckets via CNAME.
π Exploit Steps:
- Detect 404 pages with
NoSuchBucket - Register the missing bucket in the same region
- Upload malware to the new bucket
- Victims visiting the site get served the attackerβs content
π Case Study: Persistent Access via Installer Hijack
If an app downloads files from an S3 bucket and executes them:
- An attacker hijacking the bucket can upload
.tgzor script files - These get executed on the userβs machine
- Example: HackerOne Report #399166
π§ Summary
- S3 permission models and policy structures
- Uploading/downloading via AWS CLI
- Enumeration with AWSBucketDump
- Real world exploitation examples like JS injection and backdooring
π Defensive Best Practices
- Block public write access unless explicitly required
- Use S3 Block Public Access settings
- Review all IAM and bucket policies for least privilege
- Enable S3 Access Logging and monitor for suspicious uploads
- Use AWS Config to enforce compliance rules (e.g., βno public bucketsβ)