Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.67 KB | None | 0 0
  1. #!/bin/bash
  2. storageName="otwPasswords";
  3. storageLocation="./";
  4. #Needs to be changed so which sshpass is run on startup
  5. sshpass="/usr/bin/sshpass"; #If this doesn't work, run "which sshpass" in your terminal and paste the output here
  6.  
  7. storage=$storageLocation$storageName;
  8. file=$storage/$1;
  9. started=false;
  10. passwords=false;
  11. inProgress=true;
  12. #Check if password directory exists, create if it doesn't.
  13. for file in ./*; do
  14.     if [ $file == $storage ]; then
  15.         passwords=true;
  16.         break;
  17.     fi
  18. done
  19. if [ $passwords = false ]; then
  20.     mkdir otwPasswords;
  21. fi
  22. #Check for the current otw challenge, create if doesn't exist
  23. for file in $storage/*; do
  24.     if [ "$storage/"$1 == $file ]; then
  25.         started=true;
  26.         break;
  27.     fi
  28. done
  29. #get last password, or create list
  30. if [ $started = false ]; then  
  31.     touch $storage/$1;
  32.     echo $1"0:"$1"0" >> $storage/$1;
  33. fi
  34. while [ $inProgress = "true" ]; do
  35.     lastLine=$(tail -n 1 $storage/$1); #Format = $username:$pass
  36.     username=$(echo $lastLine | cut -f1 -d":");
  37.     pass=$(echo $lastLine | cut -f2 -d":");
  38.     $sshpass -p $pass ssh $username@$1.labs.overthewire.org;
  39.     if [ $? -eq 0  ]; then
  40.         echo "paste the password or type STOP;"
  41.         read answer;
  42.         answer=${answer,,};
  43.         if [ $answer = "stop" ]; then
  44.             inProgress=false;
  45.         fi
  46.         username=$1$(wc -l $storage | cut -f1 -d" ");
  47.         echo $username:$pass >> $storage/$1;
  48.     else
  49. #delete incorrect password
  50.         head -n -1 $storage > temp.txt;
  51.         mv temp.txt $storage
  52.         rm temp.txt
  53.         echo "Incorrect password! Would you like to go back to your last save? Y|N";
  54.         read answer;
  55.         answer={$answer,,};
  56.         if [ $answer = "y" || $answer = "yes" ]; then
  57.             echo $lastLine;
  58.         else
  59.             working=false;
  60.         fi
  61.     fi         
  62.     echo $?
  63. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement