hashlib穷举字典破解md5,sha1,hashlibsha1,初步完工,在Ubuntu


初步完工,在Ubuntu 10.04 Kernel linux 3.2.6 python 2.6.5上基本测试通过。

#! /usr/bin/python# -*- coding: utf-8 -*-# Filename: crackhash.py 穷举字典破解md5,sha1import sys,getopt,hashlibif len(sys.argv) == 1:    print 'usage: crackhash.py -t hashtype{md5/sha1} -h hashcode -w wordfile'    sys.exit()opts,args = getopt.getopt(sys.argv[1:],"t:h:w:")hashtype = ""hashcode = ""wordfile = ""for op,value in opts:    if op == "-t":        hashtype = value    elif op == "-h":        hashcode = value    elif op == "-w":        wordfile = value    else:        sys.exit()w = file(wordfile,'r')if hashtype =="md5":    while True:        line = w.readline()        if line:            y = hashlib.md5(line.rstrip()).hexdigest()            if hashcode == y:                print "md5(%s)=%s" % (line.rstrip(),y)                break        else:            print 'NULL'            breakif hashtype == "sha1":    while True:        line = w.readline()        if line:            y = hashlib.sha1(line.rstrip()).hexdigest()            if hashcode == y:                print "sha1(%s)=%s" % (line.rstrip(),y)                break        else:            print 'NULL'            breakw.close()#该片段来自于http://byrx.net

评论关闭