-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinShad.py
More file actions
76 lines (59 loc) · 2.12 KB
/
Copy pathlinShad.py
File metadata and controls
76 lines (59 loc) · 2.12 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
#!/usr/bin/env python3
"""
Created by atinfosec
Title: Linux Shadow Cracker
Description: This script cracks linux shadow file using bruteforce technique.
This script needs root privileges if you are cracking shadow file directly
"""
import crypt
import threading
import argparse
screenLock = threading.BoundedSemaphore(1) # Semaphore to lock screen so that each thread gets screen to print at a time
def crackFile(password,salt,dictPass):
cryptWord = crypt.crypt(dictPass,salt)
screenLock.acquire()
print('[+] Testing for {} .....'.format(dictPass))
if cryptWord == password:
crackedPass = dictPass
print('Password Found!!!!!')
print(crackedPass)
exit(0) # if password found then script ends all threads/daemons stops
screenLock.release()
def main():
parser = argparse.ArgumentParser(description='Crack passwords by bruteforcing a shadow formatted file')
parser.add_argument('user',help='User to crack')
parser.add_argument('shadow',help='Shadow file to crack')
parser.add_argument('dictionary',help='Your dictionary file')
args = parser.parse_args()
if not args.dictionary:
print('Specify you dictionary file')
exit(0)
else:
dictFile = args.dictionary
if not args.user:
print('Specify a user to crack')
exit(0)
else:
userToCrack = args.user
if not args.shadow:
print('Specify your shadow file')
exit(0)
else:
shadFile = args.shadow
dictionary = open(dictFile,"r") #opening dictionary file
try:
shadowFile = open(shadFile,"r") #opening shadow file
except:
print('You do not have access to shadow file')
exit(0)
for line in shadowFile.readlines():
if line.split(':')[0] == userToCrack: #picking out the user to be cracked from shadow file
passToCrack = line.split(':')[1]
break
salt = '$' + passToCrack.split('$')[1] + '$' + passToCrack.split('$')[2] + '$' #extracting salt
for line in dictionary.readlines():
dictPass = line.strip('\n')
t = threading.Thread(target=crackFile,args=(passToCrack,salt,dictPass),daemon=True) #daemon is created so that when password is found main() ends and script ends then all threads gets stopped
t.start()
if __name__ == '__main__':
main()