Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #
- # Simple Hash list builder
- # Converts Wordlist into Hash List
- # Handy for testing and pot file seeding
- # By: Hood3dRob1n
- #
- # ./dict2hash.py [OPTIONS]
- # -s = single plaintext
- # -w = wordlist file to convert to hash list
- # -t = hash type to use
- # -o = output filename to use (default: converted.hashes)
- #
- # Currently Supporting the Following Types:
- # 1:Bcyrpt, 2:Cisco PIX, 3:Cisco Type7, 4:DES, 5:MD4, 6:MD5, 7:Unix(MD5), 8:SHA1, 9:SHA256, 10:SHA512,
- # 11:LM, 12:MS-SQL 2000, 13:MS-SQL 2005, 14:MySQL 323, 15:MySQL 4.1+, 16:NTLM,
- # 19:Oracle 11G, 20:Django DES, 21:Django MD5, 22:Django SHA1
- #
- # Removed as require username for hashing: 17:Postgres(MD5) & 18:Oracle 10G
- # Write your own, im tired...
- #
- # Leverages passlib package/module for all hashing...
- # Passlib uses py-bcrypt, so also need that installed too...
- #
- import os
- import optparse
- import passlib
- import sys
- from passlib.hash import bcrypt
- from passlib.hash import cisco_pix as pix
- from passlib.hash import cisco_type7 as type7
- from passlib.hash import des_crypt
- from passlib.hash import django_salted_sha1 as django_sha1
- from passlib.hash import django_salted_md5 as django_md5
- from passlib.hash import django_des_crypt as django_des
- from passlib.hash import hex_md4 as md4
- from passlib.hash import hex_md5 as md5
- from passlib.hash import hex_sha1 as sha1
- from passlib.hash import hex_sha256 as sha256
- from passlib.hash import hex_sha512 as sha512
- from passlib.hash import lmhash
- from passlib.hash import md5_crypt
- from passlib.hash import mssql2000 as m20
- from passlib.hash import mssql2005 as m25
- from passlib.hash import mysql323
- from passlib.hash import mysql41
- from passlib.hash import nthash
- from passlib.hash import oracle11 as oracle11
- def cls():
- """Clear the Terminal Screen"""
- if os.name == 'nt':
- os.system('cls')
- elif sys.platform.startswith('win'):
- os.system('cls')
- else:
- os.system('clear')
- def banner():
- """0x1337 Banner"""
- cls()
- print "\nWordlist to Hash List Convertor"
- print "By: Hood3dRob1n\n"
- def hasher(self, hashtype):
- """Convert String to requested Hashtype
- Returns the updated hash string
- Unless it's a single plaintext, which displays each hash type"""
- if hashtype == 0: # ALL Hash Formats
- print "Hashing using all available hash formats...."
- for key, value in valid_hash_types.iteritems():
- h = hasher(self, key)
- if h.startswith('DISABLED FUNCTIONALITY') or h.startswith('ERROR'):
- pass
- else:
- print value.upper() + ":" + h
- return
- elif hashtype == 1: # Bcyrpt
- try:
- hash_string = bcrypt.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to Bcrypt Hash Format!" % self
- elif hashtype == 2: # Cisco PIX
- try:
- hash_string = pix.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to Cisco PIX Hash Format!" % self
- elif hashtype == 3: # Cisco Type7
- try:
- hash_string = type7.encrypt(self)
- except:
- hash_string = "ERROR: Problem Encoding '%s' to Cisco Type7 Hash Format!" % self
- elif hashtype == 4: # DES
- try:
- hash_string = des_crypt.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to DES Crypt Hash Format!" % self
- elif hashtype == 5: # MD4
- try:
- hash_string = md4.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to MD4 Hash Format!" % self
- elif hashtype == 6: # MD5
- try:
- hash_string = md5.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to MD4 Hash Format!" % self
- elif hashtype == 7: # Unix(MD5)
- try:
- hash_string = md5_crypt.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to Unix(MD5) Hash Format!" % self
- elif hashtype == 8: # SHA1
- try:
- hash_string = sha1.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to SHA1 Hash Format!" % self
- elif hashtype == 9: # SHA256
- try:
- hash_string = sha256.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to SHA256 Hash Format!" % self
- elif hashtype == 10: # SHA512
- try:
- hash_string = sha512.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to SHA512 Hash Format!" % self
- elif hashtype == 11: # LM
- try:
- hash_string = lmhash.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to LM Hash Format!" % self
- elif hashtype == 12: # MS-SQL 2000
- try:
- hash_string = m20.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to MS-SQL 2000 Hash Format!" % self
- elif hashtype == 13: # MS-SQL 2005
- try:
- hash_string = m25.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to MS-SQL 2005 Hash Format!" % self
- elif hashtype == 14: # MySQL 323
- try:
- hash_string = mysql323.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to MySQL 323 Hash Format!" % self
- elif hashtype == 15: # MySQL 4.1+
- try:
- hash_string = mysql41.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to MySQL 4.1+ Hash Format!" % self
- elif hashtype == 16: # NTLM
- try:
- hash_string = nthash.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to NTLM Hash Format!" % self
- elif hashtype == 17: # Postgres(MD5)
- # Requires username for hashing....
- hash_string = "DISABLED FUNCTIONALITY: Postgres MD5"
- elif hashtype == 18: # Oracle 10G
- # Requires username for hashing....
- hash_string = "DISABLED FUNCTIONALITY: Oracle 10G"
- elif hashtype == 19: # Oracle 11G
- try:
- hash_string = oracle11.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to Oracle 11G Hash Format!" % self
- elif hashtype == 20: # Django DES
- try:
- hash_string = django_des.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to Django DES Crypt Hash Format!" % self
- elif hashtype == 21: # Django MD5
- try:
- hash_string = django_md5.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to Django MD5 Hash Format!" % self
- elif hashtype == 22: # Django SHA1
- try:
- hash_string = django_sha1.encrypt(self)
- except:
- hash_string = "ERROR: Problem Converting '%s' to Django SHA1 Hash Format!" % self
- else: # Unknown hash type, skip it
- hash_string = "ERROR: Unknown Hash Format: %s:%s" % (hash_type_string, self)
- if hash_string.startswith('ERROR'):
- print hash_string
- else:
- open(output, "a+").write(hash_string.upper() + "\n")
- return hash_string
- # Parse Arguments/Options
- parser = optparse.OptionParser(banner(), version="%prog v0.01b")
- parser.add_option("-s", "--single", dest="plain", default=None, type="string", help="Single Plaintext to Hash")
- parser.add_option("-w", "--wordlist", dest="wordlist", default=None, type="string", help="Wordlist for Hash Cracking")
- parser.add_option("-t", "--type", dest="hash_type", default=6, type="int", help="Hash Types: 1:Bcyrpt, 2:Cisco PIX, 3:Cisco Type7, 4:DES, 5:MD4, 6:MD5, 7:Unix(MD5), 8:SHA1, 9:SHA256, 10:SHA512, 11:LM, 12:MS-SQL 2000, 13:MS-SQL 2005, 14:MySQL 323, 15:MySQL 4.1+, 16:NTLM, 17:Postgres(MD5), 18:Oracle 10G, 19:Oracle 11G, 20:Django DES, 21:Django MD5, 22:Django SHA1")
- parser.add_option('-o', '--output', dest="outfile", default="converted.hashes", type="string", help="Custom Output Filename to Use")
- (options, args) = parser.parse_args()
- # Valid Hashtypes, update as needed
- valid_hash_types = { 1: 'Bcyrpt', 2: 'Cisco PIX', 3: 'Cisco Type7', 4: 'DES', 5: 'MD4', 6: 'MD5', 7: 'Unix(MD5)', 8: 'SHA1', 9: 'SHA256', 10: 'SHA512', 11:'LM', 12:'MS-SQL 2000', 13: 'MS-SQL 2005', 14: 'MySQL 323', 15: 'MySQL 4.1+', 16: 'NTLM', 19: 'Oracle 11G', 20: 'Django DES', 21: 'Django MD5', 22: 'Django SHA1' }
- # Check to confirm we have a valid hash_type requested
- valid=False
- try:
- usropt=valid_hash_types[options.hash_type]
- for i in valid_hash_types.values():
- if i.upper().startswith(usropt.upper()):
- hash_type_string = i.upper()
- valid=True
- except:
- print "ERROR: Invalid Hash Type Provided!"
- print "Can't continue as a result...\n\n"
- sys.exit()
- if not valid:
- print "Invalid Hash Type Provided!"
- print "Can't continue as a result...\n\n"
- sys.exit()
- # Output File to write any cracked hashes to
- output = options.outfile.split('.')[0] + '-' + hash_type_string + '.hashes'
- def main():
- """Start the Magic Show..."""
- try:
- if options.plain:
- # Single plaintext, hash with all formats
- hasher(options.plain, 0)
- elif options.wordlist:
- # Wordlist, convert to new hash list
- # Check the file exists, then check and confirm we can access said file
- if os.path.isfile(options.wordlist):
- if os.access(options.wordlist, os.R_OK):
- pass
- else:
- print "Error: Unable to access provided wordlist: %s" % options.wordlist
- print "Can't continue without a valid wordlist...\n\n"
- sys.exit()
- else:
- print "Error: Unable to locate provided wordlist: %s" % options.wordlist
- print "Can't continue without a valid wordlist...\n\n"
- sys.exit()
- print "Converting %s to %s based hash list...." % (options.wordlist, hash_type_string)
- fh = open(options.wordlist)
- for line in fh:
- hasher(line.strip(), options.hash_type)
- # Catch Ctrl-C Interupt Signal
- except KeyboardInterrupt:
- print "\nWARNING: CTRL+C Detected, Shutting Down...\n\n"
- sys.exit(666)
- except EOFError:
- print "\nEOF ERROR: Shutting Down...\n\n"
- except SystemExit:
- pass
- except:
- e = sys.exc_info()
- print "\nERROR Detected: Shutting Things Down...\n\n"
- for error in e:
- print error
- finally:
- e = sys.exc_info()[1]
- if e != None:
- print e
- print "\nAll Finished!\nNew Hash File Saved to: %s\n\n" % output
- sys.exit(0)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement