-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mthread_LUKS_Bruteforce.py
executable file
·92 lines (78 loc) · 2.37 KB
/
Mthread_LUKS_Bruteforce.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
#!/usr/bin/python
import subprocess
import sys
from multiprocessing import Process, Manager
import time
from progressbar import AnimatedMarker, Bar, BouncingBar, Counter, ETA, FileTransferSpeed, FormatLabel, Percentage,ProgressBar, ReverseBar, RotatingMarker,SimpleProgress, Timer
import os
import commands
import re
def passw(passwd,return_list,headerfile):
try:
luks_file = headerfile
#print 'Trying %s...' % repr(passwd)
st = "cryptsetup luksOpen --test-passphrase "+passwd + " " + luks_file
r = subprocess.Popen('echo %s | cryptsetup luksOpen --test-passphrase %s ' % (passwd, luks_file), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = r.communicate()
if len(err) == 0:
return_list[0]="true"
return_list[1]=repr(passwd)
return []
except:
sys.exit(1)
def main(headerfile,uni):
uni = open(uni,"r")
headerfile = headerfile
words = []
jobs=[]
luks_file = uni
manager = Manager()
return_list = manager.list(range(2))
for lines in uni:
lines = lines.strip()
pattern = r'[^\.\w\!]'
sa = re.search('[^\.\w\!]', lines)
if not sa and len(lines) > 2:
words.append(lines)
print "trying ",len(words), "potential passwords"
words.reverse()
nowtime = time.time()
widgets = ['Cracking LUKS-header: ', Percentage(), ' ', Bar(marker="|"), ' ', ETA(),]
pbar = ProgressBar(widgets=widgets, maxval=len(words)).start()
for i,passwd in enumerate(words):
pbar.update(i+1)
t = Process(target=passw, args = (passwd,return_list,headerfile,))
jobs.append(t)
if len(jobs) == 10 or (i == len(words)-1):
for job in jobs:
job.start()
if (len(jobs) == 10) or (i == len(words)-1):
#print "merge"
for job in jobs:
job.join()
jobs=[]
if "true" in return_list:
i = len(words)
pbar.update(i)
break
pbar.finish()
print "time used: ", (time.time() - nowtime) / 60,"Min"
if "true" not in return_list:
print "No password found"
else:
print "password is ",return_list[1]
return 0
if __name__ == '__main__':
if len(sys.argv) < 2:
sys.stderr.write("Need a headerfile \n")
sys.exit(1)
headerfile = sys.argv[1]
if len(sys.argv) < 3:
sys.stderr.write("Need a file containing potential passwords \n")
sys.exit(1)
uni = sys.argv[2]
try:
main(headerfile,uni)
except KeyboardInterrupt:
print "############ got controll + c, exiting ############"
sys.exit(1)