-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadrishya.py
269 lines (206 loc) · 10.9 KB
/
adrishya.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
import re
from urllib.parse import urljoin
import asyncio
import aiohttp
import requests
from aiohttp.client import ClientSession
import sys
import subprocess
class colors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
lightgrey = '\033[37m'
darkgrey = '\033[90m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
print(colors.OKGREEN,colors.BOLD,"""
░█████╗░██████╗░██████╗░██╗░██████╗██╗░░██╗██╗░░░██╗░█████╗░
██╔══██╗██╔══██╗██╔══██╗██║██╔════╝██║░░██║╚██╗░██╔╝██╔══██╗
███████║██║░░██║██████╔╝██║╚█████╗░███████║░╚████╔╝░███████║
██╔══██║██║░░██║██╔══██╗██║░╚═══██╗██╔══██║░░╚██╔╝░░██╔══██║
██║░░██║██████╔╝██║░░██║██║██████╔╝██║░░██║░░░██║░░░██║░░██║
╚═╝░░╚═╝╚═════╝░╚═╝░░╚═╝╚═╝╚═════╝░╚═╝░░╚═╝░░░╚═╝░░░╚═╝░░╚═╝
███████████████████████████████████
█─▄▄▄▄█▄─▄▄─█▄─▄█▄─▄▄▀█▄─▄▄─█▄─▄▄▀█
█▄▄▄▄─██─▄▄▄██─███─██─██─▄█▀██─▄─▄█
▀▄▄▄▄▄▀▄▄▄▀▀▀▄▄▄▀▄▄▄▄▀▀▄▄▄▄▄▀▄▄▀▄▄▀
@kartikhunt3r
""",colors.ENDC)
target = input(colors.HEADER+colors.BOLD+"Enter Target URL: "+colors.ENDC)
if not target.startswith("http://") and not target.startswith("https://"):
target="http://"+target
if target.endswith("/"):
target=target[:-1]
print(colors.OKCYAN+colors.BOLD+"[+] Target: "+target+colors.ENDC)
try:
requests.get(target)
except Exception as e:
print(colors.FAIL+colors.BOLD+"Please Enter A Valid URL ex:https://example.com")
sys.exit()
x = target.split("/")
y=x[2]
subprocess.call("mkdir "+y,shell=True)
invalid=True
while invalid:
externals=input(colors.WARNING+colors.BOLD+"Do you Want to include External third Party Links?[Y/N]: ")
if externals == "Y" or externals == "y" or externals == "N" or externals == "n":
invalid=False
else:
print(colors.FAIL+colors.BOLD+"Please Answer In Y/N")
wayinvalid=True
while wayinvalid:
waybacks=input(colors.WARNING+colors.BOLD+"Do you Want to include Way Back Urls?[Y/N]: ")
if waybacks == "Y" or waybacks == "y" or waybacks == "N" or waybacks == "n":
wayinvalid=False
else:
print(colors.FAIL+colors.BOLD+"Please Answer In Y/N")
target_url=[]
target_links = []
temp_links=[]
target_js=[]
target_form=[]
target_robo=[]
target_sitemaps=[]
ginti=[]
target_url.append(target)
target_url.append(target+"/sitemap.xml")
target_url.append(target+"/robots.txt")
async def link_extractor(url,session:ClientSession):
async with session.get(url) as response:
result = await response.text()
href_links= re.findall('(?:href=")(.*?)"',str(result)) + re.findall("(?:href=')(.*?)'",str(result))
js_links= re.findall('(?:src=")(.*?)"',str(result)) + re.findall("(?:src=')(.*?)'",str(result))
form_links= re.findall('(?:action=")(.*?)"',str(result)) + re.findall("(?:action=')(.*?)'",str(result))
xml_links= re.findall('(?:<loc>)(.*?)</loc>',str(result))
robo_links= re.findall('(?:Disallow: )(.*?)\n',str(result))+re.findall('(?:Allow: )(.*?)\n',str(result))+re.findall('(?:sitemap: )(.*?)\n',str(result))
for link in href_links:
link = urljoin(url,link)
# if "#" in link:
# link = link.split("#")[0]
if target in link and link not in target_links:
temp_links.append(link)
if externals=="y" or externals=="Y":
if link not in target_links:
print(colors.OKGREEN+colors.BOLD+"[+] Link: "+link+colors.ENDC)
target_links.append(link)
ginti.append("[+] Link: "+link)
elif externals=="n" or externals=="N":
if target in link and link not in target_links:
print(colors.OKGREEN+colors.BOLD+"[+] Link: "+link+colors.ENDC)
target_links.append(link)
ginti.append("[+] Link: "+link)
for limk in js_links:
limk = urljoin(url,limk)
if target in limk and limk not in target_js and limk.endswith(".json"):
temp_links.append(limk)
if externals == "Y" or externals == "y":
if limk not in target_js and limk.endswith(".js"):
target_js.append(limk)
print(colors.OKBLUE+colors.BOLD+"[+] JS file: "+limk+colors.ENDC)
ginti.append("[+] JS file: "+limk)
elif limk not in target_js and limk not in target_form and limk not in target_links:
target_js.append(limk)
print(colors.OKGREEN+colors.BOLD+"[+] Link: "+limk+colors.ENDC)
ginti.append("[+] Link: "+limk)
elif externals == "N" or externals == "n":
if target in limk and limk not in target_js and limk.endswith(".js"):
target_js.append(limk)
print(colors.OKBLUE+colors.BOLD+"[+] JS file: "+limk+colors.ENDC)
ginti.append("[+] JS file: "+limk)
elif target in limk and limk not in target_js and limk not in target_form and limk not in target_links:
target_js.append(limk)
print(colors.OKGREEN+colors.BOLD+"[+] Link: "+limk+colors.ENDC)
ginti.append("[+] Link: "+limk)
for limk in form_links:
limk = urljoin(url,limk)
if target in limk and limk not in target_form:
temp_links.append(limk)
if externals == "Y" or externals == "y":
if limk not in target_form:
target_form.append(limk)
print(colors.HEADER+colors.BOLD+"[+] Form: "+limk+colors.ENDC)
ginti.append("[+] Form: "+limk)
elif externals == "N" or externals == "n":
if target in limk and limk not in target_form:
target_form.append(limk)
print(colors.HEADER+colors.BOLD+"[+] Form: "+limk+colors.ENDC)
ginti.append("[+] Form: "+limk)
for limk in xml_links:
limk = urljoin(url,limk)
if externals == "Y" or externals == "y":
if limk not in target_form:
target_form.append(limk)
print(colors.WARNING+colors.BOLD+"[+] Sitemap-Results: "+limk+colors.ENDC)
ginti.append("[+] Sitemap-Results: "+limk)
elif externals == "N" or externals == "n":
if target in limk and limk not in target_form:
target_form.append(limk)
print(colors.WARNING+colors.BOLD+"[+] Sitemap-Results: "+limk+colors.ENDC)
ginti.append("[+] Sitemap-Results: "+limk)
for limk in robo_links:
limk = urljoin(url,limk)
if externals == "Y" or externals == "y":
if limk not in target_robo:
target_robo.append(limk)
print(colors.OKCYAN+colors.BOLD+"[+] ROBOTS.TXT-Results: "+limk+colors.ENDC)
ginti.append("[+] ROBOTS.TXT-Results: "+limk)
elif externals == "N" or externals == "n":
if target in limk and limk not in target_robo:
target_robo.append(limk)
print(colors.OKCYAN+colors.BOLD+"[+] ROBOTS.TXT-Results: "+limk+colors.ENDC)
ginti.append("[+] ROBOTS.TXT-Results: "+limk)
async def crawl(urls):
rocky=[]
for i in urls:
rocky.append(i)
temp_links.clear()
my_conn = aiohttp.TCPConnector(limit=10)
async with aiohttp.ClientSession(connector=my_conn) as session:
tasks = []
for url in rocky:
task = asyncio.ensure_future(link_extractor(url=url,session=session))
tasks.append(task)
await asyncio.gather(*tasks,return_exceptions=True) # the await must be nest inside of the session
asyncio.run(crawl(target_url))
while True:
try:
asyncio.run(crawl(temp_links))
if len(temp_links)<=0:
print(colors.HEADER+colors.BOLD+"Finding Wayback Results ...")
with open(y+'/results.txt', 'a') as the_file:
for link in ginti:
the_file.write(link+'\n')
if waybacks=="Y" or waybacks=="y":
url = 'http://web.archive.org/cdx/search/cdx?url=*.'+target+'/*&output=txt&fl=original&collapse=urlkey'
r = requests.get(url)
results = r.text
print(colors.OKBLUE+colors.BOLD+"------------- [+] Way Back Result ------------")
print (results)
with open(y+'/wayback.txt', 'a') as the_file:
the_file.write(results)
the_file.close()
print(colors.HEADER+colors.BOLD+"[+] Done")
print(colors.OKCYAN+colors.BOLD+"[+] Total Discoveries: "+(str(len(ginti))))
sys.exit()
except KeyboardInterrupt:
print(colors.HEADER+colors.BOLD+"Finding Wayback Results ...")
with open(y+'/results.txt', 'a') as the_file:
for link in ginti:
the_file.write(link+'\n')
if waybacks=="Y" or waybacks=="y":
url = 'http://web.archive.org/cdx/search/cdx?url=*.'+target+'/*&output=txt&fl=original&collapse=urlkey'
r = requests.get(url)
results = r.text
print(colors.OKBLUE+colors.BOLD+"------------- [+] Way Back Result ------------")
print (results)
with open(y+'/wayback.txt', 'a') as the_file:
the_file.write(results)
the_file.close()
print(colors.FAIL+colors.BOLD+"[!] Scan Aborted By User.")
print(colors.OKCYAN+colors.BOLD+"[+] Total Discoveries: "+str(len(ginti)))
sys.exit()