0

I'm completely new to using "expect" and clearly don't understand it at all well. My problem is that I used "encfs" to protect some files a while ago, and although I left myself a text file which included obfuscated hints about the password, I'm failing to remember/guess it. So, I'm pretty sure that it's one of a series of perhaps a hundred permutations, and I thought it would be easy to use expect to try them for me. So far, no luck there either!

I think expect has a scripting language, but I don't see where it's defined (and I was hoping not to learn an entire programming language just for this!)

Anyway, I created this script by copy-guess-and-fiddle:

#!/usr/bin/expect
set password [lindex $argv 0]
spawn echo Trying $password
spawn /usr/bin/encfs /home/simon/.safe /home/simon/safe
expect "Password: "
send "$password\r";
interact

Which tests a single password and seems to work when I use it on a newly created encfs system. However, then I tried to run it over all the permutations, which I've created in a file called "tries". I did this using another script:

#!/bin/bash

while read line
do
  echo trying $line
#  ./breakone.sh "$line"
  echo Status is $?
done < tries

(the first file is called "breakone.sh") If I run the script in the form shown, it iterates over the lines of text in the file "tries". But if I uncomment the call to the expect script, it immediately drops out after entering the expect script the first time. Furthermore, it drops out immediately. Normally, expect will take a short pause (~ 1/2 second, maybe) and report that the password is bad. But when triggered from the primary script, it drops back to the calling script immediately (I know it comes back to the caller, as it prints the status, and the iteration immediately quits.

I'm guessing this is somehow because expect has "taken over" standard input to the point that the while loop no longer reads from the file, but I have no clue where to go next.

Any suggestions would be most welcome!

(Edit, I tried changing from reading the file to using a here-document, but that didn't change anything).

1 Answers1

1

A quick fix is to use a different file descriptor for the while read loop:

while read line <&3
do
  echo trying $line
  ./breakone.sh "$line"
  echo Status is $?
done 3< tries

That leaves the default stdin alone

glenn jackman
  • 26,306