forked from sa7mon/S3Scanner
-
Notifications
You must be signed in to change notification settings - Fork 6
/
s3dumper.sh
executable file
·63 lines (49 loc) · 1.65 KB
/
s3dumper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
#############################################################################
#
# testS3.sh - Test if S3 buckets are open to everyone and dump if they are
#
# Author: Dan Salmon (twitter.com/bltjetpack, github.com/sa7mon)
# Created: 6/20/2017
#
# Requirements: aws-cli (pip install awscli)
#
#############################################################################
# Actually obey ctrl+c while inside while loop
trap trapint 2
function trapint {
exit 0
}
s3file=$1
# Read file with lines in format:
# domain:s3region (i.e. google.com:us-west-2)
while read line
do
# Do what you want to $domain
domain=`echo $line | awk -F ':' '{print tolower($1)}'`
region=`echo $line | awk -F ':' '{print tolower($2)}'`
echo "[$domain] Checking domain: $domain:$region"
awsls=`aws s3 ls s3://$domain --no-sign-request --region $region 2>&1`
# Check if we get an "AccessDenied" error while attempting to
# list the bucket's contents
if [[ $awsls == *"AccessDenied"* ]]
then
echo "[$domain] Nope. Access denied."
else
echo "[$domain] Seems good!"
# Create directory if it doesn't already exist
if [ ! -d "./buckets/$domain" ]
then
mkdir -p "./buckets/$domain";
fi
# Download bucket into directory
aws s3 sync s3://$domain ./buckets/$domain/ --no-sign-request --region $region
# Check if dumped bucket folder is empty and delete if it is.
target="./buckets/$domain"
if ! find "$target" -mindepth 1 -print -quit | grep -q .; then
echo "[$domain] Folder is empty. Deleting..."
rmdir $target
fi
fi
# fi
done < $s3file