LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-26-2013, 12:34 AM   #1
GNewbie
Member
 
Registered: Sep 2005
Distribution: (U/K/X)buntu 6.1 (newer box) / D*mn Small Linux (older box)
Posts: 269

Rep: Reputation: 31
Expect TCL Programming pProblem


Hi All,

I'm developing TCL code to enter a list of passwords into ecryptfs in order to find which password is accurate. I know the base of the password, but I'm missing the cap status and the charcters for the last two digits, but I have the possible characters narrowed down. The bottom line is a I have about 200-250 password I need to feed into ecryptfs.

I coded the following and I will explain the resulting error at the end of the code

Code:
#!/usr/bin/expect

set timeout 10

#Set variables here  prefer incrementing through list

set pwlist[list Pass1 Pass2]      

foreach password $pwlist {

spawn sudo "ecryptfs-recover-private"

expect {
  timeout { send_user "\nTime Out Hit\n"; puts "$password\r"; exit 1 }
  eof { send_user "\nEnd of file hit, attempt terminated \n"; exit 1 }
  
  if {"Try to recover this directory? [Y/n]: "} {
     send "y\r"
  } elseif {"Do you know your LOGIN passphrase? [Y/n] "} {
     send "y\r" 
  } elseif {"Passphrase: "} {
     send "$password\r" 
  } else {
     puts "end of expect if statement"
  }

}

}
ecryptfs responds:

Try to recover this directory? [Y/n]:

The Expect response should be "Y"

Then ecryptfs asks:

Do you know your LOGIN passphrase? [Y/n]

The Expect response should be "Y"

Then it asks:

Passphrase:

The Expect response should be to enter the current password in the list.

The result:

"Try to recover this directory? [Y/n]: " is displayed in the terminal and nothing happens until it times out. If I enter the Y, nothing happens until it times out. The first password int he list is displayed in the terminal afer it times out.

I think the problem likely lies here:

"if {"Try to recover this directory? [Y/n]: "}"

My guess is it should be in the form:

"if {$return_var = "Try to recover this directory? [Y/n]: "}" or some such.

I can't find anything to guide my way, so any help is appreciated.

TIA...
 
Old 03-27-2013, 02:16 AM   #2
GNewbie
Member
 
Registered: Sep 2005
Distribution: (U/K/X)buntu 6.1 (newer box) / D*mn Small Linux (older box)
Posts: 269

Original Poster
Rep: Reputation: 31
Update - I used the autoexpect program to help me dial in the details of my code. I have a working version that cycles through ecryptfs password input and I will post it below.

First, though, I have three questions.

1. I want to create a list in TCL that isn't all on one line.

set pwlist[list item1 item2 --what goes here so that a new line isn't registered--
item3 item4]

The items in this list would be item1, item2, item3 and item4.

I tried a \ character, but that didn't work.

2. I don't know what output will come when the right password is entered. What code in TCL will abort the program once unidentified program output is encountered?

On to the code that is working as (1. as long as the list text is all on one line and 2. I don't know what will happen when the right password is input... will the program abort or will it continue on? I don't know)

3. Some of the passwords I tested had a $ character in them, but expect choked because it thought it was an unassigned variable. How can I fix this?

Code:
#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Wed Mar 27 04:45:46 2013
# Expect and autoexpect were both written by Don Libes, NIST.
#
# Note that autoexpect does not guarantee a working script.  It
# necessarily has to guess about certain things.  Two reasons a script
# might fail are:
#
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts.  If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character.  This
# pacifies every program I know of.  The -c flag makes the script do
# this in the first place.  The -C flag allows you to define a
# character to toggle this mode off and on.

set force_conservative 0  ;# set to 1 to force conservative mode even if
			  ;# script wasn't run conservatively originally
if {$force_conservative} {
	set send_slow {1 .1}
	proc send {ignore arg} {
		sleep .1
		exp_send -s -- $arg
	}
}

set timeout 30
spawn $env(SHELL)
match_max 100000

set pwlist[list test1 test2]

foreach password $pwlist {

spawn sudo "ecryptfs-recover-private"

expect -exact "Try to recover this directory? \[Y/n\]: "
send -- "y\r"

expect -exact "y\r
INFO: Found your wrapped-passphrase\r
Do you know your LOGIN passphrase? \[Y/n\] "
send -- "y\r"

expect -exact "y\r
INFO: Enter your LOGIN passphrase...\r
Passphrase: "
send -- "$password\r"

expect -exact "\r
Error: Unwrapping passphrase and inserting into the user session keyring failed \[-5\]\r
Info: Check the system log for more information from libecryptfs\r
\]0;xubuntu@xubuntu: ~xubuntu@xubuntu:~\$ "
puts $password

}

Last edited by GNewbie; 03-27-2013 at 02:21 AM.
 
Old 03-28-2013, 11:59 PM   #3
GNewbie
Member
 
Registered: Sep 2005
Distribution: (U/K/X)buntu 6.1 (newer box) / D*mn Small Linux (older box)
Posts: 269

Original Poster
Rep: Reputation: 31
I've found solutions to two of the three problems:

1. I want to create a list in TCL that isn't all on one line.

set pwlist[list item1 item2 --what goes here so that a new line isn't registered--
item3 item4]

Answer:

set pwlist[list item1 item2 \
item3 item4]

The pwlist list includes item1, item2, item3 and item4.

The items in this list would be item1, item2, item3 and item4.


I tried a \ character, but that didn't work.

Update, the \ works. I received an error and assumed it was related to the \ but was probably related to not escaping the $ sign (like this: \$)

2. I don't know what output will come when the right password is entered. What code in TCL will abort the program once unidentified program output is encountered?

On to the code that is working as (1. as long as the list text is all on one line and 2. I don't know what will happen when the right password is input... will the program abort or will it continue on? I don't know)

No answer yet. Any guidance would be appreciated.

3. Some of the passwords I tested had a $ character in them, but expect choked because it thought it was an unassigned variable. How can I fix this?

Answer: The $ sign must be escaped with the \ character. Example: \$
 
Old 03-29-2013, 12:30 AM   #4
GNewbie
Member
 
Registered: Sep 2005
Distribution: (U/K/X)buntu 6.1 (newer box) / D*mn Small Linux (older box)
Posts: 269

Original Poster
Rep: Reputation: 31
Hi All,

Please note that the set assignment is displayed as:

"set pwlist[list Pass1 Pass2]"

Note their should be a space between "pwlist" and "[list Pass1 Pass2]"

I don't know how to make this space display correctly.

Last edited by GNewbie; 03-29-2013 at 12:31 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
expect (Tcl) question kristof_v Programming 2 01-24-2013 06:32 AM
[SOLVED] Is it possible to control VI with tcl and expect ? Stuart07 Programming 2 03-08-2011 09:30 AM
TCL e EXPECT gustavolinux Programming 1 10-17-2008 10:03 AM
TCL, Expect, for Rsync - Please Help dholingw Programming 2 02-08-2004 11:27 AM


All times are GMT -5. The time now is 04:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration