-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelliot.py
259 lines (241 loc) · 10.6 KB
/
elliot.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
#!/usr/bin/python3
import re
import hashlib
from multiprocessing.pool import Pool
import itertools
import string
import argparse
import os
import sys
import time
lower = string.ascii_lowercase
upper = string.ascii_uppercase
num = string.digits
symbols = "!@#$%^&*?,()-=+[]/;"
defaultwordlist = "wordlist/rockyou.txt"
def timer(start, end):
hours, rem = divmod(end-start, 3600)
minutes, seconds = divmod(rem, 60)
return "{:0>2}:{:0>2}:{:05.2f}".format(int(hours), int(minutes), seconds)
def resumecrack(sessionfile):
if os.path.exists(sessionfile):
try:
with open(sessionfile, "r") as file:
data = file.read().splitlines()
mode = data[0]
if mode == "wordlist":
hashtocrack = data[1]
wordlistpath = data[2]
lin = data[3]
outputfile = data[4]
ext(wordlistpath, hashtocrack, outputfile,
linetoresume=int(lin), sessionfile=sessionfile)
elif mode == "incremental":
hashtocrack = data[1]
min_lenght, max_lenght = data[2].split(" ")
current_i = data[3]
current = data[4][:1]
c = data[5].find(current)
remove = data[5][:c]
remain_c = data[5].replace(remove, "")
characters = remain_c + remove
outputfile = data[6]
customcrack(characters, int(current_i), int(
max_lenght), hashtocrack, outputfile, sessionfile=sessionfile)
elif mode == "wordlist,incremental":
pass
file.close()
except Exception as error:
print(error)
sys.exit()
def customcrack(chrs, min_lenght, max_length, hashtocrack, outputfile, sessionfile=None):
check = bool(re.match(r"([a-fA-F\d]{32}$)", hashtocrack))
if check:
try:
starting_time = time.time()
for n in range(min_lenght, max_length + 1):
for x in itertools.product(chrs, repeat=n):
password = "".join(x)
# print(first_bits)
try:
print(
f"\rtrying password : {password}", end='\r', flush=True)
hash = hashlib.md5(
password.encode("UTF-8")).hexdigest()
if hash == hashtocrack:
print("\r\nPassword : " + str(password))
with open(outputfile, "w") as ou:
ou.write(password)
break
if sessionfile != None and "00:05:00" in timer(starting_time, time.time()):
with open(sessionfile, "w") as file:
file.write(
f"incremental\n{hashtocrack}\n{min_lenght} {max_length}\n{n}\n{password}\n{characters}\n{outputfile}")
starting_time = time.time()
except Exception as error:
print(error)
sys.exit()
except KeyboardInterrupt:
if sessionfile != None:
with open(sessionfile, "w") as file:
file.write(
f"incremental\n{hashtocrack}\n{min_lenght} {max_length}\n{n}\n{password}\n{characters}\n{outputfile}")
sys.exit()
else:
print(hashtocrack + " is not the md5 hash")
def ext(wordlist, hashtocrack, outputfile, linetoresume=None, sessionfile=None):
check = bool(re.match(r"([a-fA-F\d]{32}$)", hashtocrack))
if check:
try:
with open(wordlist, "r") as file:
data = file.read().splitlines()
if linetoresume != None:
print("Loaded lines : " + str(len(data)))
print("resuming from lines : " + str(linetoresume))
data = data[linetoresume:]
file.close()
except Exception as error:
if "No such file" in str(error):
print("[*_*] No such file")
sys.exit()
starting_time = time.time()
for password in data:
linenumber = data.index(password)
try:
try:
print(
f"\rtrying password No : {linenumber}", end='\r', flush=True)
hash = hashlib.md5(password.encode("UTF-8")).hexdigest()
if hash == hashtocrack:
print("\r\nPassword : " + str(password))
with open(outputfile, "w") as ou:
ou.write(password)
break
if sessionfile != None and "00:05:00" in timer(starting_time,time.time()):
with open(sessionfile, "w")as file:
file.write(
f"wordlist\n{hashtocrack}\n{wordlist}\n{linenumber}\n{outputfile}")
starting_time = time.time()
except Exception as error:
print(error)
sys.exit()
except KeyboardInterrupt as error:
if sessionfile != None:
with open(sessionfile, "w")as file:
file.write(
f"wordlist\n{hashtocrack}\n{wordlist}\n{linenumber}\n{outputfile}")
print("\nAttact is stopped at " + str(linenumber))
sys.exit()
else:
print(hashtocrack + " is not md5 hash")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-w", dest="wordlist",
help="Path of wordlist")
parser.add_argument("--min", type=int, dest="min",
help="minimum lenght of chars")
parser.add_argument("--max", type=int, dest="max",
help="maximum lenght of chars")
parser.add_argument("--char", "-c", dest="chars",
help="""characters to use in brute force using incremental mode\n
avaliable :
[
lower
upper
num
symbol ]
use (,) to use together like lower,num
""")
parser.add_argument("-t", dest="hash", help="md5hash to crack")
parser.add_argument("-n", dest="newsession",
help="Session name with path")
parser.add_argument("-r", dest="resumesession",
help="Path of session file")
parser.add_argument("--output", "-o", dest="outputfile",
help="Path of output file where password will store after cracking it")
args = parser.parse_args()
l = {"lower": lower, "upper": upper, "num": num, "symbol": symbols}
result = []
p = Pool()
characters = ""
if args.resumesession != None:
if args.hash or args.outputfile or args.min or args.max or args.chars or args.wordlist == None:
try:
result.append(p.apply_async(resumecrack(args.resumesession)))
p.close()
p.join()
except Exception as error:
print(error)
sys.exit()
else:
print("[_] -r can only be use alon")
elif args.hash == None:
parser.print_help()
elif args.outputfile == None:
parser.print_help()
elif args.wordlist and args.chars != None:
print("First I perform wordlist attack then incremental mode")
if args.min and args.max != None:
try:
if args.min > args.max:
print("[-_-] --max must be equal or greater the --min")
sys.exit()
ch = args.chars.split(",")
for c in ch:
if c in l:
characters += l[c]
else:
print("charset " + str(c) + " not in list")
sys.exit()
print(
f"performing attact with {args.wordlist} and '{characters}'")
result.append(p.apply_async(
ext(args.wordlist, args.hash, args.outputfile, sessionfile=args.newsession)))
result.append(p.apply_async(customcrack(
characters, args.min, args.max, args.hash, args.outputfile, sessionfile=args.newsession)))
p.close()
p.join()
# ext(args.wordlist, args.hash,args.outputfile,sessionfile=args.newsession)
# customcrack(characters,args.min,args.max,args.hash,args.outputfile,sessionfile=args.newsession)
except Exception as error:
print(str(error))
else:
print("[-*-] -c/--chars need --min and --max")
elif args.chars != None:
if args.min and args.max != None:
try:
if args.min > args.max:
print("[-_-] --max must be equal or greater the --min")
sys.exit()
ch = args.chars.split(",")
for c in ch:
if c in l:
characters += l[c]
else:
print("charset " + str(c) + " not in list")
sys.exit()
print(f"performing attact with '{characters}'")
result.append(p.apply_async(customcrack(
characters, args.min, args.max, args.hash, args.outputfile, sessionfile=args.newsession)))
p.close()
p.join()
except Exception as error:
print(str(error))
else:
print("--char/-c need --max and --min both")
elif args.wordlist and args.min or args.max != None:
print("wordlist not require --min or --max")
elif args.wordlist != None:
print("performing wordlist attack")
result.append(p.apply_async(ext(args.wordlist, args.hash,
args.outputfile, sessionfile=args.newsession)))
p.close()
p.join()
elif args.min or args.max != None:
print(" --min or --max need -c/--char")
else:
print("performing with default wordlist")
result.append(p.apply_async(ext(defaultwordlist, args.hash,
args.outputfile, sessionfile=args.newsession)))
p.close()
p.join()