forked from appsecco/bugcrowd-levelup-subdomain-enumeration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudflare_enum.py
executable file
·223 lines (195 loc) · 9.17 KB
/
cloudflare_enum.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created using Metafidv2 by Matthew Bryant (mandatory)
# Unauthorized use is stricly prohibited, please contact [email protected] with questions/comments.
from __future__ import print_function
import requests
import getpass
import json
import time
import csv
import sys
import os
from bs4 import BeautifulSoup
class cloudflare_enum:
def __init__( self ):
# Master list of headers to be used in each connection
self.global_headers = {
}
self.verbose = True
self.s = requests.Session()
self.s.headers.update( self.global_headers )
self.atok = ''
def log_in( self, username, password ):
parse_dict = {}
r = self.s.get('https://www.cloudflare.com/', )
new_headers = {
'Referer': 'https://www.cloudflare.com/',
}
self.s.headers.update( dict( new_headers.items() + self.global_headers.items() ) )
r = self.s.get('https://www.cloudflare.com/a/login', )
parse_dict[ 'security_token_0' ] = self.find_between_r( r.text, '"security_token":"', '"}};</script>' ) # http://xkcd.com/292/
post_data = {
'email': username,
'password': password,
'security_token': parse_dict[ 'security_token_0' ],
}
new_headers = {
'Referer': 'https://www.cloudflare.com/a/login',
'Content-Type': 'application/x-www-form-urlencoded',
}
self.s.headers.update( dict( new_headers.items() + self.global_headers.items() ) )
r = self.s.post('https://www.cloudflare.com/a/login', data=post_data)
self.atok = self.find_between_r( r.text, 'window.bootstrap = {"atok":"', '","locale":"' ) # http://xkcd.com/292/
def get_domain_dns( self, domain ):
parse_dict = {}
post_data = {
"betas": [],
"created_on": "2015-08-24T00:27:16.048Z",
"development_mode": False,
"jump_start": True,
"meta": {},
"modified_on": 'null',
"name": domain,
"owner": {},
"paused": False,
"status": "initializing",
"type": "full"
}
new_headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://www.cloudflare.com/a/add-site',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'X-ATOK': self.atok,
}
self.s.headers.update( dict( new_headers.items() + self.global_headers.items() ) )
r = self.s.post('https://www.cloudflare.com/api/v4/zones', data=json.dumps( post_data ))
data = json.loads( r.text )
success = data['success']
if not success:
print( r.text )
return False
request_id = data['result']['id']
time.sleep( 60 )
get_data = {
'per_page': '100',
'direction': 'asc',
'page': '1',
'order': 'type',
}
new_headers = {
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://www.cloudflare.com/a/setup/' + domain + '/step/2',
'X-ATOK': self.atok,
}
self.s.headers.update( dict( new_headers.items() + self.global_headers.items() ) )
r = self.s.get('https://www.cloudflare.com/api/v4/zones/' + request_id + '/dns_records', params=get_data)
return_data = json.loads( r.text )
new_headers = {
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://www.cloudflare.com/a/setup/' + domain + '/step/2',
'X-ATOK': self.atok,
}
self.s.headers.update( dict( new_headers.items() + self.global_headers.items() ) )
r = self.s.delete('https://www.cloudflare.com/api/v4/zones/' + request_id, )
get_data = {
'status': 'initializing,pending',
'per_page': '50',
'page': '1',
}
new_headers = {
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://www.cloudflare.com/a/add-site',
'X-ATOK': self.atok,
}
self.s.headers.update( dict( new_headers.items() + self.global_headers.items() ) )
r = self.s.get('https://www.cloudflare.com/api/v4/zones', params=get_data)
return return_data['result']
def get_spreadsheet( self, domain ):
dns_data = self.get_domain_dns( domain )
if dns_data:
filename = domain.replace( ".", "_" ) + ".csv"
with open( filename, 'wb' ) as csvfile:
dns_writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
dns_writer.writerow( [ "name", "type", "content" ] )
for record in dns_data:
dns_writer.writerow( [ record["name"], record["type"], record["content"] ] )
self.statusmsg( "Spreadsheet created at " + os.getcwd() + "/" + filename )
def print_banner( self ):
if self.verbose:
print("""
`..--------..`
.-:///::------::///:.`
`-//:-.`````````````.-://:.` ` `
.://-.```````````````````.-://-` : `- .
`-//:.........................-://. /. -: `:` ``
`://--------:::://////:::--------://-::.::`:- .:.
``.---..` `///::::::///////////////////:::::::///::::::--:.`.-.
.://::::///::///::///////////////////////////:::///:-----::--:-` `
`:/:-...--:://////////////////////////////////////////----------.--.`
`:/:..-:://////////////////////////////////////////////-----------.````
.//-::////////////////////////////////////:::::////////-...--------...`
-/////////////////////////////////////////////::::----:. `.-::::::-..``
``.--:////////////////////////////////////////////////::-..```-///::::///:-`
`.:///::::://////////////////////////////////////:::::::::::::::-----......-:/:.
`-//:-----::::://///////////////////////////////:///////////////////:-::::---..-//:`
`:/:---://+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//+++//::--//:
`//:-/+oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo+++oooo+//://.
:///ossssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssosssssso+//:
`//+sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss+/-
`//+ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo+++++/.
``````````````````````````````````````````````````````````````````````````````````````
Cloudflare DNS Enumeration Tool v1.3
Created by mandatory
Modified by yamakira
""" )
def pprint( self, input_dict ):
print( json.dumps(input_dict, sort_keys=True, indent=4, separators=(',', ': ')) )
def statusmsg( self, msg ):
if self.verbose:
print( "[ STATUS ] " + msg )
def errormsg( self, msg ):
if self.verbose:
print( "[ ERROR ] " + msg )
def successmsg( self, msg ):
if self.verbose:
print( "[ SUCCESS ] " + msg )
def find_between_r( self, s, first, last ):
try:
start = s.rindex( first ) + len( first )
end = s.rindex( last, start )
return s[start:end]
except ValueError:
return ""
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
def get_cookie_from_file( self, cookie_file ):
return_dict = {}
with open( cookie_file ) as tmp:
data = tmp.readlines()
tmp_data = []
for i, item in enumerate(data):
if " " in data[i]:
pew = data[i].split( " " )
return_dict[ pew[5] ] = pew[6]
return return_dict
def get_creds(self):
username = sys.argv[1]
password = getpass.getpass('Provide your cloudflare password:')
return username,password
if __name__ == "__main__":
if len( sys.argv ) < 2:
print( "Usage: " + sys.argv[0] + " [email protected] domain.com" )
else:
cloud = cloudflare_enum()
username,password = cloud.get_creds()
cloud.print_banner()
cloud.log_in(username,password)
cloud.get_spreadsheet(sys.argv[2])