-
-
Save iantho/63338f424cd22ce822da to your computer and use it in GitHub Desktop.
| """ | |
| The MIT License (MIT) | |
| Copyright (c) 2012-2025 Ian Thomas | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in | |
| all copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| THE SOFTWARE. | |
| """ | |
| import os | |
| import string | |
| import itertools | |
| import subprocess | |
| # SETTINGS ==================================================================== | |
| max_combination_size = 3 | |
| password_components_file = "password_components.txt" | |
| truecrypt_device = "\\Device\\Harddisk1\\Partition1" | |
| truecrypt_exe = "C:\\Program Files\\TrueCrypt\\truecrypt.exe" | |
| # FUNCTIONS =================================================================== | |
| def read_password_components(): | |
| if not os.path.exists(password_components_file): | |
| raise RuntimeError("Password components file not found: '%s'" % password_components_file ) | |
| file = open( password_components_file, "r" ) | |
| password_components = file.readlines() | |
| if not password_components: | |
| raise RuntimeError("Password components file is empty!") | |
| password_components = list(map( lambda s: s.strip(), password_components )) # strip trailing newlines from each line | |
| print(f"Read {len(password_components)} password components: {password_components}") | |
| return password_components | |
| def find_password_combination( password_components, combination_size ): | |
| print(f"\nTrying passwords of combination size {combination_size}...\n") | |
| product = itertools.product( password_components, repeat=combination_size ) | |
| for prod in product: | |
| password = ''.join(prod) | |
| print(f"\tTrying password: '{password}'") | |
| truecrypt_command = "\"%s\" /q /s /v %s /lT /m ro /a /p \"%s\" /b" % ( truecrypt_exe, truecrypt_device, password ) | |
| process = subprocess.Popen( truecrypt_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) | |
| return_code = process.wait() # wait until TrueCrypt has finished trying current password | |
| ( stdout, stderr ) = process.communicate() | |
| if stderr: | |
| print(f"Error: '{stderr}'") | |
| return False | |
| if return_code == 0: | |
| print(f"\nPassword found: {password}") | |
| return True | |
| return False | |
| def find_password(): | |
| password_components = read_password_components() | |
| for i in range( 1, max_combination_size + 1 ): | |
| if find_password_combination( password_components, i ): | |
| return True | |
| return False | |
| # MAIN ======================================================================== | |
| print(f"Hunting TrueCrypt password for device '{truecrypt_device}'...") | |
| try: | |
| success = find_password() | |
| if success: | |
| print("Success!") | |
| else: | |
| print("Failed!") | |
| except Exception as ex: | |
| print(f"Fatal Error: {ex}") |
Hi, can you update this script for the python 3.33. It does not run.
Thanks
Ian
Online I found this:
This is a Python 3 incompatibility: under Python 3, map
no longer returns a list but an interator (and you cannot call
len on an iterator). Fix: enclose the map call in list(...).
But I do not know python at all.
Hi, can you update this script for the python 3.33. It does not run. Thanks Ian
Hey @IanD26 - yes of course, I'll take a look as soon as I can...
Hi @IanD26 - a couple of important things have changed since I last looked at this TrueCrypt script many years ago:
- I now develop using a Mac rather than Windows
- TrueCrypt is no longer actively maintained, and has been superseded by VeraCrypt
I already released a port of this script that is compatible with VeraCrypt. Are you able to use that updated version instead by any chance?
https://gist.github.com/iantho/78ca710215c112f152c301db198176da
Hi again @IanD26 - if you'd prefer to try an updated version of this original script, I've just made some changes and it now appears to be compatible with Python3. Please keep in mind that I don't have access to a Windows machine with TrueCrypt, so I can't test it properly, but I think it's probably okay now!
Simple, but saved my neck in a pinch!
Thanks!