How do I break an inner for loop every time a condition is satisfied?

  python, python-3.x

Good afternoon,

Im very new to python coding and Im trying to write a very basic md5 brute force password cracker for a school project.

I am supposed to write a script that will crack a series of MD5 hashed passwords. The passwords must be read in from a text file named “hashes.txt”, with one password on every line. The script should then start generating passwords, starting with single character, and then two characters, etc

My thought process of how to make a brute force cracker is as follows:

import hashlib
import itertools
abc = "[email protected]"
abc_list = list(abc)

def combo():
    md5_hash = ""
    file_name = open("hashes.txt", "r")
    for password in file_name:
        password = password.strip()
        #print(password)
        for r in range(len(abc_list)):
            combinations_object = itertools.combinations(abc_list, r)
            combinations_list = list(combinations_object)
            #print(combinations_list)
            for lis in combinations_list:
                glue = "".join(lis)
                hash_object = hashlib.md5(glue.encode())
                md5_hash = hash_object.hexdigest()
                print(glue)
                #print(md5_hash)
                #print(glue + " " + md5_hash)
                if md5_hash == password :
                    print("Your password is: " + "'" + glue +"' "+ md5_hash)
                    break

The passwords I am given to crack are:
Z,
AD,
God,
1234,
AbCdE,
Trojan

Every time I run the script it only outputs the password: Z and then runs through the rest without fulfilling the ‘if’ statement.

I have tried using the ‘break’ statement under the ‘if’ but the outcome is the same.

Source: Python-3x Questions

LEAVE A COMMENT