Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert OpenLDAP hashes to a format Hashcat can understand
#!/usr/bin/env python3
# Convert OpenLDAP hashes to a format Hashcat 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 + ':' + '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 + ":" + hhash)
elif '{SHA512}' in line:
user = line.split(':')[0]
hhash = base64.b64decode(line.split('}')[1]).hex()
print(user + ":" + 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