forked from openwall/john
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwsafe2john.py
executable file
·63 lines (49 loc) · 1.68 KB
/
pwsafe2john.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
#!/usr/bin/env python
# pwsafe2john processes input Password Safe files into a format suitable
# for use with JtR.
#
# This software is Copyright (c) 2012, Dhiru Kholia <dhiru at openwall.com>,
# and it is hereby released to the general public under the following terms:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted.
#
# Password Safe file format is documented at,
# http://keybox.rubyforge.org/password-safe-db-format.html
#
# formatV3.txt at http://passwordsafe.svn.sourceforge.net/viewvc/passwordsafe/trunk/pwsafe/pwsafe/docs/
#
# Output Format: filename:$passwordsaf$*version*salt*iterations*hash */
magic = "PWS3"
import sys
import struct
from binascii import hexlify
import os
def process_file(filename):
f = open(filename, "rb")
data = f.read(4)
if data != magic:
sys.stderr.write("%s : PWS3 magic string missing, is this a Password Safe file?\n", filename)
return
buf = f.read(32)
if len(buf) != 32:
sys.std.write("Error: salt read failed.\n")
return
iterations = struct.unpack(">I", f.read(4))[0]
sys.stdout.write("%s:$pwsafe$*3*" %
os.path.basename(filename).rstrip(".psafe3"))
sys.stdout.write(hexlify(buf))
sys.stdout.write("*%s*" % iterations)
hsh = f.read(32)
if len(hsh) != 32:
sys.stderr.write("Error: hash read failed.\n")
return
sys.stdout.write(hexlify(hsh))
sys.stdout.write("\n")
f.close()
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.stdout.write("Usage: pwsafe2john [.psafe3 files]\n")
sys.exit(-1)
for i in range(1, len(sys.argv)):
process_file(sys.argv[i])