-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathweaver.py
278 lines (250 loc) · 10.6 KB
/
weaver.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
try:
import requests
import sys
import time
from queue import Queue
import os
# from progress.bar import Bar
# from progress.spinner import PixelSpinner
import threading
from requests.exceptions import ConnectionError
except ImportError:
import os
os.system('pip install -r requirements.txt')
import requests
import sys
import time
import os
# from progress.bar import Bar
# from progress.spinner import PixelSpinner
import threading
from requests.exceptions import ConnectionError
class ProgrssBar:
class Bar:
def __init__(self, max_value, title, char, length, unit):
self.__title = title
self.__char = char
self.__len = length
self.speed = 0
self.__fill = 0
self.max = max_value
self.value = 0
self.percent = 0
self.unit = unit
def string(self):
self.percent = round(self.value / self.max * 100)
if self.percent > 100:
self.percent = 100
self.__fill = round(self.percent * self.__len / 100)
return "{} |{}{}| {}/{} ({}%) {} {}/s".format(self.__title,
self.__fill * self.__char,
(self.__len - self.__fill) * " ",
self.value, self.max, self.percent,
self.speed, self.unit)
def __init__(self, max_value, title="Loading", char="█", length=70, unit="", multiplyer=1):
self.bar = self.Bar(max_value, title, char, length, unit)
self.multiplyer = multiplyer
def set_value(self, value):
self.bar.value = value
def inc_value(self, increment=1):
self.bar.value += increment
def show_progress(self):
def monitor_speed():
value_start = self.bar.value
start = time.time()
time.sleep(1)
self.bar.speed = int((self.bar.value - value_start) / (time.time() - start) * self.multiplyer)
t = threading.Thread(target=monitor_speed, daemon=True)
t.start()
print()
while self.bar.percent < 100:
try:
print(self.bar.string(), end="\r")
time.sleep(0.1)
except KeyboardInterrupt:
raise NameError
print()
class DirBruter:
def __init__(self, target_url, wordlist_file):
requests.packages.urllib3.disable_warnings() # Mute SSL-Errors
self.running = True
self.__found_directories = []
self.__redirect_directories = []
self.__error500_directories = []
self.__forbidden_directories = []
self.__timeout = 1
self.__headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'}
self.__target = target_url
self.__wordlist = wordlist_file
self.__wordlist_list = list(open(self.__wordlist))
self.__threads = []
self.__count = 0
self.__robots_path_count = 0
self.__not_found_count = 0
self.__check_redirect()
self.__check_robots()
self.__wordlist_count()
self.__verify_ssl_cert()
self.__dirs = Queue()
self.PB = ProgrssBar(int(self.__count), unit="dirs")
def __verify_ssl_cert(self):
try:
_ = requests.get(target + "/robots.txt", headers=self.__headers, verify=True)
except requests.exceptions.SSLError:
_ = input("[!] The SSL certificate cannot be verified. Continue? (y/n) [y]:")
if _:
if _ != "y":
print("[!] Aborting. SSL certificate not trusted.")
sys.exit()
else:
pass
def __check_robots(self):
try:
sys.stdout.write("[+] Checking for a robots.txt\n")
html = requests.get(target + "/robots.txt", headers=self.__headers, verify=False)
html_text = html.text
if html.status_code == 200:
for line in html_text.split("\n"):
if line.startswith("Disallow: "):
self.__wordlist_list.append(str(line.split(":")[1]))
self.__robots_path_count += 1
sys.stdout.write("[+] Wrote contents of robots.txt into wordlist\n")
else:
raise Exception
except:
sys.stdout.write("[+] No robots.txt found\n")
def __wordlist_count(self):
for _ in self.__wordlist_list:
self.__count += 1
if self.__robots_path_count != 0:
self.__count += self.__robots_path_count
sys.stdout.write("[ ] Wordlist length: %d\n" % self.__count)
def __urlenum(self): # Interprets HTTP Status Codes & sorts into lists
while self.__dirs.qsize() > 0:
current_dir = self.__dirs.get()
if self.running:
try:
current_dir = current_dir.replace('\n','')
s = requests.get(target + "/" + current_dir, headers=self.__headers, verify=False, timeout=3)
if '404' in str(s.text):
self.__not_found_count = self.__not_found_count + 1
pass
else:
if 'Not' and 'Found' in str(s.text):
self.__not_found_count = self.__not_found_count + 1
pass
else:
if str(s.status_code).startswith("2"):
self.__found_directories.append(current_dir)
else:
if s.status_code == 200:
self.__found_directories.append(current_dir)
else:
pass
if str(s.status_code).startswith("5"):
self.__error500_directories.append(current_dir)
else:
pass
if str(s.status_code).startswith("4"):
if s.status_code == 404:
self.__not_found_count = self.__not_found_count + 1
else:
self.__forbidden_directories.append(current_dir)
else:
pass
if str(s.status_code).startswith("3"):
self.__found_directories.append(current_dir)
else:
pass
except KeyboardInterrupt:
pass
except requests.exceptions.ConnectionError:
pass
except requests.exceptions.Timeout:
pass
except Exception as e:
print(e)
pass
self.PB.inc_value()
else:
break
def __check_redirect(self):
r = requests.get(self.__target, verify=False)
if r.url != (self.__target + "/"):
sys.stdout.write("[ ] You got redirected to %s\n" % (str(r.url)))
follow_redirect = input("[ ] Want to follow? y/n : ")
if follow_redirect == 'y':
self.__target = r.url
sys.stdout.write("[+] Followed redirect: %s" % self.__target)
else:
pass
def run(self): # Starts threads and prints lists
with open(self.__wordlist) as dirs:
try:
sys.stdout.write("\n[+] Starting Directory Bruteforcer\n\n")
for dir_ in dirs:
self.__dirs.put(dir_)
# starting threads
for onedir in range(int(sys.argv[3])):
t = threading.Thread(target=self.__urlenum, daemon=True)
t.start()
self.__threads.append(t)
try:
self.PB.show_progress()
except NameError:
raise TypeError # print results
raise TypeError # print results
except KeyboardInterrupt:
raise TypeError
except TypeError:
# print results
print("\n")
for directory in self.__found_directories:
sys.stdout.write("[+] %s/%s\n" % (target, directory))
if not self.__found_directories:
sys.stdout.write("[+] Code 200 : 0")
else:
pass
if self.__error500_directories:
for response in self.__error500_directories:
sys.stdout.write("[+] Code 500: %s/%s" % (target, response))
if self.__forbidden_directories:
for directory in self.__forbidden_directories:
sys.stdout.write("[+] Forbidden: %s/%s" % (target, directory))
sys.stdout.write("\n[+] 404 received: %d" % self.__not_found_count)
# empty queue and wait for threads
self.running = False
print("\n[ ] Waiting for threads ...")
for t in self.__threads:
t.join()
print("_________________________________")
sys.exit()
if __name__ == '__main__':
if len(sys.argv) < 4:
sys.stdout.write("[-] You forgot to add an argument!\n")
sys.stdout.write("[ ] Usage: python weaver.py <example.com> <wordlist.txt> <threads>\n")
sys.exit()
target = sys.argv[1]
wordlist = sys.argv[2]
print("""
____ ,
/---.'.__ ____//
'--.\ /.---'
_______ \\ //
/.------.\ \| .'/ ______
// ___ \ \ ||/|\ // _/_----.\__
|/ /.-.\ \ \:|< >|// _/.'..\ '--'
// \'. | \'.|.'/ /_/ / \\
// \ \_\/" ' ~\-'.-' \\
// '-._| :H: |'-.__ \\
// (/'==='\)'-._\ ||
|| \\ \|
|| \\ '
|/ \\
Weaver v.3.0 ||
||
\\
'
""")
Bruter = DirBruter(target_url=target, wordlist_file=wordlist)
Bruter.run()