Created
December 13, 2019 19:13
-
-
Save Mukundan314/e79455594342eb0c3c2e5132f576ffc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import hashlib | |
import sys | |
HASH_ALGORITHIMS = ["md5", "sha1", "sha224", "sha256", "sha384", "sha512"] | |
def hash_subcommand(args): | |
h = hashlib.new(args.algorithim) | |
h.update(args.string.encode('ascii')) | |
print(h.hexdigest()) | |
def crack_subcommand(args): | |
with open(args.wordlist) as f: | |
words = map(lambda x: x[:-1].encode('ascii'), f.readlines()) | |
for word in words: | |
h = hashlib.new(args.algorithim) | |
h.update(word) | |
if args.hash == h.hexdigest(): | |
print("Hash Cracked:", word.decode('ascii')) | |
return | |
print("Hashed word is not in wordlist") | |
exit(1) | |
def main(argv): | |
parser = argparse.ArgumentParser() | |
subparsers = parser.add_subparsers(required=True) | |
hash_parser = subparsers.add_parser('hash', description="Hash given string") | |
hash_parser.add_argument("algorithim", choices=HASH_ALGORITHIMS, help="The hash algorithim") | |
hash_parser.add_argument("string", type=str, help="string to hash") | |
hash_parser.set_defaults(func=hash_subcommand) | |
crack_parser = subparsers.add_parser('crack', description="Crack given hash") | |
crack_parser.add_argument("algorithim", choices=HASH_ALGORITHIMS, help="The hash algorithim") | |
crack_parser.add_argument("wordlist", help="Path to file containing the wordlist") | |
crack_parser.add_argument("hash", type=str, help="hash to crack") | |
crack_parser.set_defaults(func=crack_subcommand) | |
args = parser.parse_args(sys.argv[1:]) | |
args.func(args) | |
if __name__ == "__main__": | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment