| #!/usr/bin/env python |
| # File: Hash.py |
| # Author: Shady Tyrant |
| # Date: 2009-11-01 |
| # Notes: Module for creating and cracking hashes. Very flexible and is able to be ported to many different front ends. |
| # Error checking / handling must be done by front end but this module supplys front end with proper error returns. |
| #------------------------------------------------ |
| |
| import hashlib, base64 |
| |
| class Crack: |
| |
| def LoadWordlist(self, wordlist): |
| '''Trys to open a wordlist and load it for use in the Crack() methods. If successful it returns the loaded list, else it returns false. \nWordlist should be checked for errors by front end before words is passed to a crack() method to avoid errors''' |
| try: |
| words = open(wordlist, "r") |
| except(IOError): |
| words = False |
| return words |
| |
| words = words.readlines() |
| return words |
| |
| #------------------------------------------------ |
| |
| def Md5(self, words, hash): |
| '''Trys to crack a md5 hash, if successful it returns the word, else it returns false''' |
| for word in words: |
| value = hashlib.md5(word[:-1]).hexdigest() |
| if hash == value: |
| return word |
| return False |
| |
| def Sha1(self, words, hash): |
| '''Trys to crack a sha1 hash, if successful it returns the word, else it returns false''' |
| for word in words: |
| value = hashlib.sha1(word[:-1]).hexdigest() |
| if hash == value: |
| return word |
| return False |
| |
| def Base64(self, words, hash): |
| '''Trys to crack a base64 hash, if successful it returns the word, else it returns false''' |
| for word in words: |
| value = base64.b64encode(word[:-1]) |
| if hash == value: |
| return word |
| return False |
| |
| #------------------------------------------------ |
| |
| def CheckMd5(self, hash): |
| '''Checks to see if hash could be a md5 hash. Returns True or False as expected''' |
| if len(hash) != 32: |
| return False |
| else: |
| return True |
| |
| def CheckSha1(self, hash): |
| '''Checks to see if hash could be a Sha1 hash. Returns True or False as expected''' |
| if len(hash) != 40: |
| return False |
| else: |
| return True |
| |
| #------------------------------------------------ |
| |
| class Encrypt: |
| |
| def Md5(self, word): |
| '''Encrypts word to md5 hash''' |
| value = hashlib.md5(word).hexdigest() |
| return value |
| |
| def Sha1(self, word): |
| '''Encrypts word to sha1 hash''' |
| value = hashlib.sha1(word).hexdigest() |
| return value |
| |
| def Base64(self, word): |
| '''Encrypts word to base64 hash''' |
| value = base64.b64encode(word) |
| return value |