Ejemplo n.º 1
0
        return return_value


if __name__ == "__main__":

    parser = argparse.ArgumentParser(description="Generate a rainbow table")
    parser.add_argument("-s", "--size", required=True, nargs=1, help="Size of the alphabet")
    parser.add_argument("-a", "--alphabet", required=True, nargs=1, help="Alphabet")
    parser.add_argument("-o", "--output", required=True, nargs=1, help="Rainbow table file")
    args = parser.parse_args()

    alphabet_size = int(args.size[0])
    alphabet = parse_alphabet(args.alphabet[0])

    print(alphabet)
    with open(args.output[0], "w") as file_out:

        print("0/%s" % alphabet_size)
        for i in range(alphabet_size):

            start_time = time.time()
            for c in itertools.product(alphabet, repeat=(i+1)):
                word = ''.join(c)
                file_out.write("%s " % word)

                for j in range(1000):
                    hash_string = hash_utilities.reduce(hash_utilities.hash(word))
                file_out.write("%s\n" % hash_string)
            
            print("%s/%s [ %s ]" % (i+1, alphabet_size, time.time() - start_time))
Ejemplo n.º 2
0
def success(value):
	print("%s => %s" % (input_hash, value))

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description="Crack a hash using a rainbow table")
    parser.add_argument("hash", nargs=1, help="Hash to crack")
    parser.add_argument("-i", "--input", nargs=1, help="Rainbow table file")
    args = parser.parse_args()

    input_hash = args.hash[0]

    rainbow_table = {}
    with open(args.input[0]) as f:
            for line in f:
                    plain, hashed = line.split(" ")
                    rainbow_table[hash_utilities.reduce(hashed.strip())] = plain

    if input_hash in rainbow_table.keys():
            success(rainbow_table[input_hash])
    else:
            word = input_hash
            for i in range(1000):
                    word = hash_utilities.reduce(word)
                    if word in rainbow_table.keys():
                            success(rainbow_table[word])
                            break
                    else:
                            word = hash_utilities.hash(word)