Last active
November 17, 2020 14:38
-
-
Save gquere/9530ea12fc76bac6a46b9a1806e8868c to your computer and use it in GitHub Desktop.
Convert OpenLDAP hashes to a format john the ripper can understand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Convert OpenLDAP hashes to a format john the ripper can understand | |
import sys | |
import base64 | |
with open(sys.argv[1], 'r') as f: | |
lines = f.readlines() | |
for line in lines: | |
line = line.rstrip("\n") | |
if '{PBKDF2-SHA512}' in line: | |
username = line.split(':')[0] | |
hashvals = line.split('}')[1] | |
iterations, b64salt, b64hash = hashvals.split('$') | |
b64salt = b64salt.replace('.', '+') + '===' | |
b64hash = b64hash.replace('.', '+') + '===' | |
print(username + ':' + '$pbkdf2-hmac-sha512$' + iterations + '.' + base64.b64decode(b64salt).hex() + '.' + base64.b64decode(b64hash).hex()) | |
elif '{SHA256}' in line: | |
user = line.split(':')[0] | |
hhash = base64.b64decode(line.split('}')[1]).hex() | |
print(user + ":$SHA256$" + hhash) | |
elif '{SHA512}' in line: | |
user = line.split(':')[0] | |
hhash = base64.b64decode(line.split('}')[1]).hex() | |
print(user + ":$SHA512$" + hhash) | |
elif '{CRYPT}' in line: | |
print(line.replace('{CRYPT}', '')) | |
else: | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment