-
Notifications
You must be signed in to change notification settings - Fork 28
/
cloudhunter.py
315 lines (256 loc) · 10.1 KB
/
cloudhunter.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# CloudHunter
# Version: 0.4
import sys
import socket
import requests
import argparse
import json
try:
import boto3
except ImportError:
print('Install boto3 for full AWS support.')
from queue import Queue
from threading import Thread
from enum import Enum
googleCloud = {
'Google Storage': 'storage.googleapis.com',
'Google App Engine': 'appspot.com'
}
awsCloud = {
'AWS Bucket': 's3.amazonaws.com'
}
azureCloud = {
'Storage Files': 'file.core.windows.net',
'Storage Blobs': 'blob.core.windows.net',
'Storage Queues': 'queue.core.windows.net',
'Storage Tables': 'table.core.windows.net',
'App Management': 'scm.azurewebsites.net',
'App Azure': 'azurewebsites.net',
'App Web': 'p.azurewebsites.net',
'CloudApp': 'cloudapp.net',
'Key Vaults': 'vault.azure.net',
'Azure CDN': 'azureedge.net',
'Search Appliance': 'search.windows.net',
'API Services': 'azure-api.net',
'Hosted Domain': 'onmicrosoft.com',
'Databases-Redis': 'redis.cache.windows.net',
'Databases-CosmosDB': 'documents.azure.com',
'Databases-MSSQL': 'database.windows.net',
'Email': 'mail.protection.outlook.com',
'SharePoint': 'sharepoint.com'
}
class State(Enum):
CLOSE = 'CLOSE'
DOMAIN = 'DOMAIN'
PRIVATE = 'PRIVATE'
OPEN = 'OPEN'
UNKNOWN = 'UNKNOWN'
class Risk(Enum):
LOW = 0
MEDIUM = 34
HIGH = 31
class Bucket(object):
def __init__(self, name, domain, cloud='Generic', srv_name='Generic'):
self.name = name
self.domain = domain
self.cloud = cloud
self.srv_name = srv_name
self.state = State.CLOSE
self.risk = Risk.LOW
self.details = []
def process_status(self, response):
if(response == False):
self.state = State.DOMAIN
return
elif response.status_code == 200:
self.state = State.OPEN
self.risk = Risk.MEDIUM
elif response.status_code in [400, 401, 403]:
self.state = State.PRIVATE
elif response.status_code in [500, 502, 503]:
self.state = State.OPEN
self.risk = Risk.MEDIUM
self.details.append('WebApp Error')
else:
self.state = State.UNKNOWN
self.risk = Risk.MEDIUM
self.details.append('Response: {}'.format(response.status_code))
if self.name == base_name:
self.risk = Risk.MEDIUM
if(len(response.history) != 0 and response.history[0].status_code in [301, 302]):
self.details.append('Redirects ' + response.url)
self.process_rights()
def echo(self):
print('\033[0;{}m{}{:<22}{:<42}\t{:<10}{}\033[0;0m'.format(
self.risk.value, ' ' * 4, self.srv_name, self.domain, self.state.value, ' | '.join(self.details)))
if verbose and hasattr(self, 'acl'):
print(json.dumps(self.acl, indent=4))
def process_rights(self):
if self.state != State.OPEN:
return
if self.cloud == 'google':
self._google_acl()
elif self.cloud == 'aws':
self._aws_acl()
elif self.cloud == 'azure':
self._azure_acl()
def _azure_acl(self):
#azure_api = 'https://{}.blob.core.windows.net/{}?restype=container&comp=acl'.format(self.name,self.name)
#remote_acl = requests.get(azure_api)
# print(remote_acl)
pass
def _google_acl(self):
google_api = 'https://www.googleapis.com/storage/v1/b/{}/iam/testPermissions?permissions=storage.buckets.delete&permissions=storage.buckets.get&permissions=storage.buckets.getIamPolicy&permissions=storage.buckets.setIamPolicy&permissions=storage.buckets.update&permissions=storage.objects.create&permissions=storage.objects.delete&permissions=storage.objects.get&permissions=storage.objects.list&permissions=storage.objects.update'.format(
self.name)
remote_acl = requests.get(google_api).json()
if remote_acl.get('permissions'):
self.acl = remote_acl['permissions']
user = 'AllUsers'
symb = ''
if 'storage.objects.list' in self.acl:
symb += 'L'
if 'storage.objects.get' in self.acl:
symb += 'R'
if 'storage.objects.create' in self.acl or \
'storage.objects.delete' in self.acl or \
'storage.objects.update' in self.acl:
self.risk = Risk.HIGH
symb += 'W'
if 'storage.buckets.setIamPolicy' in self.acl:
self.risk = Risk.HIGH
symb += 'V'
self.details.append('{} [{}]'.format(user, symb))
def _aws_acl(self):
try:
s3 = boto3.client('s3')
remote_acl = s3.get_bucket_acl(Bucket=self.name)
if 'Grants' in remote_acl:
self.acl = remote_acl['Grants']
rights = {}
for right in self.acl:
if right['Grantee']['Type'] == 'CanonicalUser' and 'DisplayName' in right['Grantee']:
user = right['Grantee']['DisplayName']
elif right['Grantee']['Type'] == 'Group':
user = right['Grantee']['URI'].split('/')[-1]
else:
user = right['Grantee']['ID'][:8]
if right['Permission'] == 'READ' or right['Permission'] == 'READ_ACP':
symb = 'R'
elif right['Permission'] == 'WRITE' or right['Permission'] == 'WRITE_ACL':
self.risk = Risk.HIGH
symb = 'W'
elif right['Permission'] == 'FULL_CONTROL':
self.risk = Risk.HIGH
symb = 'F'
if user not in rights:
rights[user] = symb
elif symb not in rights[user]:
rights[user] += symb
for user, symb in rights.items():
self.details.append('{} [{}]'.format(user, symb))
except:
pass
def check_dns(hostname):
try:
ip = socket.gethostbyname(hostname)
if ip in ['0.0.0.0', '127.0.0.1']:
return False
return True
except socket.error:
return False
def check_host(host):
try:
response = requests.get('http://' + host)
except:
return False
if response.status_code in [404]:
return False
return response
def generate_permutations(base_name, dict_file):
p = []
p.append(base_name)
rules = ['{}-{}', '{}.{}', '{}{}']
with open(dict_file, 'r') as f:
lines = f.read().splitlines()
for affix in lines:
p += [x.format(affix, base_name) for x in rules]
p += [x.format(base_name, affix) for x in rules]
return p
def check_cloud(cloud_dict, names, cloud='default'):
q = Queue(maxsize=0)
results = []
for srv_name, srv_url in cloud_dict.items():
for name in names:
domain = '{}.{}'.format(name, srv_url)
q.put((srv_name, domain, name))
for w in range(num_threads):
worker = Thread(target=check_cloud_worker, args=(q, results, cloud))
worker.setDaemon(True)
worker.start()
q.join()
return results
def check_cloud_worker(q, results, cloud):
while not q.empty():
work = q.get()
srv_name = work[0]
domain = work[1]
name = work[2]
if(verbose):
print('[d] checking {}'.format(domain))
if check_dns(domain):
response = check_host(domain)
if(response != False or cloud == 'azure'):
b = Bucket(name, domain, cloud, srv_name)
b.process_status(response)
results.append(b)
if not show_open_only or b.state == State.OPEN:
b.echo()
q.task_done()
return True
def show_banner():
banner = '''\033[0;32m
________ ____ __ __
/ ____/ /___ __ ______/ / / / /_ ______ / /____ _____
/ / / / __ \/ / / / __ / /_/ / / / / __ \/ __/ _ \/ ___/
/ /___/ / /_/ / /_/ / /_/ / __ / /_/ / / / / /_/ __/ /
\____/_/\____/\__,_/\__,_/_/ /_/\__,_/_/ /_/\__/\___/_/
\n\033[0;0m'''
print(banner)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='CloudHunter. Searches for AWS, Azure and Google cloud storage buckets.')
parser.add_argument('base_name', metavar='basename', type=str,
nargs='+', help='Company name or any base name.')
parser.add_argument('-p', '--permutations-file', metavar='file',
type=str, default='permutations.txt', help='Permutations file.')
parser.add_argument('-t', '--threads', metavar='num',
type=int, default=10, help='Threads.')
parser.add_argument('-b', '--base-only', action='store_true',
help='checks only the base name, skips permutations generation.')
parser.add_argument('-v', '--verbose',
action='store_true', help='verbose log')
parser.add_argument('-o', '--open-only',
action='store_true', help='show only open buckets.')
args = parser.parse_args()
show_banner()
num_threads = min(300, args.threads)
show_open_only = args.open_only
verbose = args.verbose
results = []
base_name = args.base_name[0].strip().lower()
if(args.base_only):
permutations = [base_name]
else:
permutations = generate_permutations(base_name, args.permutations_file)
srv_len = len(azureCloud) + len(googleCloud) + len(awsCloud)
print('[>] {} name permutations.'.format(len(permutations)))
print('[>] {} tries, be patient.\n'.format(len(permutations) * srv_len))
print('\n[+] Check Google Cloud')
results += check_cloud(googleCloud, permutations, 'google')
print('\n[+] Check Amazon Cloud')
results += check_cloud(awsCloud, permutations, 'aws')
print('\n[+] Check Azure Cloud')
results += check_cloud(azureCloud, permutations, 'azure')