Skip to content

Instantly share code, notes, and snippets.

@MarkBaggett
Created March 26, 2018 20:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkBaggett/29995da8bd4e22681ad8cf2bdb139fb2 to your computer and use it in GitHub Desktop.
Save MarkBaggett/29995da8bd4e22681ad8cf2bdb139fb2 to your computer and use it in GitHub Desktop.
Rainbow Tables Challenge
#!/usr/bin/env python3
import argparse
import math
import random
import hashlib
import codecs
"""
Given the following MD5 Rainbow table that was generate using this program, determine
the password for this hash bcccb2598de87da2952522eae448b356. You must use this program
to solve the problem. Bruteforce md5 cracking will not count.
[['mark', '0drUPiyl'],
['ed', 'qPYgBkmL'],
['don', 'iVDxXJuE'],
['chris', 'koaEUK4z'],
['bill', 'FRIdNmNT'],
['tad', 'z0Smes0J'],
['lester', 'BzInH0n2'],
['josh', 'gcFqhXph']]
"""
def reduction_function(ahash_hexdigest):
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
ahash_digest = codecs.decode(ahash_hexdigest,"HEX")
bignumber = int.from_bytes(ahash_digest, byteorder = "little")
base = len(charset)
max_length = 8
rnum = bignumber % base**max_length
random_length = math.ceil(math.log(rnum, base))
pw = ""
while bignumber > 0 and len(pw)<random_length:
pw = pw + charset[bignumber%base]
bignumber -= (bignumber % base)
bignumber //= base-1
return pw
parser = argparse.ArgumentParser()
parser.add_argument("HASH", type=str, help = "A Hexidecimal hash to reduce to the next possible password")
parser.add_argument("-r","--rehash", action="store_true", help = "If this argument is passed it will reduce the hash to a new password and then convert the new password to a MD5 hash.")
args = parser.parse_args()
newpw = reduction_function(args.HASH)
if args.rehash:
newpw= hashlib.md5(newpw.encode()).hexdigest()
print(newpw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment