Demo entry 4813716

crackPassword.py

   

Submitted by anonymous on May 19, 2016 at 11:08
Language: Python. Code size: 1.2 kB.

#!/usr/bin/python

import os, sys, hashlib

supportedHashFunctions = {32: (hashlib.md5, "md5"), 40: (hashlib.sha1, "sha1"), 56: (hashlib.sha224, "sha224"), 64: (hashlib.sha256, "sha256"), 96: (hashlib.sha384, "sha384"), 128: (hashlib.sha512, "sha512")}

def main():
    if len(sys.argv) < 3:
        print "[*] Usage: python crackPasswords.py [hash] [dictionary]"
        return
    # Retrieve inputs
    passwordHash = sys.argv[1]
    passwordDict = sys.argv[2]
    # Dictionary file exists?
    if not os.path.exists(passwordDict):
        print "[*] Dictionary file \"%s\" not found. Exiting" % passwordDict
    # Figure out hash function
    hashLength = len(passwordHash)
    if hashLength in supportedHashFunctions.keys():
        hashFunction = supportedHashFunctions[hashLength]
        print "[*] Cracking with the %s hash algorithm" % hashFunction[1]
    else:
        print "[*] Unsupported hash of length %s. Exiting" % hashLength
        return
    # Brute-force the hash
    for password in open(passwordDict).read().split('\n'):
        if hashFunction[0](password).hexdigest() == passwordHash:
            print "[*] Got it: %s" % password
    
if __name__ == "__main__":
    main()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).