Skip to content

Instantly share code, notes, and snippets.

@michelep
Created December 24, 2021 14:07
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 michelep/c2681714f7266c80de973089d3ad1cc1 to your computer and use it in GitHub Desktop.
Save michelep/c2681714f7266c80de973089d3ad1cc1 to your computer and use it in GitHub Desktop.
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 + ':' + b64salt + ':' + b64hash)
elif '{SHA256}' in line:
user = line.split(':')[0]
hhash = base64.b64decode(line.split('}')[1]).hex()
print(user + ":" + hhash)
elif '{MD5}' in line:
user = line.split(':')[0]
hhash = base64.b64decode(line.split('}')[1]).hex()
print(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