Using expect to try a series of passwords












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 "$passwordr";
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).










share|improve this question



























    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 "$passwordr";
    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).










    share|improve this question

























      0












      0








      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 "$passwordr";
      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).










      share|improve this question














      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 "$passwordr";
      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).







      expect






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 10 at 15:42









      Toby EggittToby Eggitt

      1074




      1074






















          1 Answer
          1






          active

          oldest

          votes


















          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






          share|improve this answer
























          • That seems to have done it, many thanks.

            – Toby Eggitt
            Feb 13 at 14:50











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1404163%2fusing-expect-to-try-a-series-of-passwords%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          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






          share|improve this answer
























          • That seems to have done it, many thanks.

            – Toby Eggitt
            Feb 13 at 14:50
















          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






          share|improve this answer
























          • That seems to have done it, many thanks.

            – Toby Eggitt
            Feb 13 at 14:50














          1












          1








          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






          share|improve this answer













          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 11 at 14:12









          glenn jackmanglenn jackman

          16.2k22645




          16.2k22645













          • That seems to have done it, many thanks.

            – Toby Eggitt
            Feb 13 at 14:50



















          • That seems to have done it, many thanks.

            – Toby Eggitt
            Feb 13 at 14:50

















          That seems to have done it, many thanks.

          – Toby Eggitt
          Feb 13 at 14:50





          That seems to have done it, many thanks.

          – Toby Eggitt
          Feb 13 at 14:50


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1404163%2fusing-expect-to-try-a-series-of-passwords%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

          Mangá

           ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕