Skip to content

Instantly share code, notes, and snippets.

@gquere
Last active November 17, 2020 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gquere/9530ea12fc76bac6a46b9a1806e8868c to your computer and use it in GitHub Desktop.
Save gquere/9530ea12fc76bac6a46b9a1806e8868c to your computer and use it in GitHub Desktop.
Convert OpenLDAP hashes to a format john the ripper can understand
#!/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