Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iantho
Created June 28, 2015 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iantho/63338f424cd22ce822da to your computer and use it in GitHub Desktop.
Save iantho/63338f424cd22ce822da to your computer and use it in GitHub Desktop.
TrueCrypt Password Hunter
"""
The MIT License (MIT)
Copyright (c) 2012 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 = map( lambda s: s.strip(), password_components ) # strip trailing newlines from each line
print "Read %d password components: %s" % ( len(password_components), password_components )
return password_components
def find_password_combination( password_components, combination_size ):
print "%sTrying passwords of combination size %d...%s" % ( os.linesep, combination_size, os.linesep )
product = itertools.product( password_components, repeat=combination_size )
for prod in product:
password = string.join( prod, '' )
print "\tTrying password: '%s'" % 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 "Error: '%s'" % stderr
return False
if return_code == 0:
print "%sPassword found: %s" % ( os.linesep, 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 "Hunting TrueCrypt password for device '%s'..." % truecrypt_device
try:
success = find_password()
if success:
print "Success!"
else:
print "Failed!"
except Exception as ex:
print "Fatal Error: %s" % ex
@SheldonPatnett
Copy link

Simple, but saved my neck in a pinch!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment