-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment2.py
50 lines (47 loc) · 1.38 KB
/
assignment2.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
import crypt
import sys
def printme(str):
length = len(str)
with open(sys.argv[2], "r") as f:
array = []
for line in f:
array.append(line)
sLine = (line[0:length])
if(sLine == str):
print ("User Name found\n")
return line
f.close()
def dictAttack(originalPw, hashVal):
with open("./john.txt", "r") as f:
print("we are looking for a password with a hash value of " + originalPw + "\n")
for line in f:
line = line.strip();
hashedPw = crypt.crypt(line, hashVal)
hashedPw = hashedPw.split("$")[3]
#print(line + " is now " + hashedPw)
if(hashedPw == originalPw):
print ("Password Found \n")
return line
f.close()
def main():
if (len(sys.argv) < 3):
print("You have not entered the correct number of arguments \n")
exit()
userName = sys.argv[1]
shadowLine = printme(userName)
if(shadowLine is None):
print("User name not found in shadow file \n")
exit()
sep = shadowLine.split("$")
if(len(sep) == 1):
print("User name does not have a password")
exit()
hashVal = "$"+sep[1]+ "$" + sep[2]
hashPw = sep[3]
hashPw = hashPw.split(":")[0]
result = dictAttack(hashPw, hashVal)
if(result is None):
print("Password not found in dictionary")
exit()
print("password is " + result)
main()