-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamcrack.py
55 lines (44 loc) · 1.48 KB
/
samcrack.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
import os, sys
from passlib.hash import lmhash, nthash
def main():
if sys.platform == 'win32':
os.system('cls')
else:
os.system('clear')
if len(sys.argv) != 3:
sys.exit('\r\nUsage: <wordlist> <sam-file>\r\n')
wordlist = []
sam_hashes = []
print('Importing wordlist...')
try:
with open(sys.argv[1], 'r') as f:
wordlist = f.read().splitlines()
except Exception as ex:
sys.exit(f"Error: {ex}")
print('Importing SAM file...')
try:
with open(sys.argv[2], 'r', encoding='utf-8') as f:
sam_hashes = f.read().splitlines()
except Exception as ex:
sys.exit(f"Error: {ex}")
print('Extracting SAM hashes...')
hashes = {}
for line in sam_hashes:
if ':' in line:
username, hash_value = line.split(':', 1)
hashes[username] = hash_value.strip()
print('\r\nCracking! Please be patient...\r\n')
for username, hash_value in hashes.items():
for password in wordlist:
# use UTF-16 when generating hash
try:
ntlm_hash = nthash.hash(password)
except Exception as ex:
print(f"Error: {ex}")
continue
if ntlm_hash == hash_value.lower():
print(f'Password "{password}" found for user "{username}"')
break
print('\r\nDone.\r\n')
if __name__ == "__main__":
main()