Cracking hashes with Python

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Nov 27 02:04:45 CET 2013


On 26/11/2013 23:06, TheRandomPast . wrote:
> 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.
>

Good to see another cricketer on the list :)  Besides that stating "x 
isn't working" usually doesn't help us to help you.  However here it's 
obvious that you define chklength to take an argument hashes but call it 
without arguments.  You also use raw_input on one line and input on the 
next, not a good idea.  I haven't looked for anything else.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence




More information about the Python-list mailing list