From 86f21992e9750b81e39a5078b69f1d7839b8f081 Mon Sep 17 00:00:00 2001 From: Jamie Riden Date: Wed, 19 Dec 2018 07:43:12 +0000 Subject: [PATCH] build changes --- hashcrack.py | 308 ++++++++++++------------------------------------ hashcrackwin.py | 216 +++------------------------------ setupbin.py | 24 ++++ setupexe.py | 4 +- 4 files changed, 115 insertions(+), 437 deletions(-) create mode 100755 setupbin.py diff --git a/hashcrack.py b/hashcrack.py index 0161486..104891b 100644 --- a/hashcrack.py +++ b/hashcrack.py @@ -11,6 +11,11 @@ # #TODO preprocessors like prince, OMEN #TODO graph flag +#TOD all files need to be abspathd +#TODO merge hashcrackwin hashcrack + +#import platform +# platform.system - Linux / Windows import re import base64 @@ -26,6 +31,7 @@ import time import stat import configparser +import platform # strip out the given regexp from ifile and stick it in ofile - unique strips out dupes if True def getregexpfromfile(pattern, ifile, ofile,unique): @@ -211,200 +217,19 @@ def selectparams( hashtype, nuke, ruleshome, dicthome ): return tp -#autodetect the hashtype given the first line of the file def autodetect( line ): - - if re.search(r'(^|:)\$1\$',line): - print('Autodetected md5crypt') - return '500' - - if re.search(r'(^|:)\$krb5tgs\$23\$',line): - print('Autodetected kerberos ticket type 13100') - return '13100' - - if re.search(r'(^|:)\$P\$',line): - print('Autodetected phpass') - return '400' - - if re.search(r'(^|:)\$H\$',line): - print('Autodetected phpass') - return '400' - - if re.search(r'(^|:)\$8\$',line): - print('Autodetected Cisco type 8 (pbkdf2-sha256)') - return '9200' - - if re.search(r'(^|:)\$9\$',line): - print('Autodetected Cisco type 9 (scrypt)') - return '9300' - - if re.search(r'(^|:)sha1\$',line): - print('Autodetected Django SHA1') - return '124' - - if re.search(r'(^|:)\$S\$',line): - print('Autodetected Drupal') - return '7900' - - if re.search(r'(^|:)\$PHPS\$',line): - print('Autodetected PHPS') - return '2612' - - if re.search(r'(^|:)(A|a)dministrator:500:[A-Fa-f0-9]{32}:[A-Fa-f0-9]{32}:',line): - print('Autodetected pwdump') - return 'pwdump' - - if re.search(r'[^:]+:\d+:[A-Fa-f0-9]{32}:[A-Fa-f0-9]{32}:',line): - print('Autodetected pwdump') - return 'pwdump' - - if re.search(r'(^|:)[a-f0-9]{32}:[A-Za-z0-9_]{1,10}$',line): - print('Autodetect postgres MD5') - return '12' - - if re.search(r'(^|:)\$2(a|b|y)',line): - print('Autodetected bcrypt') - return '3200' - - if re.search(r'(^|:)sha512:',line): - print('Autodetected Cisco sha512 pbkdf2') - return '12100' - - if re.search(r'(^|:)\$5\$',line): - print('Autodetected sha256crypt') - return '7400' - - if re.search(r'(^|:)\$6\$',line): - print('Autodetected sha512crypt') - return '1800' - - if re.search(r'(^|:)[A-Fa-f0-9]{32}:[A-Fa-f0-9]{14}$',line): - print('Autodetected DCC / ms cache') - return '1100' - - if re.search(r'(^|:)[A-Fa-f0-9]{32}:[A-Fa-f0-9]{6}$',line): - print('Autodetected vBulletin (2611)') - return '2611' - if re.search(r'(^|:)[A-Fa-f0-9]{32}:.{5}$',line): - print('Autodetected IPB (2811)') - return '2811' - - if re.search(r'(^|:)[A-Fa-f0-9{32}:[A-Fa-f0-9]{49}$',line): - print('Autodetected Citrix netscaler') - return '8100' - - if re.search(r'(^|:)[A-Fa-f0-9]{126,130}:[A-Fa-f0-9]{40}$',line): - print('Autodetected IPMI2') - return '7300' - - if re.search(r'(^|:)[A-Za-z0-9\./]{43}$',line): - print('Autodetected Cisco type 4') - return '5700' - - if re.search(r'(^|:)[A-Fa-f0-9]{16}:[A-Fa-f0-9]{32}:[A-Fa-f0-9]{106}$',line): - print('Autodetected NetLMv2') - return '5600' - - if re.search(r'(^|:)[A-Fa-f0-9]{32}:[A-Fa-f0-9]{210}$',line): - print('Autodetected NetLMv2') - return '5600' - - if re.search(r':[a-fA-f0-9]{48}:[a-fA-f0-9]{48}:',line): - print('Autodetected NetLMv1') - return '5500' - - if re.search(r'(^|:)[A-Za-z0-9\./]{16}$',line): - print('Autodetected Cisco ASA') - return '2400' - - if re.search(r'(^|:)[A-Za-z0-9\./]{13}$',line): - print('Autodetected descrypt') - return '1500' - - if re.search(r'(^|:)[A-Fa-f0-9]{40}$',line): - print('Autodetected SHA1') - return '100' - - if re.search(r'(^|:)[A-Fa-f0-9]{64}$',line): - print('Autodetected SHA256') - return '1400' - - if re.search(r'(^|:)[A-Fa-f0-9]{96}$',line): - print('Autodetected SHA384') - return '10800' - - if re.search(r'(^|:)[A-Fa-f0-9]{128}$',line): - print('Autodetected SHA512') - return '1700' - - if re.search(r'(^|:)[A-Fa-f0-9]{786}',line): - print('Autodetected WPA/WPA2') - return '2500' - - if re.search(r'(^|:)\$apr1\$',line): - print('Autodetected apache MD5\n') - return '1600' - - if re.search(r'(^|:)\$DCC2',line): - print('Autodetected DCC2 / mscache2') - return '2100' - - if re.search(r'(^|:)\{SHA\}',line): - print('Autodetected nsldap SHA1') - return '101' - - if re.search(r'(^|:)\{SSHA256\}',line): - print('Autodetected ldap SHA256') - return '1411' - - if re.search(r'(^|:)\{SSHA512\}',line): - print('Autodetected ldap SHA512') - return '1711' - - if re.search(r'(^|:)\{SSHA\}',line): - print('Autodetected ldap SSHA1') - return '111' - - if re.search(r'(^|:)0x0100',line): - if re.search(r'(^|:)0x[A-Fa-f0-9]{52}$',line): - print('Autodetected MSSQL2005') - return '132' - if re.search(r'(^|:)0x[A-Fa-f0-9]{92}$',line): - print('Autodetected MSSQL2000') - return '131' - - if re.search(r'(^|:)0x0200',line): - print('Autodetected MSSQL2012+') - return '1731' - - if re.search(r'(^|:)\{smd5\}',line): - print('Autodetected AIX smd5') - return '6300' - - if re.search(r'(^|:)\{ssha1\}',line): - print('Autodetected AIX ssha1') - return '6700' - - if re.search(r'(^|:)\{ssha256\}',line): - print('Autodetected AIX ssha256') - return '6400' - - if re.search(r'(^|:)\{ssha512\}',line): - print('Autodetected AIX ssha512') - return '6500' - - if re.search(r'(^|:)[A-Fa-f0-9]{40}$',line): - print('Autodetected MySQL5') - return '8100' - - if re.search(r'(^|:)[A-fa-f0-9]{60}$',line): - print('Autodetected Oracle (112) - but it needs a hash between the first 40 and last 20 for some reason') - return '112' - - if re.search(r'(^|:)[A-fa-f0-9]{40}:[A-fa-f0-9]{20}$',line): - print('Autodetected Oracle (112)') - return '112' + with open("regmap.cfg") as f: + for cfgline in f: + try: + (regexp, type, hr) = cfgline.split('!') + + if re.search(regexp,line): + print('Autodetected '+ hr) + return type + + except: + print("Couldn't interpret " + cfgline) if re.search(r'(^|:)[A-fa-f0-9]{32}$',line): print('Autodetected NTLM. Probably - or, it might be MD5 (100)x') @@ -445,7 +270,7 @@ def runhc( hashcathome, pwdfile, hashtype, dict, rules, inc, trailer, dicthome, r='rules'+pathsep+r else: if not re.search('^/',rules): - r=ruleshome+'/'+rules + r=ruleshome+pathsep+rules if dictoverride: d=dictoverride @@ -453,7 +278,7 @@ def runhc( hashcathome, pwdfile, hashtype, dict, rules, inc, trailer, dicthome, d='dict'+pathsep+d else: if not re.search('^/',dict): - d=dicthome+'/'+dict + d=dicthome+pathsep+dict if rightdictoverride: if not is_non_zero_file(rightdictoverride): @@ -529,18 +354,15 @@ def runhc( hashcathome, pwdfile, hashtype, dict, rules, inc, trailer, dicthome, btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' found.txt -r '+ruleshome+pathsep+'best64.rule --loopback '+trailer,hashcathome) btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' found.txt '+dicthome+'/last3.txt '+trailer,hashcathome) - if is_non_zero_file('dict/ofound.txt'): - btexeccwd(hcbin+' -a6 -m '+hashtype+' '+pwdfile+' dict/ofound.txt ?a?a -i '+trailer,hashcathome) - btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' dict/ofound.txt '+dicthome+'/last3.txt '+trailer,hashcathome) + if is_non_zero_file('dict/found.txt'): + btexeccwd(hcbin+' -a6 -m '+hashtype+' '+pwdfile+' dict/found.txt ?a?a -i '+trailer,hashcathome) + btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' dict/found.txt '+dicthome+'/last3.txt '+trailer,hashcathome) if dolast==1: - btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+dicthome+'/ofound.txt '+dicthome+'/last4.txt '+trailer,hashcathome) + btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+dicthome+'/found.txt '+dicthome+'/last4.txt '+trailer,hashcathome) if dolast==1 or nuke: btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' found.txt '+dicthome+'/last4.txt '+trailer,hashcathome) - if nuke: - btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' found.txt '+dicthome+'/last5.txt '+trailer,hashcathome) - if words: print("Using bog standard dictionary words with variations") btexeccwd(hcbin+' -a6 -m '+hashtype+' '+pwdfile+' '+dicthome+'/words.txt ?a?a -i '+trailer,hashcathome) @@ -588,12 +410,11 @@ def runhc( hashcathome, pwdfile, hashtype, dict, rules, inc, trailer, dicthome, print("Using dict and rules") btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' '+d+' -r '+r+' --loopback '+trailer+skip,hashcathome) - if dolast==1: + if dolast==1 or nuke: btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+d+' '+dicthome+'/last3.txt '+trailer,hashcathome) if nuke: btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+d+' '+dicthome+'/last4.txt '+trailer,hashcathome) - btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+d+' '+dicthome+'/last5.txt '+trailer,hashcathome) #get first line @@ -610,7 +431,6 @@ def getfirstline( file ): return first_line -#def copyfiletostdout( file ) #run a shell command def run_command(command): @@ -638,8 +458,39 @@ def main(): # setup my defaults hashtype = 'auto' # autodetect - hashcathome='./hashcat-4.1.0' - dicthome='./dict' + hashcathome='hashcat-5.1.0' + dicthome='dict' + ruleshome='rules' + + print("Loading config") + try: + + config = configparser.ConfigParser() + config.read("winhc.cfg") + + hashcathome = config.get('paths', 'hc') + + if re.search(r'\\$',hashcathome): + hashcathome=hashcathome[:-1] + + ruleshome = config.get('paths', 'rules') + + if not re.search(r'\\$',ruleshome): + ruleshome+='\\' + + dicthome = config.get('paths', 'dict') + + if not re.search(r'\\$',dicthome): + dicthome+='\\' + + + + print("Ruleshome "+ruleshome) + + print("Dicthome "+dicthome) + print("HChome "+hashcathome) + except: + print("Error reading config files, so going with default dicts and rules") # declarations trailer='' @@ -714,6 +565,9 @@ def main(): inhash=args.hash crib=args.crib + if infile is not None: + infile=os.path.abspath(infile) + if crib is not None: crib=os.path.abspath(crib) @@ -738,42 +592,28 @@ def main(): prince=args.prince omen=args.omen - #platform identification - try: - loc=os.path.dirname(os.path.realpath(__file__)) - except: - loc="C:" - - if re.match(r'^/',loc): - stdoutdata = subprocess.check_output("uname -a", shell=True) - uname=bytearray(stdoutdata).decode() - - if re.match(r'Linux',uname): - pathstyle='unix' - unix=1 - crackopts=crackopts+" -w4 " - hashcathome='./hashcat-5.0.0' - ruleshome='./hashcat-5.0.0/rules' - exe='.bin' - else: - if not show: - print("Running under cygwin") - pathstyle='win32' - hashcathome='./hashcat-4.0.1' #relative path issues with 4.10 - ruleshome='./hashcat-4.0.1/rules' - cygwin=1 - exe='.exe' + p_os=platform.system() + + if re.match(r'Linux',p_os): + pathstyle='unix' + unix=1 + crackopts=crackopts+" -w4 " + hashcathome='./hashcat-5.1.0' + ruleshome='./hashcat-5.1.0/rules' + exe='.bin' else: - if re.match(r'[CDEF]:',loc): + if re.match(r'Windows',p_os): if not show: print("Running under win32") exe='.exe' - hashcathome='hashcat-4.0.1' #relative path issues with 4.10 + hashcathome='hashcat-5.1.0' #relative path issues with 4.10 pathstyle='win32' pathsep=r'\\' - ruleshome='hashcat-4.0.1\\rules' + ruleshome='hashcat-5.1.0\\rules' else: print("Unknown platform") + exit + trailer=crackopts+' --session hc' diff --git a/hashcrackwin.py b/hashcrackwin.py index 44ccfbb..abf7590 100755 --- a/hashcrackwin.py +++ b/hashcrackwin.py @@ -219,202 +219,18 @@ def selectparams( hashtype, nuke, ruleshome, dicthome ): #autodetect the hashtype given the first line of the file def autodetect( line ): - - if re.search(r'(^|:)\$1\$',line): - print('Autodetected md5crypt') - return '500' - - if re.search(r'(^|:)\$krb5tgs\$23\$',line): - print('Autodetected kerberos ticket type 13100') - return '13100' - - if re.search(r'(^|:)\$krb5pa\$23\$',line): - print('Autodetected kerberos type 7500') - return '7500' - - if re.search(r'(^|:)\$P\$',line): - print('Autodetected phpass') - return '400' - - if re.search(r'(^|:)\$H\$',line): - print('Autodetected phpass') - return '400' - - if re.search(r'(^|:)\$8\$',line): - print('Autodetected Cisco type 8 (pbkdf2-sha256)') - return '9200' - - if re.search(r'(^|:)\$9\$',line): - print('Autodetected Cisco type 9 (scrypt)') - return '9300' - - if re.search(r'(^|:)sha1\$',line): - print('Autodetected Django SHA1') - return '124' - - if re.search(r'(^|:)\$S\$',line): - print('Autodetected Drupal') - return '7900' - - if re.search(r'(^|:)\$PHPS\$',line): - print('Autodetected PHPS') - return '2612' - - if re.search(r'(^|:)(A|a)dministrator:500:[A-Fa-f0-9]{32}:[A-Fa-f0-9]{32}:',line): - print('Autodetected pwdump') - return 'pwdump' - - if re.search(r'[^:]+:\d+:[A-Fa-f0-9]{32}:[A-Fa-f0-9]{32}:',line): - print('Autodetected pwdump') - return 'pwdump' - - if re.search(r'(^|:)[a-f0-9]{32}:[A-Za-z0-9_]{1,10}$',line): - print('Autodetect postgres MD5') - return '12' - - if re.search(r'(^|:)\$2(a|b|y)',line): - print('Autodetected bcrypt') - return '3200' - - if re.search(r'(^|:)sha512:',line): - print('Autodetected Cisco sha512 pbkdf2') - return '12100' - - if re.search(r'(^|:)\$5\$',line): - print('Autodetected sha256crypt') - return '7400' - - if re.search(r'(^|:)\$6\$',line): - print('Autodetected sha512crypt') - return '1800' - - if re.search(r'(^|:)[A-Fa-f0-9]{32}:[A-Fa-f0-9]{13,14}$',line): - print('Autodetected DCC / ms cache') - return '1100' - - if re.search(r'(^|:)[A-Fa-f0-9]{32}:[A-Fa-f0-9]{6}$',line): - print('Autodetected vBulletin (2611)') - return '2611' - - if re.search(r'(^|:)[A-Fa-f0-9]{32}:.{5}$',line): - print('Autodetected IPB (2811)') - return '2811' - - if re.search(r'(^|:)[A-Fa-f0-9{32}:[A-Fa-f0-9]{49}$',line): - print('Autodetected Citrix netscaler') - return '8100' - - if re.search(r'(^|:)[A-Fa-f0-9]{126,130}:[A-Fa-f0-9]{40}$',line): - print('Autodetected IPMI2') - return '7300' - - if re.search(r'(^|:)[A-Za-z0-9\./]{43}$',line): - print('Autodetected Cisco type 4') - return '5700' - - if re.search(r'(^|:)[A-Fa-f0-9]{16}:[A-Fa-f0-9]{32}:[A-Fa-f0-9]{106}$',line): - print('Autodetected NetLMv2') - return '5600' - - if re.search(r'(^|:)[A-Fa-f0-9]{32}:[A-Fa-f0-9]{210}$',line): - print('Autodetected NetLMv2') - return '5600' - if re.search(r':[a-fA-f0-9]{48}:[a-fA-f0-9]{48}:',line): - print('Autodetected NetLMv1') - return '5500' - - if re.search(r'(^|:)[A-Za-z0-9\./]{16}$',line): - print('Autodetected Cisco ASA') - return '2400' - - if re.search(r'(^|:)[A-Za-z0-9\./]{13}$',line): - print('Autodetected descrypt') - return '1500' - - if re.search(r'(^|:)[A-Fa-f0-9]{40}$',line): - print('Autodetected SHA1') - return '100' - - if re.search(r'(^|:)[A-Fa-f0-9]{64}$',line): - print('Autodetected SHA256') - return '1400' - - if re.search(r'(^|:)[A-Fa-f0-9]{96}$',line): - print('Autodetected SHA384') - return '10800' - - if re.search(r'(^|:)[A-Fa-f0-9]{128}$',line): - print('Autodetected SHA512') - return '1700' - - if re.search(r'(^|:)[A-Fa-f0-9]{786}',line): - print('Autodetected WPA/WPA2') - return '2500' - - if re.search(r'(^|:)\$apr1\$',line): - print('Autodetected apache MD5\n') - return '1600' - - if re.search(r'(^|:)\$DCC2',line): - print('Autodetected DCC2 / mscache2') - return '2100' - - if re.search(r'(^|:)\{SHA\}',line): - print('Autodetected nsldap SHA1') - return '101' - - if re.search(r'(^|:)\{SSHA256\}',line): - print('Autodetected ldap SHA256') - return '1411' - - if re.search(r'(^|:)\{SSHA512\}',line): - print('Autodetected ldap SHA512') - return '1711' - - if re.search(r'(^|:)\{SSHA\}',line): - print('Autodetected ldap SSHA1') - return '111' - - if re.search(r'(^|:)0x0100',line): - if re.search(r'(^|:)0x[A-Fa-f0-9]{52}$',line): - print('Autodetected MSSQL2005') - return '132' - if re.search(r'(^|:)0x[A-Fa-f0-9]{92}$',line): - print('Autodetected MSSQL2000') - return '131' - - if re.search(r'(^|:)0x0200',line): - print('Autodetected MSSQL2012+') - return '1731' - - if re.search(r'(^|:)\{smd5\}',line): - print('Autodetected AIX smd5') - return '6300' - - if re.search(r'(^|:)\{ssha1\}',line): - print('Autodetected AIX ssha1') - return '6700' - - if re.search(r'(^|:)\{ssha256\}',line): - print('Autodetected AIX ssha256') - return '6400' - - if re.search(r'(^|:)\{ssha512\}',line): - print('Autodetected AIX ssha512') - return '6500' - - if re.search(r'(^|:)[A-Fa-f0-9]{40}$',line): - print('Autodetected MySQL5') - return '8100' - - if re.search(r'(^|:)[A-fa-f0-9]{60}$',line): - print('Autodetected Oracle (112) - but it needs a hash between the first 40 and last 20 for some reason') - return '112' - - if re.search(r'(^|:)[A-fa-f0-9]{40}:[A-fa-f0-9]{20}$',line): - print('Autodetected Oracle (112)') - return '112' + with open("regmap.cfg") as f: + for cfgline in f: + try: + (regexp, type, hr) = cfgline.split('!') + + if re.search(regexp,line): + print('Autodetected '+ hr) + return type + + except: + print("Couldn't interpret " + cfgline) if re.search(r'(^|:)[A-fa-f0-9]{32}$',line): print('Autodetected NTLM. Probably - or, it might be MD5 (100)x') @@ -601,14 +417,14 @@ def main(): # setup my defaults hashtype = 'auto' # autodetect - hashcathome = 'hashcat-4.0.1' + hashcathome = 'hashcat-5.1.0' dicthome='dict' ruleshome='rules' print("Loading config") -# try: - if True: + try: + config = configparser.ConfigParser() config.read("winhc.cfg") @@ -633,8 +449,8 @@ def main(): print("Dicthome "+dicthome) print("HChome "+hashcathome) - # except: - # print("Error reading config files, so going with default dicts and rules") + except: + print("Error reading config files, so going with default dicts and rules") # declarations trailer='' diff --git a/setupbin.py b/setupbin.py new file mode 100755 index 0000000..8d17512 --- /dev/null +++ b/setupbin.py @@ -0,0 +1,24 @@ +#setup.py +import sys, os +from cx_Freeze import setup, Executable + +__version__ = "1.0.1" + +include_files = ['regmap.cfg','hashcrack.cfg','map.cfg','quickmap.cfg','rules/l33tnsa.rule','rules/leet2.rule','rules/l33tpasspro.rule','rules/l33t64.rule','rules/best64.rule','rules/null.rule','dict/Top95Thousand-probable.txt','dict/words.txt','tests/kerb7500.txt','dict/last3.txt','dict/phrases.txt','dict/last4.txt'] + +# ,'dict/Top258Million-probable.txt','dict/Top32Million-probable.txt','cracked-passwords.txt'] +excludes = ["tkinter"] +packages = ["cx_freeze", "re", "base64", "os","sys","sqlite3","shutil","argparse","urllib","zipfile","tempfile","time","stat","configparser","platform"] + +setup( + name = "hashcrack", + description='Password cracking helper', + version=__version__, + options = {"build_exe": { + 'packages': packages, + 'include_files': include_files, + 'excludes': excludes, + 'include_msvcr': True, +}}, +executables = [Executable("hashcrack.py",base=None)] +) diff --git a/setupexe.py b/setupexe.py index a8a4cc6..1a575ad 100755 --- a/setupexe.py +++ b/setupexe.py @@ -4,9 +4,7 @@ __version__ = "1.1.0" -include_files = ['winhc.cfg','map.cfg','quickmap.cfg','rules/l33tnsa.rule','rules/l33tpasspro.rule','rules/l33t64.rule','rules/null.rule','dict/Top95Thousand-probable.txt','dict/words.txt','tests/kerb7500.txt'] - -# ,'dict/Top258Million-probable.txt','dict/Top32Million-probable.txt','cracked-passwords.txt'] +include_files = ['regmap.cfg','winhc.cfg','map.cfg','quickmap.cfg','rules/null.rule','tests/kerb7500.txt','tests/netlmv2.txt'] excludes = ["tkinter"] packages = ["cx_freeze", "re", "base64", "os","sys","sqlite3","shutil","argparse","urllib","zipfile","tempfile","time","stat","configparser"]