loldongs

PyCrack MD5 Hash Cracker (Python 3.3.2)

Sep 28th, 2013
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. # PyCrack MD5 Hash Cracker
  2. # Version 1.0.0
  3. # Coded by BlackMan in Python 3.3.2
  4. # Download : http://sourceforge.net/projects/md5crack/
  5. # File     : pycrack.py
  6.  
  7. #IMPORTS
  8. import hashlib
  9. import os
  10. import sys
  11. import datetime
  12.  
  13. #GLOBAL
  14. startTime = datetime.datetime.now()
  15.  
  16. #DEBUG MESSAGES
  17. def action(msg)    : print('[#] - ' + msg)
  18. def alert(msg)     : print('[+] - ' + msg)
  19. def error(msg)     : print('[!] - ' + msg)
  20. def errorExit(msg) : raise SystemExit('[!] - ' + msg)
  21.  
  22. #MD5 STRING
  23. def md5(string): return hashlib.md5(string.encode('utf-8')).hexdigest()
  24.  
  25. #PERMUTATION BUILDER
  26. def xpermutation(characters, size):
  27.     if size == 0:
  28.         yield []
  29.     else:
  30.         for x in range(len(characters)):
  31.             for y in xpermutation(characters[:x] + characters[x:], size - 1):
  32.                 yield [characters[x]] + y
  33.  
  34. #BRUTE FORCE
  35. def bruteForce(hash):
  36.     attempt = 0
  37.     characters = list('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
  38.     maxLength = range(0,25)
  39.     stringBuilder = ''
  40.     for length in maxLength:
  41.         for x in xpermutation(characters, length):
  42.             permutation = stringBuilder + ''.join(x)
  43.             attempt = attempt + 1
  44.             if md5(permutation) == hash:
  45.                 end_time = str(datetime.datetime.now() - startTime).split('.')[0]
  46.                 print('[' + str(attempt) + '] - ' + permutation + ' - CRACKED! Took ' + end_time)
  47.                 input('\nPress the <ENTER> key to EXIT...')
  48.                 sys.exit()
  49.             else:
  50.                 print('[' + str(attempt) + '] - ' + permutation)
  51.     errorExit('Failed to brute force hash.')
  52.  
  53. #START
  54. if os.name == 'nt' : os.system('cls')
  55. else : os.system('clear')
  56. print ''.rjust(56, '#')
  57. print '#' + ''.center(54) + '#'
  58. print '# PyCrack MD5 Hash Cracker'.ljust(55) + '#'
  59. print '# Version 1.0.0'.ljust(55) + '#'
  60. print '# Coded by InvisibleMan in Python 3.3.2'.ljust(55) + '#'
  61. print '# Download : http://sourceforge.net/projects/md5crack/'.ljust(55) + '#'
  62. print '#' + ''.center(54) + '#'
  63. print ''.rjust(56, '#')
  64. if sys.version_info.major != 3 or sys.version_info.minor != 3:
  65.     errorExit('Requires Python version 3.3')
  66. if len(sys.argv) == 2:
  67.     if len(sys.argv[1]) == 32 and sys.argv[1].isalnum():
  68.         bruteForce(sys.argv[1])
  69.     else:
  70.         error('Invalid MD5 hash!')
  71.         errorExit('Usage : pycrack.py [HASH]')
  72. else:
  73.     error('Missing command line arguments.')
  74.     errorExit('Usage : pycrack.py [HASH]')
Add Comment
Please, Sign In to add comment