-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirfy.py
212 lines (182 loc) · 7.38 KB
/
dirfy.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
#!/usr/bin/python3
#
# dirfy
# an async webpath scanner based on asyhttp
#
# Version: 0.1
# Author: pyno
#
import sys, getopt
from asyhttp import loop
from dye import *
import threading
ver = "0.1"
global_progress = 0
global_total = 0
progress_lock = threading.BoundedSemaphore()
LOG_ENABLED = True
logfile = None
def read_file(filepath):
try:
with open(filepath, "r") as file:
return [f for f in file.readlines()]
except Exception as e:
print(e)
def print_help():
print(" Usage:")
print(" -u <url> :- target URL")
print(" -e <extensions> :- comma separated extension list")
print(" -p <proxy> :- proxy string (e.g. http://myproxy:8080)")
print(" -d <dict_file> :- dictionary file (default is list.txt)")
print(" -f <false_positives_file> :- file containing strings that indicate false positives")
print(" -c <max_concurrent> :- maximum number of concurrent requests (default 1000)")
print(" -r :- follow redirects")
print(" -n :- disable logging")
print(" -H <header_file> :- file containing HTTP headers")
def main(argv):
arg_exts = ""
arg_proxy_url = ""
arg_ext_list = ""
wordlist_path = "./list.txt"
arg_max_concurrent = 1000
arg_allow_redirects = False
fps = []
fps_file = ""
arg_header_file = ""
sys.stdout.write(" ----------------------\n")
sys.stdout.write(" dirfy v{}".format(ver)+"\n")
sys.stdout.write(" ----------------------\n")
try:
opts, args = getopt.getopt(argv,"hu:e:p:d:f:c:rnH:",[
"url=","extensions=","proxy=",
"dict=","false-positives=,max-concurrent=",
"follow-redirects", "disable-log",
"header-file"
])
except getopt.GetoptError as goe:
print(fg.RED+' [!] '+str(goe)+'\n'+fg.RESET)
print_help()
sys.exit(2)
if(opts == []):
print_help()
sys.stdout.write(" ----------------------\n")
sys.exit(0)
for opt, arg in opts:
if opt == '-h':
print_help()
sys.exit()
elif opt in ("-u", "--url"):
arg_url = arg
elif opt in ("-p", "--proxy"):
arg_proxy_url = arg
elif opt in ("-e", "--extensions"):
arg_exts = arg
arg_ext_list = arg_exts.split(",")
elif opt in ("-d", "--dict"):
wordlist_path = arg
elif opt in ("-f", "--false-positives"):
fps_file = arg
fps = [fp.rstrip('\n') for fp in open(fps_file,'r').readlines()]
elif opt in ("-c", "--max-concurrent"):
arg_max_concurrent = int(arg)
elif opt in ("-r", "--follow-redirects"):
arg_allow_redirects = True
elif opt in ("-n" "--disable-log"):
global LOG_ENABLED
LOG_ENABLED=False
elif opt in ("-H" "--header-file"):
arg_header_file = arg
if LOG_ENABLED:
global logfile
logfile = open('./log.txt','a')
if arg_header_file != '':
headers = {line.split(':')[0]:line.split(':')[1].rstrip('\n') for line in open(arg_header_file).readlines()}
else:
headers = ''
path_list = [d for d in read_file(wordlist_path)]
target=arg_url+"/{}"
url_dict_list = []
for path in path_list:
if "%EXT%" in path:
for ext in arg_ext_list:
repl_path = path.replace('%EXT%',ext)
url_dict = {}
url_dict["url"] = target.format(repl_path[:-1])
url_dict["method"] = "GET"
url_dict["headers"] = headers
url_dict_list.append(url_dict)
else:
url_dict = {}
url_dict["url"] = target.format(path[:-1])
url_dict["method"] = "GET"
url_dict["headers"] = headers
url_dict_list.append(url_dict)
global global_total
global_total = len(url_dict_list)
sys.stdout.write(fg.HBLUE+" [i] tARGET {}{}\n".format(fg.RESET,arg_url))
sys.stdout.write(fg.HBLUE+" [i] eXTENSIONS "+fg.RESET+"{}".format(arg_ext_list)+"\n")
sys.stdout.write(fg.HBLUE+" [i] pROXY "+fg.RESET+"{}".format(arg_proxy_url)+"\n")
sys.stdout.write(fg.HBLUE+" [i] wORDLIST "+fg.RESET+"{} ({})".format(wordlist_path,
len(url_dict_list))+"\n")
if len(fps) > 0:
sys.stdout.write(fg.HBLUE+" [i] fALSE pOSITIVES "+fg.RESET+"{} ({})".format(fps_file,
len(fps))+"\n")
else:
sys.stdout.write(fg.HBLUE+" [i] fALSE pOSITIVES "+fg.RESET+"\n")
sys.stdout.write(fg.HBLUE+" [i] mAX cONCURRENT rEQUESTS "+fg.RESET+"{}".format(arg_max_concurrent)+"\n")
sys.stdout.write(fg.HBLUE+" [i] aLLOW rEDIRECTS "+fg.RESET+"{}".format(arg_allow_redirects)+"\n")
input("\n [+] pRESS a kEY tO cONTINUE..")
print("\n")
try:
loop(url_dict_list,process_out=process_output, proxy=arg_proxy_url, redirects=arg_allow_redirects,
max_concurrent=arg_max_concurrent,
usrdata={'false_positives':fps})
except KeyboardInterrupt as ki:
sys.stdout.write(fg.RED+"\n\n [!] eXITING"+fg.RESET)
sys.stdout.flush()
if LOG_ENABLED:
logfile.flush()
logfile.close()
sys.stdout.write("\n [+] bYE")
sys.stdout.write("\n")
def show_progress():
global global_progress
global global_total
global progress_lock
reqs_for_a_block = global_total / 20
# critical section
progress_lock.acquire()
global_progress += 1
num_blocks = int(global_progress / reqs_for_a_block)
progress_lock.release()
# end critical section
sys.stdout.write("\r [+] |{}{}| - {}/{} ".format(bg.GREEN+" "*(num_blocks)+bg.RESET,
" "*(20-num_blocks),
global_progress, global_total))
sys.stdout.flush()
def is_fp(resp, fps):
for fp in fps:
try:
if fp in resp.decode("UTF-8"):
return True
except UnicodeDecodeError as ude:
return False
return False
def LOG(s):
if LOG_ENABLED:
logfile.write(s)
logfile.flush()
logfile.write(s)
logfile.flush()
def process_output(url,return_code,reason,resp_body, usrdata):
show_progress()
#if return_code == 404:
resp_length = len(resp_body)
if return_code == 200 and not is_fp(resp_body, usrdata['false_positives']) and resp_length > 0:
sys.stdout.write("\r "+fg.HYELLOW+'{:<6}'.format(resp_length)+fg.RESET+" [ "+str(return_code)+" - "+reason+" ]")
sys.stdout.write(fg.BLUE+' {:<40}'.format(url)+fg.RESET)
sys.stdout.write("\n")
LOG(" {:<6}".format(resp_length)+" [ "+str(return_code)+" - "+reason+" ]" + ' {:<40}\n'.format(url))
#LOG(' {:<40}\n'.format(url))
if __name__ == "__main__":
main(sys.argv[1:])