-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDIRX.py
More file actions
258 lines (174 loc) · 6.33 KB
/
DIRX.py
File metadata and controls
258 lines (174 loc) · 6.33 KB
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
#!/usr/bin/python3
# Copyright 2019, Aniket.N.Bhagwate, All rights reserved.
# Date Created : 25 APRIL 2020
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import urllib.request, urllib.error
import os
import argparse
import sys
import threading
banner="""
____ ___ ____ __ ______
| _ \_ _| _ \ \ \/ / / /
| | | | || |_) | \ / / /
| |_| | || _ < / \ \ \
|____/___|_| \_\/_/\_\_\_\\
+=============================+
+-- Directory Bruteforce --+
+=============================+
+ Code by : Aniket Bhagwate +
+=============================+
"""
print(banner)
def bforce(response_code,collection,f,url,word,out,start,stop):
w = word.split("/")[-1:]
if url[-1:]=='/':
pass
else:
url = url+'/'
cnt = 0
for x in range(start,stop+1):
os.system("clear")
print(banner)
print("[*] Using Wordlist : \033[30;42m" + "{}".format(w) + "\033[m")
print("[*] Total Words : {}".format(len(f)))
print("[*] Active Threads : [4]\n")
cnt = cnt+1
u = url + f[x]
try:
for c in collection:
print(c)
print("+----------------------------------------------------------------------------------------+")
print("------------------------------------------------_=_TESTING : \033[30;42m {} \033[m ------".format(u))
conn = urllib.request.urlopen(u)
except urllib.error.HTTPError as e:
# 300 , 404 ......
if e.code==404: #or e.code==403:
pass
else:
temp = u + " ==> ( {} ) ".format(e.code) + " < {} > ".format(response_code["{}".format(e.code)])
collection.append(temp)
except urllib.error.URLError as e:
pass
#print(u + "( {} )".format(e.reason))
else:
#200
temp = u + " ==> ( {} )".format(conn.code) + " < {} > ".format(response_code["{}".format(conn.code)])
collection.append(temp)
def main():
########################################## Response Codes ---
rcode = open("Response_Codes.txt","r")
rcode = rcode.read().split("\n")
rcode.pop()
response_code={}
for res in rcode:
res = res.split("_")
response_code['{}'.format(res[0])] = res[1]
####################################################################################
collection=['']
parser = argparse.ArgumentParser(description="Bruteforce Websites")
parser.add_argument('-u','--url',metavar='',required=True , help='URL for Bruteforce ')
parser.add_argument('-w','--wordlist',metavar='',required=False,help='Wordlist to use for bruteforce',)
parser.add_argument('-o','--output',metavar='',required=False,help='File name to write the output')
args = parser.parse_args()
url = args.url
################################## To check if user has selected a wordlist
if args.wordlist==None :
word = "common.txt"
else:
word=args.wordlist
####################################################################
################################## To check if user has selected Output file
if args.output==None :
out = None
else:
out=args.output
####################################################################
################################## To check proper required url format
try:
val = url.split(":")[1]
except:
print('Improper URL format ! ')
print('\nFORMAT : http/https://<URL>')
sys.exit()
####################################################################
f = open(word,'r',encoding="ISO-8859-1")
f = f.read().split("\n")
f.pop()
###################################### Divide words by index from wordlist and allot threads
num = 4 # no of threads
val=len(f) # no of words in wordlist
tem = round((val/num))
temp = val - tem*num
lis=[]
for x in range(num):
if x==num-1:
lis.append(round(val/num)+temp)
break
lis.append(round(val/num))
l = lis[x]-lis[x]
h = lis[x]-1
val = lis[0]
dic=[]
dic.append(str(l)+"_"+str(h))
try:
for x in range(len(lis)):
l = h+1
h = h+lis[x]
dic.append(str(l)+"_"+str(h))
except:
pass
dic.pop()
############################################################################
#url,word,out,start,stop
# temporary value for out
###################################### Threads
x1 = threading.Thread(target=bforce, args=(response_code,collection,f,url,word,out,int(dic[0].split("_")[0]),int(dic[0].split("_")[1])))
x2 = threading.Thread(target=bforce, args=(response_code,collection,f,url,word,out,int(dic[1].split("_")[0]),int(dic[1].split("_")[1],)))
x3 = threading.Thread(target=bforce, args=(response_code,collection,f,url,word,out,int(dic[2].split("_")[0]),int(dic[2].split("_")[1],)))
x4 = threading.Thread(target=bforce, args=(response_code,collection,f,url,word,out,int(dic[3].split("_")[0]),int(dic[3].split("_")[1],)))
######################################
###################################### Start threads
x1.start()
os.system("clear")
x2.start()
os.system("clear")
x3.start()
os.system("clear")
x4.start()
os.system("clear")
print(banner)
######################################
###################################### Join threads
x1.join()
x2.join()
x3.join()
x4.join()
######################################
if out!=None:
os.system("clear")
print(banner)
print("\n\n \033[30;42m [!] Generating Output File....... : < {} > \033[m\n".format(out))
f = open("{}".format(out) , "a")
for x in collection:
f.write(x + "\n")
f.close()
sys.exit()
os.system("clear")
print(banner)
print("+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+")
for x in collection:
print("[ - ]" + "\t" + x)
print("+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+")
if __name__ == "__main__":
main()