-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcollector.py
197 lines (179 loc) · 6.99 KB
/
collector.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
__Name__ = "Collector"
__Description__ = "Collect XSS vulnerable parameters from entire domain."
__Author__ = "Md. Nur Habib"
__Version__ = "1.0.0"
# Import mdules
from multiprocessing import Manager
import os
import sys
import argparse
from plugins.banner import *
import requests
import warnings
import urllib.parse
import socket
import multiprocessing
warnings.filterwarnings("ignore")
Bannerfunction()
parser = argparse.ArgumentParser(description=f"{bold}{green}=============== Help Menu ===============")
parser.add_argument(
"function", help=f"\t\t`pull` or `check`")
parser.add_argument("--host", help="\tDomain/Host Name")
parser.add_argument(
"--threads", help="\t\tThe number of threads", default=5)
parser.add_argument(
"--with-subs", help="\t\t`yes` or `no`", default=True)
parser.add_argument(
"--loadfile", help="\t\tFile location")
parser.add_argument(
"--outputfile", help=f"\t\tSaving Path{reset}")
args = parser.parse_args()
def waybackurlsFunction(host, with_subs):
if with_subs:
url = f"http://web.archive.org/cdx/search/cdx?url=*.{host}/*&output=list&fl=original&collapse=urlkey"
else:
url = f"http://web.archive.org/cdx/search/cdx?url={host}/*&output=list&fl=original&collapse=urlkey"
requestsVariable = requests.get(url)
if args.outputfile:
openFileVariable = open(args.outputfile, "w")
openFileVariable.write(requestsVariable.text.strip())
openFileVariable.close()
print(requestsVariable.text.strip())
def checkGivvenDomainNameFunction(url):
global timeOutGlobalVariable
if url == "":
return
url = url.replace(":80/", "/").replace(":443/", "/")
if not url.startswith("http"):
url = f"http://{url}"
domainName = urllib.parse.urlparse(url).netloc.split(":")[0]
if domainName in timeOutGlobalVariable:
return
try:
requestVariablTwo = requests.head(
url, verify=False, timeOutGlobalVariable=.25)
except requests.exceptions.timeOutGlobalVariable:
timeOutGlobalVariable.append(domainName)
return
except requests.exceptions.ConnectionError:
timeOutGlobalVariable.append(domainName)
return
if str(requestVariablTwo.status_code)[0] == "3" and url.startswith("http://") and requestVariablTwo.headers["Location"].startswith("https://"):
try:
requestVariablTwo = requests.head(
f"https{url[4:]}", verify=False, timeOutGlobalVariable=.25)
except requests.exceptions.timeOutGlobalVariable:
return
statusCodeVariable = requestVariablTwo.status_code
if statusCodeVariable == 404:
return
if "Content-Length" in list(requestVariablTwo.headers.keys()):
cLength = requestVariablTwo.headers["Content-Length"]
else:
cLength = "Unknown"
if "Content-Type" in list(requestVariablTwo.headers.keys()):
cType = requestVariablTwo.headers["Content-Type"]
else:
cType = "Unknown"
if str(statusCodeVariable)[0] == "3":
rUrl = requestVariablTwo.headers["Location"]
print(", ".join([url, str(statusCodeVariable), cLength, cType, rUrl]))
if args.outputfile:
writeQueueVariable.put(
", ".join([url, str(statusCodeVariable), cLength, cType, rUrl])+"\n")
else:
print(", ".join([url, str(statusCodeVariable), cLength, cType]))
if args.outputfile:
writeQueueVariable.put(
", ".join([url, str(statusCodeVariable), cLength, cType])+"\n")
def checkGivvenDomainNameFunctionValidDomain(endpoints):
validDomains = []
invalidDomainNames = []
validEndpoints = []
for endpoint in endpoints:
endpoint = endpoint.strip().strip("\r").strip(""").strip(""")
try:
parsedUrl = urllib.parse.urlparse(endpoint)
domainName = parsedUrl.netloc.split(":")[0]
if domainName in validDomains:
validEndpoints.append(endpoint)
continue
elif domainName in invalidDomainNames:
continue
try:
socket.gethostbyname(domainName)
validDomains.append(domainName)
validEndpoints.append(endpoint)
except:
invalidDomainNames.append(domainName)
except:
continue
return validEndpoints
def writterFunction(fileToWrite):
while True:
line = writeQueueVariable.get(True)
if line == None:
break
fileToWrite.write(line)
Manager = multiprocessing.Manager()
timeOutGlobalVariable = Manager.list()
writeQueueVariable = Manager.Queue()
pool = multiprocessing.Pool(args.threads)
if args.function == "pull":
if args.host:
print(f'\n{bold}{green}Fetching URLs, It"s take some time Please Wait...{reset}\n')
waybackurlsFunction(args.host, args.with_subs)
elif args.loadfile:
for line in open(args.loadfile).readlines():
waybackurlsFunction(line.strip(), args.with_subs)
elif args.function == "checkGivvenDomainNameFunction":
if args.loadfile:
try:
if args.outputfile:
outputfile = open(args.outputfile, "w", 0)
p = multiprocessing.Process(
target=writterFunction, args=(outputfile,))
p.start()
endpoints = checkGivvenDomainNameFunctionValidDomain(
open(args.loadfile).readlines())
pool.map(checkGivvenDomainNameFunction, endpoints)
if args.outputfile:
writeQueueVariable.put(None)
p.join()
outputfile.close()
except IOError as error:
print(f"{bold}{red}Sorry,{reset} File not found!")
sys.exit(1)
except KeyboardInterrupt as error:
print(f"{bold}{red}Killing processes.{reset}")
pool.terminate()
sys.exit(1)
except Exception as error:
print(f"{bold}{red}An error occurred: {error}")
elif not sys.stdin.isatty():
try:
if args.outputfile:
outputfile = open(args.outputfile, "w", 0)
p = multiprocessing.Process(
target=writterFunction, args=(outputfile,))
p.start()
endpoints = checkGivvenDomainNameFunctionValidDomain(
sys.stdin.readlines())
pool.map(checkGivvenDomainNameFunction, endpoints)
if args.outputfile:
writeQueueVariable.put(None)
p.join()
outputfile.close()
except IOError as error:
print(f"{bold}{red}An error occurred: {error}")
print(f"{bold}{red}File not found!{reset}")
sys.exit(1)
except KeyboardInterrupt as error:
print(f"{bold}{red}Killing processes.{reset}")
pool.terminate()
sys.exit(1)
except Exception as error:
print(f"{bold}{red}An error occurred: {error}")
else:
print(f"{bold}{red}Please either specify a file.{reset}")
exit()