Cracking hashes with Python

TheRandomPast . wishingforsam at gmail.com
Tue Nov 26 18:06:15 EST 2013


This is my code

import md5
import sys

def chklength(hashes):
    if len(hashes) != 32:
        print '[-] Improper length for md5 hash.'
        sys.exit(1)
characters=range(48,57)+range(65,90)+range(97,122)
def checkPassword(password):
    #print password
    m = md5.new(password)
    if (m.hexdigest() == hash):
        print "match [" + password + "]"
        sys.exit()

def recurse(width, position, baseString):
    for char in characters:
        if (position < width - 1):
            recurse(width, position + 1, baseString + "%c" % char)
        checkPassword(baseString + "%c" % char)
        print "Target Hash [" + hash+ " string: "+ baseString
def brute_force():
    maxChars = 32
    for baseWidth in range(1, maxChars + 1):
        print "checking passwords width [" + `baseWidth` + "]"
        recurse(baseWidth, 0, "")
def dictionary():
    for line in File.readlines():
        checkPassword(line.strip('\n'))
hash =raw_input("Input MD5 hash:")
option=input("Choose method:1=Brute Force; 0=Dictionary")
if(option==1):
    chklength()
    brute_force()
else:
    if(option==0):
        File=open("dict.txt")
        chklength()
        dictionary()
    else:
        print "You picked wrong!"

IT WORKS! ...(Almost) My chklength isn't working. Can anyone see why not?
I'm stumped.


On Tue, Nov 26, 2013 at 6:17 PM, Denis McMahon <denismfmcmahon at gmail.com>wrote:

> On Tue, 26 Nov 2013 02:30:03 -0800, TheRandomPast wrote:
>
> >>    for value in values:
> >         print value
>
> ..........^^^^^^^^^^^
>
> so change this to:
>           crackMD5Hash( value )
>
> >> import hashlib
> >> def crackMD5Hash():
>
> Nah ....
>
> def crackMD5Hash( hash ):
>         print "cracking hash:", hash
>         some code goes here ...
>         print "original string was:", result
>
> Algorithms for cracking md5 hashes is not a python topic, but rather a
> cryptography topic. When you find an algorithm to use, then if you have
> trouble converting it into code we may be able to help with that bit.
>
> --
> Denis McMahon, denismfmcmahon at gmail.com
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131126/82ac4686/attachment.html>


More information about the Python-list mailing list