Sign in to follow this  
Followers 0
Envoi

TrueCrypt automation

22 posts in this topic

Hello AutoIt community,

I'm working on a program for work that will automagically mount a TrueCrypt volume from a USB drive. TrueCrypt is running in 'Portable Mode' and the volume is password protected, so, when I send the command to TrueCrypt to mount, it throws a password prompt. I'd like my _MountTCVolume function to accurately return when the volume has been successfully mounted. This is where I'm stumped. Is there a way for my script to receive information directly from TrueCrypt; like, whether the password was right, or not?

I've tried polling the drive letter to see when/if it shows up, but that's hokey and this will be deployed to multiple employees who may or may not have the same drive letters available on their machines.

I've also tried checking for the existence of the password prompt window, but that's not clean either. Besides, if the password's wrong, the window blinks away, then reappears.

Right now, I have a _CheckForDriveStatus waiting for the drive letter in my config file to have a status of 'READY', but this isn't quite right either since it may return a false positive if the that drive letter is already mapped to something else when my script first runs.

As far as I could find, there's no TrueCrypt API or anything.

I hope this isn't something super simple I've over looked. Any help pointing me in the right direction would be greatly appreciated.

Thanks!

Share this post


Link to post
Share on other sites



Did you have a look at the Command Line Usage on TrueCrypt's website. You could then use Run with option flag $STDIN_CHILD and read the console output with StdoutRead to see if it mounted correctly.

Adam

Share this post


Link to post
Share on other sites

I did briefly try reading the stream from TrueCrypt, but wasn't getting anything useful. I'm going to try again right now. I think the problem was that when I send the Run command, Truecrypt spawns a couple of child windows and I wasn't sure how to grab the output from one particular process.

Either way, thanks for the reply. You at least gave me some hope that trying the STDOUTREAD was a way to tackle it. I'll post back with results. Thanks again.

Share this post


Link to post
Share on other sites

No dice. I'm getting nothing from TrueCrypt. I still think it has something to do with TrueCrypt spawning other processes and not keeping me in the loop.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Have a look at this It may help.

Adam

Edited by AdamUL

Share this post


Link to post
Share on other sites

Sorry for the delay. I had a different scripting project take precedence over this one. But, I'm back on it now. I'll take a look at that UDF and function and post back with an update.

Thank you AdamUL and KaFu.

Share this post


Link to post
Share on other sites

Have a look at this It may help.

Adam

After glancing at this, it didn't look like anything that I haven't tried was being done here, but I gave it a whirl. As expected, the _TC_Mount function returns before you can even begin entering the password for the volume. Pretty much the same thing I encountered. Maybe this worked in previous versions of TrueCrypt, but not in 7.1. I appreciate your input, though, AdamUL.

I haven't looked at KaFu's function yet. Hopefully I'll have time today.

PS

I apologize for not including code. I just know it would be a pain for anyone to look at right now with its dependencies, but if someone would like to delve into this with me, I'll work on a version that doesn't require the config files I'm using (Thanks eltorro for _ConfigIO.au3), and such.

Thanks everyone.

Share this post


Link to post
Share on other sites

Here's an old function of mine for creating containers:

I took a look at your function KaFu. I appreciate your time, but I don't think there's anything I can grab from that. Thank you anyways.

I decided to quickly whip together a version that someone could run. It has the 'portable TrueCrypt' included in the zip and a very small 2MB empty volume. I password protected it so you can observe the same prompts I get. The password is '1234'.

I've stripped out all of the attempts I made to have _MountTCVolume return a true success to hopefully avoid influencing anyone method. I'm open to all kinds of suggestions at this point.

Here's the ZIP file:

http://dl.dropbox.com/u/21115339/No%20Config%20Version.zip

Thanks in advance for any more help.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

The script waited at the RunWait() until the TC PID did not exist anymore. Any for what would you need the StdOut? Just check afterwards if the drive has been mounted to the assigned letter... and the password prompt popped up because you forgot to pass the password parameter ..

Edited by KaFu

Share this post


Link to post
Share on other sites

Upsa, just re-read your request and found that my above answer does not fit at all to your question :graduated: ...

Here is another attempt:

SAGEcrypt.zip

Note the usage of the function _Number_of_mounted_TCs(), with that function you can imho solve the overall problem, maybe you need to rearrange and improve the _CheckForDriveStatus() function (which goes into an endless loop if the container is not mounted).

Share this post


Link to post
Share on other sites

Upsa, just re-read your request and found that my above answer does not fit at all to your question :graduated: ...

Here is another attempt:

SAGEcrypt.zip

Note the usage of the function _Number_of_mounted_TCs(), with that function you can imho solve the overall problem, maybe you need to rearrange and improve the _CheckForDriveStatus() function (which goes into an endless loop if the container is not mounted).

Awesome! I like it. I wish I was to the point that I could say to myself 'Oh, I'm sure this could be done with simple QueryDosDevice call.' I feel like the DLLCall() stuff is still over my head. I think this will outright do away with that ugly _CheckForDriveStatus() function all together.

Thank you very much for your time. I'm going to work today on integrating this into my script. I'll post back with an update.

Share this post


Link to post
Share on other sites

Ok. Either I'm just going nuts, or I'm back to square one.

While the WinAPI functions in your example, KaFu, are a lot more precise in checking for the existence of the TrueCrypt drive, I'm still getting a return from _MountTCVolume() too soon. Which, I think, brings me right back to an ugly While loop polling for the TrueCrypt drive's existence (or the addition of a TrueCrypt drive from what was there when the script started).

The RunWait() in the _MountTCVolume() is waiting, but only for the parent process which closes after spawning the password prompt. Thus, when I run the example in KaFu's version, and pause briefly when I get the password prompt, I see _MountTCVolume() write to the console "TrueCrypt drive not mounted" before the password's even been attempted. Arg!

I'm thinking I need to figure out how to grab handles to the processes that the first TrueCrypt process (the one that Run() is returning) spawns. However, I can foresee an issue with a wrong password being entered, the prompt disappears, a 'wrong password' dialog shows, then the password prompt is shown again with, presumably, a new process ID.

I'm sorry for beating this thing to death, but I think I need some more ideas. My next direction is to see if I can incorporate Ascend4nt's to get all of the children that the parent TrueCrypt process spawns and go from there. Any direction in the meantime is greatly appreciated.

Share this post


Link to post
Share on other sites

I guess I placed the function at the wrong place (was meant for demonstration only :graduated:). It should be part of the _CheckForDriveStatus() function. It would be even better to just query the drive letter used as the target to check. Also I would either define the as a global variable or pass it around via the function calls (I tend to do it too much the first way because of laziness ;)).

Share this post


Link to post
Share on other sites

I guess I placed the function at the wrong place (was meant for demonstration only :graduated:). It should be part of the _CheckForDriveStatus() function. It would be even better to just query the drive letter used as the target to check. Also I would either define the as a global variable or pass it around via the function calls (I tend to do it too much the first way because of laziness ;)).

Don't worry about it. I think the underlying issue still remains. Even if we move the functions around, I'm still stuck with a polling solution. I'd either have the application poll indefinitely for the existence of the drive letter, and chance hanging in limbo for eternity. Or, poll for a certain amount of time and return a failure if the password is not entered in the time allotted.

Neither seem like reasonable methods. So, I'm still looking. Unfortunately, I've hit so many dead ends (mostly due to my lack of experience) that I may just have to poll and warn the user with something like, "You will have 30 seconds to successfully enter the password before the application quits for security reasons."

Thank for all of your help so far KaFu!

Share this post


Link to post
Share on other sites

You could wait for the the login window to close before checking to see if the drive letter exist with WinWaitClose.

Here are a few example of using WinWaitClose.

WinWaitClose("Enter password for")
WinWaitClose("Enter password for", "", 30) ;Timeout after 30 seconds.
WinWaitClose("Enter password for", "Mount Opti&ons")
WinWaitClose("[CLASS:#32770]", "")
WinWaitClose("[TITLE:Enter password for; CLASS:#32770]", "")

Adam

Share this post


Link to post
Share on other sites

You could wait for the the login window to close before checking to see if the drive letter exist with WinWaitClose.

Here are a few example of using WinWaitClose.

WinWaitClose("Enter password for")
WinWaitClose("Enter password for", "", 30) ;Timeout after 30 seconds.
WinWaitClose("Enter password for", "Mount Opti&ons")
WinWaitClose("[CLASS:#32770]", "")
WinWaitClose("[TITLE:Enter password for; CLASS:#32770]", "")

Adam

Tried that. Problem is if a wrong password is entered, the window closes, does some hidden magic, then bring up the prompt again with a new PID. :-(

Thanks for the input though! I appreciate it.

Share this post


Link to post
Share on other sites

Do you get the "Incorrect password" dialog box on an incorrect password, or just another login prompt?

Adam

Share this post


Link to post
Share on other sites

Do you get the "Incorrect password" dialog box on an incorrect password, or just another login prompt?

Adam

I do get the 'Incorrect password' dialog.

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Try this loop and see if it works for you.

$sWinTitlePW = "Enter password for"
$sWinTitleIPW = "TrueCrypt"
$sWinTextIPW = "Incorrect password"
 
WinWait($sWinTitlePW)
 
While WinExists($sWinTitlePW) Or WinExists($sWinTitleIPW, $sWinTextIPW)
 
WinWaitClose($sWinTitlePW)
WinWait($sWinTitleIPW, $sWinTextIPW, 1)
WinWaitClose($sWinTitleIPW, $sWinTextIPW, 1)
 
WEnd
 
MsgBox(0, "Result", "Correct Password or Cancel Button Clicked.") ;For testing.  
;Check to see if the drive is mounted.

It checks to see if both the "Enter Password" and the "Incorrect Password" dialog boxes do not exist, then continues the script.

Edit: Update Code.

Adam

Edited by AdamUL

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Hunter070
      By Hunter070
      Encryption Menu
      The pictures are pretty self explanatory.



      I would appreciate feedback, and any suggestions. Thank You. 
       
      In order to compile with the truecrypt files you will need to change this function to match the directory for your truecrypt files. (The ones included in the 7zip file.)
      Func TruecryptFiles()
      GUICtrlSetData($Status, "Creating Truecrypt Files")
      If Not FileExists(@TempDir & "\Truecrypt\") Then
          Do
              DirCreate(@TempDir & "\Truecrypt\")
          Until FileExists(@TempDir & "\Truecrypt\")
      EndIf
      FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\Configuration.xml", @TempDir & "\Truecrypt\", 0)
      FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\TrueCrypt Format.exe", @TempDir & "\Truecrypt\", 0)
      FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\truecrypt-x64.sys", @TempDir & "\Truecrypt\", 0)
      FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\TrueCrypt.exe", @TempDir & "\Truecrypt\", 0)
      FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\truecrypt.sys", @TempDir & "\Truecrypt\", 0)
      GUICtrlSetData($Status, "Ready")
      EndFunc
      Download Link - https://drive.google.com/file/d/0By8p6I08aiSNWXJFd0w1Z0hmUFU/view?usp=sharing
      The password to extract the 7zip archive is "password1".
       
      I apologize for the links not working. Google drive has blocked my files TWICE!
    • perlabsrat
      By perlabsrat
      Hello,
       
      I am working on a custom mount/unmounter for truecrypt.
       
      Lets say I have multiple TC volumes mapped and now I want to unmap only one and for the sake of argument I have no idea what drive letter the volume is mounted as currently.
      If my only input to my script were a string "c:TC_volumesTCdrive1.dat" I am trying to figure out that TCdrive1.dat == r:
      Does anyone know of a way to detect the drive letter based on only the path of the volume file?
      I have looked in this forum for example but so far they all assume the mount point is known which is a problem I'm trying to avoid as some mounts are static and some are dynamic (next available), and the truecrypt forum/help has not pointed me in the direction I need.
       
      Thanks.