From 06cab2cf7faf4cc3f79237482a83866989e488dc Mon Sep 17 00:00:00 2001 From: thor-vath Date: Thu, 3 Jul 2025 01:17:39 -0400 Subject: [PATCH] Update timecrack.py Replace FileType('r') with file opening using UTF-8 encoding. Add error handling with errors='ignore' to continue through encoding errors in a wordlist. Resolves a crash when wordlist contains non-UTF-8 encoded errors. --- extra-scripts/timecrack.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/extra-scripts/timecrack.py b/extra-scripts/timecrack.py index c362e13..6778b04 100755 --- a/extra-scripts/timecrack.py +++ b/extra-scripts/timecrack.py @@ -56,18 +56,28 @@ def main(): passwords that are popular in an organisation. """) + # Keep hash file as FileType since it's less likely to have encoding issues argparser.add_argument('hashes', type=FileType('r'), help='Output of timeroast.py') - argparser.add_argument('dictionary', type=FileType('r'), help='Line-delimited password dictionary') + # Change dictionary to just take the filename as a string + argparser.add_argument('dictionary', type=str, help='Line-delimited password dictionary') args = argparser.parse_args() crackcount = 0 - for rid, password in try_crack(args.hashes, args.dictionary): - print(f'[+] Cracked RID {rid} password: {password}') - crackcount += 1 + + # Open the dictionary file with proper encoding and error handling + try: + with open(args.dictionary, 'r', encoding='utf-8', errors='ignore') as dictfile: + for rid, password in try_crack(args.hashes, dictfile): + print(f'[+] Cracked RID {rid} password: {password}') + crackcount += 1 + except FileNotFoundError: + print(f'ERROR: Dictionary file not found: {args.dictionary}', file=sys.stderr) + sys.exit(1) + except IOError as e: + print(f'ERROR: Could not read dictionary file: {e}', file=sys.stderr) + sys.exit(1) print(f'\n{crackcount} passwords recovered.') if __name__ == '__main__': - main() - - + main() \ No newline at end of file