khalilasharen

md5 crack with python from s3ym0n

Oct 9th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #Name: mt5crack.py
  3. #Version: 1.0
  4. #Author: s3my0n
  5. #Website: py1337.22web.net
  6.  
  7. #########################################################################
  8. # mt5crack performs a multi-threaded dictionary attack against multiple #
  9. # md5 hashes, and dumps all cracked hashes to a file. #
  10. # #
  11. # Copyright (C) 2010 s3my0n #
  12. # #
  13. # This program is free software: you can redistribute it and/or modify #
  14. # it under the terms of the GNU General Public License as published by #
  15. # the Free Software Foundation, either version 3 of the License, or #
  16. # any later version. #
  17. # #
  18. # This program is distributed in the hope that it will be useful, #
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  21. # GNU General Public License for more details. #
  22. # #
  23. # You should have received a copy of the GNU General Public License #
  24. # along with this program. If not, see <http://www.gnu.org/licenses/>. #
  25. #########################################################################
  26.  
  27. import sys, threading
  28. from time import ctime
  29. from hashlib import md5
  30.  
  31. class MD5Cracker(object):
  32. def __init__(self, dictionary):
  33. self.dic = dictionary
  34. self.cracked = 0
  35. self.lhashes = None
  36.  
  37. def findMatch(self, thash, fresult):
  38. try:
  39. for word in self.dic:
  40. # converting word to md5 hash
  41. m = md5()
  42. m.update(word)
  43. hashword = m.hexdigest()
  44. # matching hash to word
  45. if thash == hashword:
  46. toappend = '%s:%s\n' % (thash, word)
  47. fresult.write(toappend) # writing successful match
  48. self.cracked += 1
  49. else:
  50. continue
  51. except KeyboardInterrupt:
  52. print '\n [*] Aborted: exiting'
  53. sys.exit(1)
  54.  
  55. def about():
  56. usage = '''
  57. ##########################################
  58. # #
  59. # Name: md5crack.py #
  60. # Version: 1.0 #
  61. # Author: s3my0n #
  62. # Email: RuSH4ck3R[at]gmail[dot]com #
  63. # #
  64. # Kalimantan Cyber Hacked #
  65. # #
  66. ##########################################
  67.  
  68. Usage: mt5crack.py <hashes_file> <dictionary_file> <cracked_file>
  69.  
  70. Example: mt5crack.py hashes.txt dic.txt cracked.txt'''
  71. return usage
  72.  
  73. def main(hashfile, mt5, filetoappendto):
  74. try:
  75. fappend = open(filetoappendto, 'a')
  76. except IOError:
  77. print '\n [-] Error opening %s to append to' % (filetoappend)
  78. sys.exit()
  79.  
  80. try:
  81. ofile = open(hashfile).readlines()
  82. mt5.lhashes = len(ofile) # number of hashes
  83. print '\n [+] Loaded %d hashes' % (mt5.lhashes)
  84. except IOError:
  85. print '\n [-] Error opening %s to read from' % (hashfile)
  86. sys.exit(1)
  87.  
  88. hashes = [i.strip() for i in ofile] # storing hashes to crack here
  89. threads = [] # all our threads will be stored in here
  90. nhashes = range(len(hashes))
  91.  
  92. print '\n [*] Checking for valid md5 hashes...'
  93. validhashes = 0 # variable to test for number of valid hashes
  94. for h in hashes:
  95. if len(h) == 32:
  96. validhashes += 1
  97. t = threading.Thread(target=mt5.findMatch, args=(h, fappend)) # making threads
  98. threads.append(t)
  99.  
  100. if validhashes == 0:
  101. print '\n [-] File %s doesn\'t contain valid md5 hashes' % (hashfile)
  102. sys.exit(1)
  103.  
  104. print '\n [*] Starting cracking at [%s] ...' % (ctime())
  105. for t in nhashes:
  106. try:
  107. threads[t].start() # starting threads
  108. except KeyboardInterrupt:
  109. print '\n [*] Aborted: exiting'
  110. sys.exit(1)
  111.  
  112. print '\n [+] Cracked %d out of %d hashes at [%s]' % (mt5.cracked, mt5.lhashes, ctime())
  113.  
  114. if __name__=='__main__':
  115. if len(sys.argv) != 4:
  116. print about()
  117. sys.exit(1)
  118. try:
  119. ofile = open(sys.argv[2]).readlines() # opening dictionary file
  120. except IOError:
  121. print '\n [-] Error opening %s to read from' % (sys.argv[2])
  122. sys.exit(1)
  123.  
  124. dic = [i.strip() for i in ofile] # storing dictionary words here
  125. afile = sys.argv[3] # file to append cracked hashes to
  126. md5cracker = MD5Cracker(dic) # passing dictionary to md5cracker
  127.  
  128. print '\n [+] Loaded %d words from dictionary file' % (len(dic))
  129. main(sys.argv[1], md5cracker, afile)
Advertisement
Add Comment
Please, Sign In to add comment