#! /usr/bin/python
# -*- coding: utf-8 -*-
# Filename: crackhash.py 穷举字典破解md5,sha1

import sys,getopt,hashlib

if 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'
			break

if 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'
			break

w.close()
本文章来至源码世界   http://www.ymsky.net/views/34356.shtml
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐