Last active
November 3, 2017 03:06
-
-
Save 2e3s/3f47bdf4baa3a039838ed34678510248 to your computer and use it in GitHub Desktop.
Recover partially forgotten password for Truecrypt/Veracrypt container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The MIT License (MIT) | |
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 subprocess | |
container_file = "C:\\container.hc" | |
executable = "C:\\Program Files\\VeraCrypt\\VeraCrypt.exe" | |
print("I'm running on %s" % container_file) | |
# password: test. Or dest, est, desd, tesd? Not sure, too many to try each one manually. | |
pattern = [['d', 't', ''], ['es'], ['t', 'd']] | |
def recurse(pattern_index, password): | |
if pattern_index == len(pattern): | |
print("Trying password: %s" % password) | |
# using the default and known hash (sha-512) to speed it up dramatically | |
command = "%s /hash sha-512 /q /v %s /l p /a /p %s /s /m ro" % (executable, container_file, password) | |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
return_code = process.wait() # wait until the decrypting has finished trying current password | |
(stdout, stderr) = process.communicate() | |
if stderr: | |
print("Error: '%s'" % stderr) | |
return False | |
if return_code == 0: | |
print("Password found: %s" % password) | |
return True | |
else: | |
for i in range(len(pattern[pattern_index])): | |
if recurse(pattern_index + 1, password + pattern[pattern_index][i]): | |
return True | |
return False | |
return False | |
recurse(0, '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment