Skip to content

Instantly share code, notes, and snippets.

@ropnop
Created June 21, 2017 23:11
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 ropnop/abb60daba012548f7429a288394a23dd to your computer and use it in GitHub Desktop.
Save ropnop/abb60daba012548f7429a288394a23dd to your computer and use it in GitHub Desktop.
Script to check a plaintext password against an OpenNMS password digest
#!/usr/bin/env python
import sys
from hashlib import sha256
def checkPassword(encrypted, plaintext, iterations=100000, verbose=False):
hexstring = encrypted.decode('base64').encode('hex') # i hate working with bytes
salt = hexstring[:32]
correct = hexstring[32:]
if verbose:
print "[+] plaintext: {}".format(plaintext)
print "[+] salt: {}".format(salt)
print "[+] target hash: {}".format(correct)
testinput = salt.decode('hex')+plaintext
for i in range(1,iterations+1):
s = sha256(testinput)
h = s.hexdigest()
if h == correct:
if verbose:
print "{} iterations".format(i)
return True
else:
testinput = s.digest()
return False
def run():
if len(sys.argv) < 3:
print "Usage: {} base64value plaintext".format(sys.argv[0])
sys.exit(1)
if checkPassword(sys.argv[1], sys.argv[2], verbose=True):
print "Correct!"
else:
print "Nope"
if __name__=='__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment