Hacking&Security Workshop

ตอนนี้ MaYaSeVeN ได้ย้าย Blog ไปที่ http://blog.mayaseven.com


Thursday, September 1, 2011

python Crack MD5 by MaYaSeVeN

Code Python อันนี้เป็น V.2 ครับ V.1 ผมไม่ได้ปล่อย ><" ครั้งนี้ก็เอามาปล่อยเป็นการแชร์ความรู้ภาษา Python ละกันครับหลักการคร่าวๆของ Code นี้คือ 1.Wordlist  2.ส่งไปให้เว็บ Crack ตามลำดับ และสามารถ Crack แบบ SingleHash และ MultiHash ได้ Download ไปทดสอบกันดูครับ :P ในไฟล์ zip ที่ให้ Download ประกอบไปด้วย Source code + sample wordlist + sample hash




ปล.ขอบคุณ c1ph3r < c1ph3r {at} blackbuntu {dot} com > สำหรับ Banner สวยๆและ License
#!/usr/bin/env python
#-*- coding:UTF-8 -*-
# Python script attempt to crack md5 hash.
#----------------------------------------------------------------------------------------------#
# md5multicrack.py v2 ( 01-09-2011)                                                            #
# (C)opyright 2011 - MaYaSeVeN < mayaseven {at} blackbuntu {dot} com >                         #
#---License------------------------------------------------------------------------------------#
#  This program is free software: you can redistribute it and/or modify it under the terms     #
#  of the GNU General Public License as published by the Free Software Foundation, either      #
#  version 3 of the License, or (at your option) any later version.                            #
#                                                                                              #
#  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;   #
#  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   #
#  See the GNU General Public License for more details.                                        #
#                                                                                              #
#  You should have received a copy of the GNU General Public License along with this program.  #
#  If not, see http: licenses="" www.gnu.org="".                                                 #
#---Important----------------------------------------------------------------------------------#
#                     *** Do NOT use this for illegal or malicious use ***                     #
#              The programs are provided as is without any guarantees or warranty.             #
#----------------------------------------------------------------------------------------------#

import hashlib, re, sys, urllib

def main():
    blackbuntu_banner()
    if (len(sys.argv) != 3):
        print "usage :\t" + sys.argv[0] + " hash hashfile="" or="" wordlist\n";
    else: 
        multiHash(sys.argv[1], sys.argv[2])
 
def blackbuntu_banner():
    print "\n"
    print               "o--o  o      O    o-o o  o o--o  o   o o   o o-O-o o   o     o-O-o o--o   O  o   o" 
    print               "|   | |     / \  /    | /  |   | |   | |\  |   |   |   |       |   |     / \ |\ /|" 
    print               "O--o  |    o---oO     OO   O--o  |   | | \ |   |   |   |       |   O-o  o---o| O |" 
    print               "|   | |    |   | \    | \  |   | |   | |  \|   |   |   |       |   |    |   ||   |" 
    print               "o--o  O---oo   o  o-o o  o o--o   o-o  o   o   o    o-o        o   o--o o   oo   o"
    print               "\n                            www.blackbuntu.com\n"
    print "\n"
        
def checkLength(hashes):
    if len(hashes) != 32 :
        if len(hashes) > 1:
            print "[-] Improper length for md5 hash."
            quit()
            
def webMethod(inputHash2):
    try:
        url = "http://www.hashchecker.de/hash.cgi?action=check&wert=1&hash=%s" % inputHash2
        site = urllib.urlopen(url).read()
        decrypt = re.compile('(?<=\'\,\')[\w+"\'"]+(?=\)<)').findall(site)
        for j in range(len(decrypt)):
            if decrypt[j] != "'":
                print "[+]"+ inputHash2 + " " + decrypt[j][0:-1] + " [Cracked]"
                break
    except IOError:
        print "Can't connect to the Web"
        quit()

def wordListMethod(inputHash, wordlistFile):
    try:
        wordlist = open(wordlistFile, 'r')
        for line in wordlist:
            crop_st = line[0:-1]
            md5 = hashlib.md5(crop_st).hexdigest() 
            if inputHash == md5:
                print "[+]" + inputHash + " : " + crop_st + " [Cracked]"
        wordlist.close()
    except IOError:
        print "File \"wordlist\" not found"
    
def multiHash(hashFile, wordlistFile):
    if not "/" in hashFile and not "hash" == hashFile:
        checkLength(hashFile)
        wordListMethod(hashFile, wordlistFile)
        print "\n[Finished] Wordlist method"
        print "\nPlease Waiting..\n"
        webMethod(hashFile)
        print "\n[Finished] Web method"
    else:
        try:
            wordlist = open(hashFile, 'r')
            for line in wordlist:
                crop_st = line[0:-1]
                checkLength(crop_st)
                wordListMethod(crop_st, wordlistFile)
            wordlist.close()
            print "\n[Finished] Wordlist method"
            print "\nPlease Waiting..\n"
            wordlist = open(hashFile, 'r')
            for line in wordlist:    
                crop_st = line[0:-1]
                checkLength(crop_st)
                webMethod(crop_st)
            wordlist.close()
            print "\n[Finished] Web method"
        except IOError:
            print "File \"hash\" not found"
            quit()
main()
Download : http://www.mediafire.com/?ajs97w56tjx7o2r
Written : MaYaSeVeN