-
Notifications
You must be signed in to change notification settings - Fork 75
/
takeover.py
340 lines (269 loc) · 12 KB
/
takeover.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#SubDomain Takeover Scanner by 0x94
import threading
import sys
import optparse
import requests
from lib.TerminalSize import get_terminal_size
import platform
from thirdparty.colorama import *
import time
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
if platform.system() == 'Windows':
from thirdparty.colorama.win32 import *
is_py2 = sys.version[0] == '2'
if is_py2:
import Queue
queue = Queue.Queue()
else:
import queue as queue
queue = queue.Queue()
progress=0
lastInLine = False
try:
import dns.resolver
except:
print("You need to install dnspython")
sys.exit(1)
class hazirla:
def __init__(self,domain,wordlist,thread,filem):
self.domain=domain
self.wordlist=wordlist
self.thread=thread
self.filem=filem
def thbaslat(self,sublar,num_lines):
lock = threading.Lock()
for subum in sublar:
if subum.strip():
if self.filem!="":
queue.put(subum.strip())
else:
queue.put(subum.strip()+"."+self.domain)
threads = []
exit = threading.Event()
for i in range(self.thread):
t = DnsSorgu(queue,lock,num_lines,exit,self.filem)
t.setDaemon(True)
threads.append(t)
t.start()
try:
queue.join()
except KeyboardInterrupt:
print("Exit")
sys.exit(1)
def main(self):
try:
if self.filem!="":
num_lines = sum(1 for line in open(self.filem))
dosya = open(self.filem)
else:
num_lines = sum(1 for line in open(self.wordlist))
dosya = open(self.wordlist)
except IOError:
if self.filem!="":
print("File not found %s" % (self.filem))
else:
print("File not found %s" % (self.wordlist))
sys.exit(0)
try:
self.thbaslat(dosya.readlines(),num_lines)
except (KeyboardInterrupt,SystemExit):
print("Cancelled")
exit()
class DnsSorgu(threading.Thread):
def __init__(self, queue,lock,num_lines,exit,filem):
threading.Thread.__init__(self)
self.queue = queue
self.lock = lock
self.num_lines = num_lines
self.exit = exit
self.filem=filem
self.response=["<strong>Trying to access your account",
"Use a personal domain name",
"The request could not be satisfied",
"Sorry, We Couldn't Find That Page",
"Fastly error: unknown domain",
"The feed has not been found",
"You can claim it now at",
"Publishing platform",
"<title>No such app</title>",
"No settings were found for this company",
"<title>No such app</title>",
"is not a registered InCloud YouTrack.",
"You've Discovered A Missing Link. Our Apologies!",
"Sorry, couldn’t find the status page",
"NoSuchBucket",
"Sorry, this shop is currently unavailable",
"<title>Hosted Status Pages for Your Company</title>",
"data-html-name=\"Header Logo Link\"",
"<title>Oops - We didn't find your site.</title>",
"class=\"MarketplaceHeader__tictailLogo\"",
"Whatever you were looking for doesn't currently exist at this address",
"The page you have requested does not exist",
"This UserVoice subdomain is currently available!",
"but is not configured for an account on our platform",
"Looks like you've traveled too far into cyberspace.",
"The specified bucket does not exist",
"Bad Request: ERROR: The request could not be satisfied",
"Please try again or try Desk.com free for",
"We could not find what you're looking for",
"No Site For Domain",
"Project doesnt exist... yet!",
"project not found",
"Please renew your subscription",
"Double check the URL or <a href=\"mailto:[email protected]",
"There is no portal here",
"You may have mistyped the address or the page may have moved",
"Repository not found",
"<title>404 — File not found</title>",
"This page is reserved for artistic dogs",
"<h1>The page you were looking for doesn",
"<h1>https://www.wishpond.com/404?campaign=true",
'<p class="bc-gallery-error-code">Error Code: 404</p>',
"<h1>Oops! We couldn’t find that page.</h1>",
"Unrecognized domain <strong>",
"NoSuchKey",
"The specified key does not exist",
"<title>Help Center Closed | Zendesk</title>"]
self.success = Fore.GREEN
self.error = Fore.RED
self.info = Fore.YELLOW
def run(self):
try:
while True:
if self.exit.is_set():
break
with self.lock:
global progress
if progress<self.num_lines:
progress+=1
gelenq=self.queue.get()
percentage = lambda x, y: float(x) / float(y) * 100
x, y = get_terminal_size()
message = '{0:.2f}% - {aa}/{bb} '.format(percentage(progress, self.num_lines),aa=progress,bb=self.num_lines)
message += 'Scanning: {0}'.format(gelenq)
if len(message) > x:
message = message[:x]
self.inLine(message)
try:
answers = dns.resolver.query(gelenq, 'CNAME')
for rdata in answers:
message = '[{0}] {1} - {2} - Cname -> {3}'.format(
time.strftime('%H:%M:%S'),
gelenq,
answers.qname,
Fore.YELLOW+rdata.target.to_text()+Style.RESET_ALL
)
self.newLine(message)
self.domaindel(rdata.target.to_text())
self.takeover(rdata.target.to_text(),gelenq)
except:
hata ="hata"
#answers.timeout = 0.5
#answers.lifetime = 0.10
self.queue.task_done()
except StopIteration:
return
def domaindel(self,cname):
try:
dns.resolver.query(cname)
return True
except:
yaz="Cname not resolved "+cname
print(Style.BRIGHT+self.error+yaz+Style.RESET_ALL)
self.filewrite(yaz)
return False
def detect(self,subdomain):
try:
subrespon=requests.get("http://"+subdomain,verify=False).text
for finder in self.response:
if finder in subrespon:
self.filewrite("--- TAKEOVER DETECTED !!! : "+subdomain)
print(self.error+"--- TAKEOVER DETECTED !!! : "+subdomain+ "\n Message="+finder+Style.RESET_ALL)
except Exception as e:
a="error"
def filewrite(self,veri):
open("takeover.txt","a+").write(veri+"\n")
def takeover(self,domain,subdomain):
self.detect(subdomain)
def erase(self):
if platform.system() == 'Windows':
csbi = GetConsoleScreenBufferInfo()
line = "\b" * int(csbi.dwCursorPosition.X)
sys.stdout.write(line)
width = csbi.dwCursorPosition.X
csbi.dwCursorPosition.X = 0
FillConsoleOutputCharacter(STDOUT, ' ', width, csbi.dwCursorPosition)
sys.stdout.write(line)
sys.stdout.flush()
else:
sys.stdout.write('\033[1K')
sys.stdout.write('\033[0G')
def newLine(self,string):
global lastInLine
if lastInLine == True:
self.erase()
if platform.system() == 'Windows':
sys.stdout.write(string)
sys.stdout.flush()
sys.stdout.write('\n')
sys.stdout.flush()
else:
sys.stdout.write(string + '\n')
sys.stdout.flush()
lastInLine = False
sys.stdout.flush()
def inLine(self,string):
global lastInLine
self.erase()
sys.stdout.write(string)
sys.stdout.flush()
lastInLine = True
if __name__ == '__main__':
try:
if platform.system() == 'Windows':
init(autoreset=True) #windows icin
parser = optparse.OptionParser()
parser.add_option('-d',
action = "store",
dest = "domain",
type = "string")
parser.add_option('-w',
action = "store",
dest = "wordlist",
type = "string")
parser.add_option('-t',
action = "store",
dest = "thread",
type = "int")
parser.add_option('-f',
action = "store",
dest = "filem",
type = "string")
(option,args) = parser.parse_args()
if not option.domain:
print("example: ./takeover.py -d host.com -w wordlist.txt -t 10 or | ./takeover.py -d host.com -f sublist.txt -t 10 ")
sys.exit(0)
if option.thread:
threadsayisi=option.thread
else:
threadsayisi=20
print("""
#######################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# SubDomain TakeOver v1.5 #
# Coder: 0x94 #
# twitter.com/0x94 #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#######################################################
""")
if option.filem:
x=hazirla(option.domain,option.wordlist,threadsayisi,option.filem)
else:
x=hazirla(option.domain,option.wordlist,threadsayisi,"")
x.main()
except KeyboardInterrupt:
print('\n Exit.')
sys.exit(0)