Skip to content Skip to sidebar Skip to footer

Python Multiprocessing Password Cracker

I have been learning Python in my spare time for a small amount of time now and I set myself a challenge to build a password cracker for a very specific task, it was to test how ef

Solution 1:

I have made an example for you that should be relatively easy to add into your code. Here is how it works; First, we need to brake up the wordlist into manageable chunks that we can throw into the multiprocessor module. I do this by making a list with a dictionary of 'starting' and 'stopping' points. Next, I pass those arguments into apply_async which will in turn run the pwd_find function. This is the function you want to add your for word in wordlist: loop, but with a starting and stopping point (see code below).

from multiprocessing import Pool
import math
import time

cores = 4# Number of cores to use
wordlist = []

for i inrange(127):  # Remove this for your own word list.
    wordlist.append(str(i))  # Creates a large 'word' list for testing.defpwd_find(start, stop):

    for word inrange(start, stop):
        print(wordlist[word])
        time.sleep(0.1)  # Slows things down so it's easier to see that your system is using more than one core.### Add your code here... ###


break_points = []  # List that will have start and stopping pointsfor i inrange(cores):  # Creates start and stopping points based on length of word list
    break_points.append({"start":math.ceil(len(wordlist)/cores * i), "stop":math.ceil(len(wordlist)/cores * (i + 1))})

if __name__ == '__main__':  # Added this because the multiprocessor module acts funny without it.

    p = Pool(cores)  # Number of processors to utilize.for i in break_points:  # Cycles though the breakpoints list created above.print(i)  # shows the start and stop points.
        a = p.apply_async(pwd_find, kwds=i, args=tuple())  # This will start the separate processes.print("Done!")
    p.close()
    p.join()

If your code finds a match, add p.terminate followed by p.join to kill the processors.

If you would like to lean more about the multiprocessor module, go here to learn more.

I hope this helps you out, or at the very least, gives you a better insight into multiprocessing!

Post a Comment for "Python Multiprocessing Password Cracker"