I am attempting to write a script that will use the command line to run thru a list of possible passwords to mount a VeraCrypt file. What I have so far will mount a test file given the correct password, but if supplied an incorrect password I get a pop up window giving that notification followed by the gui window for entering another password.
I'm not quite clear exactly what you are trying to achieve, but if the task is simply to iterate through a list of passwords until the right one (if any) is found and thus mount the volume, the best approach is probably to work out how your choice of scripting language can input passwords from a file (with one password per line).
A simple batch file to do this, for example, is:
@echo off
for /f %%a in (F:\test.txt) do veracrypt /v F:\test /l E /hash sha512 /q /s /e /c n /m rm /m label=Test /nowaitdlg /p %%a & if exist E: exit
exit
The file 'test.txt' contained the passwords test1 - test9 (one per line); the correct password for my test VC volume was 'test5'. Success is visibly demonstrated by an Explorer window opening, whereupon the script's test of success, the existence of 'E:', causes the script to exit (and not try any more possibilities).
Last edit: Adrian Kentleton 2018-06-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As Adrian did in his sample, the key point is to use the /s or /silent
command line switch to prevent VeraCrypt from displaying any UI.
Thus, even if an error happens, no popup window is displayed and the
exit code of the process can be used to check for success (exit code 0)
or failure (exit code 1).
Adrian doesn't check the exit code but rather the driver letter
existence. It is up to you to decide which way is better.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Addendum: Note that my 'simple batch file' works if there are no spaces in the passwords! To deal with spaces, you need to add "tokens=*" between /f and first %%a, and use /p "%%a" instead of /p %%a.
And, a simple way to capture the correct password is to add echo %%a > E:\pwd.txt & between if exist E: and (first) exit.
Also note that this will not work with passwords that contain &, even in quotes. You should never use ampersands in passwords if you want to enter them on a Windows command line; they are always interpreted with their special meaning of 'what follows is a new command' (even if enclosed in double quotes), usually meaning that the rest of the command line, not being a recognised command, is ignored, leading eg to mounting failure or other parameters not being applied.
Last edit: Adrian Kentleton 2018-06-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
was very helpful for me to but after ten passwords in the list the script seems to interrupt or veracrypt collapses. is there possibility to let it work with a delay or autopause between each password?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Tyler - try the following, which is an integrated version of the code snippets in earlier posts, and uses variables to keep the command lines shorter. I've tested it with a list of 20 passwords, some with spaces, some not, and it works as expected whether the correct password is in the list or not. I've put a 'timeout' in between iterations of the loop. Edit it to suit your situation:
Thx a lot for your quick reponse and that you still aware of this thread after so many years. I didn't expect this. The integration works but however I get always the "Password not found!" message before the exit even if the correct testpassword was found. So far I still can't say if the timeout is needed because Veracrypt gives just no response if or which password in the list is in processing but in my case I got to try all algorithms which takes pretty long for one line and I'm sure I won't find the password I'm searching for (hidden volume). I forgot it and so far I seem to be not even near the correct password but with your help here it saves me a lot of lifetime. Again, thank you very much!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
👍👍👍
Maybe due to my older system: If the bat is processing a longer list and already closed veracrypt is still processing and not mounted. Tried this in a testvolume with correct password, the bat was already closed and around 7minutes later the volume was mounted. I did it with veracrypt and veracrypt-x64. Difficulty in a list without knowing if the correct password is in it to know wether veracrypt is still running for mounting process or ended. I only see it if the blue circle is still wheeling while mouseover the veracrypt window.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've tested my script on an outer/hidden volume, and it works as expected. That is, it tries a password with the outer volume first, then the hidden volume. So, if the passwords for the outer and hidden volumes are in the list, I can mount either at will, just by which password appears in the list first.
You do have a problem if you cannot specify the hash, but have to try all possibilities; it slows things down considerably. But I cannot reproduce your issue. I don't think the 'timeout' in the for ... do loop helps at all.
However, I'm puzzled by your reference to "the blue circle is still wheeling while mouseover the veracrypt window. " With my script, the VC GUI should not appear (it uses the/q /s parameters).
Could you post your script (with any sensitive data replaced by generic terms)?
Also, is your list of passwords a simple text file (eg created in Notepad) with one password per line, and no missing lines?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm very inexperienced so I let it run the whole day. In shorter test rounds I learned all correct pw tests solved/mounted first after the bat was closed. In most cases after 3-5minutes. The shorter the lopp timeout, f.e. 5-10sec, the longer it took until the volume was mounted. So I decided to go up to timeout /t 18 to be sure that the mounting was not triggered if no password has been correct. Otherwise Veracrypt will try to mount in a new round if I restart the bat file with another list but the previous session has not been ended. I think this is what I meant by that the gui has still Windows wait cursor (hourglass/blue circle) because I have no other visual check up that the volume is still tried to mount or failed. Even Exiting in 300 seconds and correct password, and sucessful mounting I get the "Password not found" message. Unsure why. But so far it works pretty well and I made my lists longer. Tomorrow it should be through with all possible combinations I can remember of my lost one. Think I won't get it back nut at least I have not to sit here for hours and to type it in manually. ^^
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
a. You've one too many percent signs in the third line of your for ... do loop: should be echo %%a >.
b. Need to increase the actual timeout figure to 300 in last line, if that's what you want: timeout /t 300.
What operating system are you using, and what version of VC?
More tomorrow.
Last edit: Adrian Kentleton 2020-06-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tested my script with the %%%a typo, but it still worked as expected, so that is not relevant to your issue.
Trying to think of other issues. How old is the volume you are trying to deal with ie what version of VC was used to create it? Or was it possibly created with Truecrypt?
It might be possible to create a 'loop within a loop' to try each hash separately and explicitly, but I'm not sure whether the hashes currently used are the same as hashes used in earlier versions.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am attempting to write a script that will use the command line to run thru a list of possible passwords to mount a VeraCrypt file. What I have so far will mount a test file given the correct password, but if supplied an incorrect password I get a pop up window giving that notification followed by the gui window for entering another password.
path="c:/program files/veracrypt"
os.chdir(path)
prgmrun="veracrypt /v testlocker /l h /p "+ currpass + " /q"
x=subprocess.call(prgmrun)
print(x)
I am not sure if it is a true value, but at this time x returns 0 for a succesful mount and 1 after I clear/cancel the pop up windows.
My question is, does anyone know a way to prevent the error windows but capture a success or failure to mount at the command line. Thanks in advance.
I'm not quite clear exactly what you are trying to achieve, but if the task is simply to iterate through a list of passwords until the right one (if any) is found and thus mount the volume, the best approach is probably to work out how your choice of scripting language can input passwords from a file (with one password per line).
A simple batch file to do this, for example, is:
The file 'test.txt' contained the passwords test1 - test9 (one per line); the correct password for my test VC volume was 'test5'. Success is visibly demonstrated by an Explorer window opening, whereupon the script's test of success, the existence of 'E:', causes the script to exit (and not try any more possibilities).
Last edit: Adrian Kentleton 2018-06-04
As Adrian did in his sample, the key point is to use the /s or /silent
command line switch to prevent VeraCrypt from displaying any UI.
Thus, even if an error happens, no popup window is displayed and the
exit code of the process can be used to check for success (exit code 0)
or failure (exit code 1).
Adrian doesn't check the exit code but rather the driver letter
existence. It is up to you to decide which way is better.
Addendum: Note that my 'simple batch file' works if there are no spaces in the passwords! To deal with spaces, you need to add
"tokens=*"
between/f
and first%%a
, and use/p "%%a"
instead of/p %%a
.And, a simple way to capture the correct password is to add
echo %%a > E:\pwd.txt &
betweenif exist E:
and (first)exit
.Also note that this will not work with passwords that contain
&
, even in quotes. You should never use ampersands in passwords if you want to enter them on a Windows command line; they are always interpreted with their special meaning of 'what follows is a new command' (even if enclosed in double quotes), usually meaning that the rest of the command line, not being a recognised command, is ignored, leading eg to mounting failure or other parameters not being applied.Last edit: Adrian Kentleton 2018-06-04
was very helpful for me to but after ten passwords in the list the script seems to interrupt or veracrypt collapses. is there possibility to let it work with a delay or autopause between each password?
Thank you both very much for the assistance. That was exactly what I was looking for.
Tyler - try the following, which is an integrated version of the code snippets in earlier posts, and uses variables to keep the command lines shorter. I've tested it with a list of 20 passwords, some with spaces, some not, and it works as expected whether the correct password is in the list or not. I've put a 'timeout' in between iterations of the loop. Edit it to suit your situation:
Thx a lot for your quick reponse and that you still aware of this thread after so many years. I didn't expect this. The integration works but however I get always the "Password not found!" message before the exit even if the correct testpassword was found. So far I still can't say if the timeout is needed because Veracrypt gives just no response if or which password in the list is in processing but in my case I got to try all algorithms which takes pretty long for one line and I'm sure I won't find the password I'm searching for (hidden volume). I forgot it and so far I seem to be not even near the correct password but with your help here it saves me a lot of lifetime. Again, thank you very much!
Tyler - here's a version which echoes the password being tried. I'll give some thought to the hidden volume issue later today.
👍👍👍
Maybe due to my older system: If the bat is processing a longer list and already closed veracrypt is still processing and not mounted. Tried this in a testvolume with correct password, the bat was already closed and around 7minutes later the volume was mounted. I did it with veracrypt and veracrypt-x64. Difficulty in a list without knowing if the correct password is in it to know wether veracrypt is still running for mounting process or ended. I only see it if the blue circle is still wheeling while mouseover the veracrypt window.
I've tested my script on an outer/hidden volume, and it works as expected. That is, it tries a password with the outer volume first, then the hidden volume. So, if the passwords for the outer and hidden volumes are in the list, I can mount either at will, just by which password appears in the list first.
You do have a problem if you cannot specify the hash, but have to try all possibilities; it slows things down considerably. But I cannot reproduce your issue. I don't think the 'timeout' in the
for ... do
loop helps at all.However, I'm puzzled by your reference to "the blue circle is still wheeling while mouseover the veracrypt window. " With my script, the VC GUI should not appear (it uses the
/q /s
parameters).Could you post your script (with any sensitive data replaced by generic terms)?
Also, is your list of passwords a simple text file (eg created in Notepad) with one password per line, and no missing lines?
I have it this way now
I'm very inexperienced so I let it run the whole day. In shorter test rounds I learned all correct pw tests solved/mounted first after the bat was closed. In most cases after 3-5minutes. The shorter the lopp timeout, f.e. 5-10sec, the longer it took until the volume was mounted. So I decided to go up to
timeout /t 18
to be sure that the mounting was not triggered if no password has been correct. Otherwise Veracrypt will try to mount in a new round if I restart the bat file with another list but the previous session has not been ended. I think this is what I meant by that the gui has still Windows wait cursor (hourglass/blue circle) because I have no other visual check up that the volume is still tried to mount or failed. EvenExiting in 300 seconds
and correct password, and sucessful mounting I get the "Password not found" message. Unsure why. But so far it works pretty well and I made my lists longer. Tomorrow it should be through with all possible combinations I can remember of my lost one. Think I won't get it back nut at least I have not to sit here for hours and to type it in manually. ^^Two quick points about your script:
a. You've one too many percent signs in the third line of your
for ... do
loop: should beecho %%a >
.b. Need to increase the actual timeout figure to 300 in last line, if that's what you want:
timeout /t 300
.What operating system are you using, and what version of VC?
More tomorrow.
Last edit: Adrian Kentleton 2020-06-15
I tested my script with the
%%%a
typo, but it still worked as expected, so that is not relevant to your issue.Trying to think of other issues. How old is the volume you are trying to deal with ie what version of VC was used to create it? Or was it possibly created with Truecrypt?
It might be possible to create a 'loop within a loop' to try each hash separately and explicitly, but I'm not sure whether the hashes currently used are the same as hashes used in earlier versions.