Created
September 17, 2025 06:28
-
-
Save ajdumanhug/6af4a8f12e1f650e9ea0d2d97b548609 to your computer and use it in GitHub Desktop.
This bash script checks which AWS S3 buckets are publicly accessible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if an argument (file path) is provided | |
if [ $# -ne 1 ]; then | |
echo "Usage: bash $0 /path/to/buckets.txt" | |
exit 1 | |
fi | |
BUCKET_FILE="$1" | |
# Check if the file exists | |
if [ ! -f "$BUCKET_FILE" ]; then | |
echo "Error: File '$BUCKET_FILE' not found!" | |
exit 1 | |
fi | |
# Loop through each bucket in the file | |
while IFS= read -r bucket_name; do | |
if [ -z "$bucket_name" ]; then | |
continue # Skip empty lines | |
fi | |
echo "Checking bucket: $bucket_name" | |
# Run AWS CLI command and capture both stdout and stderr | |
output=$(aws --no-sign-request s3api list-objects-v2 --bucket "$bucket_name" 2>&1) | |
# Determine response type | |
if [[ "$output" == \{* ]]; then | |
echo "✅ Accessible: $bucket_name" | |
elif echo "$output" | grep -q "AccessDenied"; then | |
echo "⛔ Access Denied: $bucket_name" | |
elif echo "$output" | grep -q "NoSuchBucket"; then | |
echo "❌ No Such Bucket: $bucket_name" | |
else | |
echo "⚠️ Unknown Error: $bucket_name" | |
echo " Message: $output" | |
fi | |
done < "$BUCKET_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment