forked from willstruggle/john
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaix2john.py
More file actions
executable file
·78 lines (59 loc) · 2.04 KB
/
aix2john.py
File metadata and controls
executable file
·78 lines (59 loc) · 2.04 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
77
#!/usr/bin/env python
import binascii
import sys
import re
try:
import argparse
except ImportError:
sys.stderr.write("Stop living in the past. Upgrade your python!\n")
def process_file(filename, is_standard):
try:
fd = open(filename, "rb")
except IOError:
e = sys.exc_info()[1]
sys.stderr.write("%s\n" % str(e))
return
username = "?"
for line in fd.readlines():
if re.match('^\s*\S+\s*:\s*$',line):
username = line.split(':')[0]
if "password = " in line and "smd5" in line:
h = line.split("=")[1].strip()
if len(h) != 37:
continue
if is_standard:
sys.stdout.write("%s:$1$%s\n" % (username, h[6:]))
else:
sys.stdout.write("%s:%s\n" % (username,
h))
elif "password = " in line and "ssha" in line:
h = line.split("=")[1].strip()
tc, salt, h = h.split('$')
sys.stdout.write("%s:%s$%s$%s\n" % (username,
tc, salt, h))
elif "password = " in line: # DES
h = line.split("=")[1].strip()
if h != "*":
sys.stdout.write("%s:%s\n" % (username, h))
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.stderr.write("Usage: %s [-s] -f <AIX passwd file "
"(/etc/security/passwd)>\n" % sys.argv[0])
sys.exit(-1)
parser = argparse.ArgumentParser()
parser.add_argument('-s', action="store_true",
default=False,
dest="is_standard",
help='Use this option if "lpa_options '
'= std_hash=true" is activated'
)
parser.add_argument('-f', dest="filename",
default=False,
help='Specify the AIX shadow file filename to read (usually /etc/security/passwd)'
)
args = parser.parse_args()
if args.filename:
process_file(args.filename, args.is_standard)
else:
print "Please specify a filename (-f)"
sys.exit(-1)