forked from ethicalhackingplayground/Bug-Bounty-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3bucketer.py
193 lines (152 loc) · 8.79 KB
/
s3bucketer.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/python
# Import modules
import time
import sys
import os
import requests
import argparse
# Import more modules
from colorama import Fore,Style
def banner():
os.system("clear")
print Style.BRIGHT + Fore.WHITE + """
______________ _
(_______(____ \ | | _
___ ____ ____) )_ _ ____| | _ ____| |_ ____ ____
/___)(___ \| __ (| | | |/ ___) | / ) _ ) _)/ _ )/ ___)
|___ |____) ) |__) ) |_| ( (___| |< ( (/ /| |_( (/ /| |
(___(______/|______/ \____|\____)_| \_)____)\___)____)_|
""" + Style.DIM + Fore.BLUE + "\t\t@z0idex\n\n"
class Scanner(object):
"""docstring for Scanner"""
def __init__(self, args):
super(Scanner, self).__init__()
self.args = args
# Print the text
def text(self,status, text):
if status == "i":
print Style.BRIGHT + Fore.WHITE + "["+Fore.YELLOW+"i"+Fore.WHITE+"]" + " " + Style.RESET_ALL + Style.DIM + Fore.WHITE + text
if status == "!":
print Style.BRIGHT + Fore.WHITE + "["+Fore.RED+"!"+Fore.WHITE+"]" + " " + Style.RESET_ALL + Style.DIM + Fore.WHITE + text
if status == "+":
print Style.BRIGHT + Fore.WHITE + "["+Fore.GREEN+"+"+Fore.WHITE+"]" + " " + Style.RESET_ALL + Style.DIM + Fore.WHITE + text
# Bucket checker
def checker(self,domain):
if os.path.isfile(self.args.buckets) == None:
self.text("!", "No bucket wordlist")
return
buckets = open(self.args.buckets, "r")
for bucket in buckets.readlines():
# Strip the bucket
bucket = bucket.strip()
# Check the prefix / seperator
for i in range(3):
seperator = ""
if i == 0:
seperator = "_"
if i == 1:
seperator = "-"
if i == 2:
seperator = "."
for i in range(2):
if i == 0:
url = ("https://%s%s%s.s3.amazonaws.com" % (bucket, seperator, domain))
if args.quite == "0":
self.text("i", url)
# Try to get the response a check the status_code for a bucket
try:
# make a request
response = requests.get(url, verify=True, timeout=10)
# Access Denied
if response.status_code == 403:
self.text("!", "Found Bucket: %s (%s)" % (url, str(response.status_code)))
# Public Bucket
if response.status_code == 200:
self.text("+", "Found Bucket: %s (%s)" % (url,str(response.status_code)))
os.system("echo %s >> %s"% (url, args.output))
except:
pass
url = ("http://%s%s%s.s3.amazonaws.com" % (bucket, seperator, domain))
if args.quite == "0":
self.text("i", url)
# Try to get the response a check the status_code for a bucket
try:
# make a request
response = requests.get(url, verify=True, timeout=10)
# Access Denied
if response.status_code == 403:
self.text("!", "Found Bucket: %s (%s)" % (url, str(response.status_code)))
# Public Bucket
if response.status_code == 200:
self.text("+", "Found Bucket: %s (%s)" % (url,str(response.status_code)))
os.system("echo %s >> %s"% (url, args.output))
except:
pass
if i == 1:
url = ("https://%s%s%s.s3.amazonaws.com" % (domain, seperator, bucket))
if args.quite == "0":
self.text("i", url)
# Try to get the response a check the status_code for a bucket
try:
# make a request
response = requests.get(url, verify=True, timeout=10)
# Access Denied
if response.status_code == 403:
self.text("!", "Found Bucket: %s (%s)" % (url,str(response.status_code)))
# Public Bucket
if response.status_code == 200:
if "The specified bucket does not exist" in response.text:
self.text("+", "Found Bucket: %s (%s)" % (url,str(response.status_code)))
os.system("echo %s >> %s" % (url, args.output))
except:
pass
url = ("http://%s%s%s.s3.amazonaws.com" % (domain, seperator, bucket))
if args.quite == "0":
self.text("i", url)
# Try to get the response a check the status_code for a bucket
try:
# make a request
response = requests.get(url, verify=True, timeout=10)
# Access Denied
if response.status_code == 403:
self.text("!", "Found Bucket: %s (%s)" % (url,str(response.status_code)))
# Public Bucket
if response.status_code == 200:
if "The specified bucket does not exist" in response.text:
self.text("+", "Found Bucket: %s (%s)" % (url,str(response.status_code)))
os.system("echo %s >> %s" % (url, args.output))
except:
pass
# Start the scanner
def scan(self):
# Validate the arguments
if (self.args.domains != None):
if (os.path.isfile(self.args.domains)):
# Start checking for buckets
doms = open(self.args.domains, 'r')
print Style.RESET_ALL + Style.BRIGHT + Fore.CYAN + "Scanning...\n"
time.sleep(2)
for domain in doms.readlines():
host = domain.strip()
print Style.RESET_ALL + Style.BRIGHT + Fore.CYAN + " Checking " + Fore.GREEN + host + Fore.CYAN+" for buckets.\n"
print Style.RESET_ALL + Style.BRIGHT + Fore.WHITE +"------------------------------------------------"
self.checker(host)
if os.path.isfile(args.output):
print Style.RESET_ALL + Style.BRIGHT + Fore.WHITE + "------------------ FOUND ---------------------"
buckets = open(args.output, 'r')
for bucket in buckets.readlines():
bucket = bucket.strip()
print bucket
print "--------------------------------------"
# Print the banner
banner()
# Arguments
parser = argparse.ArgumentParser(description="S3 Bucket Scanner")
parser.add_argument("--domains", "-d", help="The list of domains")
parser.add_argument("--buckets", "-b", help="The file containing the buckets")
parser.add_argument("--quite", "-q", help="Verbose (1 = false, 0 = true)",default="1")
parser.add_argument("--output", "-o", help="The output file")
args = parser.parse_args()
# Start the scanner
bucket = Scanner(args)
bucket.scan()