-
Notifications
You must be signed in to change notification settings - Fork 1
/
subpwnable.py
150 lines (122 loc) · 4.32 KB
/
subpwnable.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
#!/usr/bin/env python3
import requests
import sys
import dns.resolver
import argparse
import re
import lxml.html
from prettytable import PrettyTable
print('''
<:|3~~...<:|3~~...<:|3~~...<:|3~~...<:|3~~...<:|3~~...<:|3~~...<:|3~~
__ _ ___ _ _
/ _\_ _| |__ / _ \__ ___ __ __ _| |__ | | ___
\ \| | | | '_ \ / /_)/\ \ /\ / / '_ \ / _` | '_ \| |/ _ \
_\ \ |_| | |_) / ___/ \ V V /| | | | (_| | |_) | | __/
\__/\__,_|_.__/\/ \_/\_/ |_| |_|\__,_|_.__/|_|\___|by S1rN3tZ
<:|3~~...<:|3~~...<:|3~~...<:|3~~...<:|3~~...<:|3~~...<:|3~~...<:|3~~
''')
class bcolors:
OK = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
RESET = '\033[0m'
INFO = '\033[94m'
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--domain", help="Target a single domain", type=str)
parser.add_argument("-l", "--list", help="Target a list of domains", type=str)
args = parser.parse_args()
def Record(domain):
list=[]
try:
result = dns.resolver.resolve(domain, 'CNAME')
for record in result:
CNAME = str(record)
list.append(CNAME)
return list
except:
pass
def sc(domain):
for proto in ["http://","https://"]:
try:
url=proto+domain
rq=requests.get(url)
status_code=str(rq.status_code)
if status_code == "404":
print("["+bcolors.INFO+"Domain Available"+bcolors.RESET+"]"+domain+bcolors.INFO+' ==> '+bcolors.RESET+bcolors.INFO+status_code+bcolors.RESET)
elif status_code == "302":
print("["+bcolors.WARNING+"Redirect"+bcolors.RESET+"]"+domain+bcolors.INFO+' ==> '+bcolors.RESET+bcolors.WARNING+status_code+bcolors.RESET)
req=requests.get(rq.url)
else:
print("["+bcolors.FAIL+"Domain Not Available"+bcolors.RESET+"]"+domain+bcolors.INFO+' ==> '+bcolors.RESET+bcolors.FAIL+status_code+bcolors.RESET)
except KeyboardInterrupt:
print(bcolors.FAIL+"[!] "+bcolors.RESET+"Script canceled.")
exit(0)
except:
pass
def match(regex, data):
list=[]
matches = re.finditer(regex, data, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
return "{match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())
def tabparsing(markup):
tbl = []
rows = markup.cssselect("tr")
for row in rows:
tbl.append(list())
for td in row.cssselect("td"):
tbl[-1].append(td.text_content())
return tbl
def main():
if args.domain:
sc(args.domain)
records=Record(args.domain)
if not records:
print(bcolors.FAIL+"[!] "+bcolors.RESET+"No record found for "+args.domain)
else:
for CNAME in records:
print(args.domain+bcolors.INFO+' CNAME '+bcolors.RESET+CNAME)
elif args.list:
print(bcolors.INFO+"[*] "+bcolors.RESET+"Processing your request... It can take few minutes.\n")
sublist = open(args.list, encoding='utf-8')
try:
for sub in sublist:
sc(sub.strip())
sublist.close()
print(bcolors.INFO+"\n[*] "+bcolors.RESET+"CNAME records:\n")
sublist = open(args.list, encoding='utf-8')
t=PrettyTable(['Domain','CNAME','Record'])
for sub in sublist:
records=Record(sub.strip())
if not records:
t.add_row([sub,bcolors.INFO+'CNAME'+bcolors.RESET,bcolors.FAIL+'None'+bcolors.RESET])
pass
else:
for CNAME in records:
t.add_row([sub,bcolors.INFO+'CNAME'+bcolors.RESET,CNAME])
print(t)
sublist.close()
except:
pass
table = r"<table>(.|\n)*?<\/table>"
rq=requests.get("https://github.com/EdOverflow/can-i-take-over-xyz/blob/master/README.md")
result = match(table, rq.text)
markup = lxml.html.fromstring(result)
tbl = tabparsing(markup)
tab = PrettyTable(['Engine','Status','Fingerprint'])
tbl = [x for x in tbl if x != []]
for list in tbl:
del list[3]
del list[3]
tab.add_row(list)
print(bcolors.INFO+"\n[*] "+bcolors.RESET+"Known Services:\n")
print(tab)
print(bcolors.INFO+"\n[*] "+bcolors.RESET+"Check out these helpful resources to know more about subdomains takeover:\n")
print(bcolors.INFO+"[*] "+bcolors.RESET+"https://github.com/EdOverflow/can-i-take-over-xyz")
print(bcolors.INFO+"[*] "+bcolors.RESET+"https://s1rn3tz.gitbook.io/notes/bug-bounty-tips/prise-de-controle-de-sous-domaine")
try:
main()
except Exception as e:
print(e)
except KeyboardInterrupt:
print(bcolors.FAIL+"[!] "+bcolors.RESET+"Script canceled.")
exit(0)