Skip to content

Instantly share code, notes, and snippets.

@mauricioklein
Created August 11, 2019 09:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioklein/57af2f643316ace70204cfcf32f0411d to your computer and use it in GitHub Desktop.
Save mauricioklein/57af2f643316ace70204cfcf32f0411d to your computer and use it in GitHub Desktop.
Script to check EBS snapshots vulnerability
#!/bin/bash
#
# RUN:
# AWS_PROFILE=[profile] AWS_REGION=[region] ./check-ebs-snapshots.sh
#
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account')
snapshots=$(aws ec2 describe-snapshots \
--region $AWS_REGION \
--owner-ids $AWS_ACCOUNT_ID \
--filters "Name=status,Values=completed" \
--output text \
--query "Snapshots[*].SnapshotId" | tr "\t" "\n")
for ss in $snapshots; do
echo -n "Checking EBS snapshot '$ss': "
perms=$(aws ec2 describe-snapshot-attribute \
--region $AWS_REGION \
--snapshot-id $ss \
--attribute createVolumePermission \
--query 'CreateVolumePermissions[]')
[[ $perms =~ '"Group": "all"' ]] && echo "vulnerable!" || echo "secure!"
done
echo "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment