0

I wanted to write a bash script that reads a word in a file and then tries to loop through the alphabet until it finds the word. This is the code I have worked out so far but I am not very sure what to do from here and any help would be appreciated.

maxlen=5

while -r file; do

for i in {a...z}; do

done 

done < ~/textfilelocation

So basically as part of homework I am supposed to attempt a tivial brute force attack against a password file with every possible combination of characters and we are to assume it is all lower case English.

  • In short, are you trying to check whether the word read from the file has a particular pattern? – sjsam Aug 29 '16 at 13:00
  • Not sure what you are asking here. Why would it loop through the alphabet to find the word? The alphabet contains letters not words. – spectre-d Aug 29 '16 at 13:00
  • http://stackoverflow.com/questions/7300070/bash-script-looping-through-alphabet?rq=1 – spectre-d Aug 29 '16 at 13:01
  • So basically as part of homework I am supposed to attempt a tivial brute force attack against a password file with every possible combination of characters and we are to assume it is all lower case English. – user3925467 Aug 29 '16 at 13:04

1 Answers1

2

I left something for you to finish here-

while read -r file; do
  for i in {a..z}; do
    for j in {a..z}; do
      for k in {a..z}; do
        for l in {a..z}; do
          for m in {a..z}; do
            word="$i""$j""$k""$l""$m"

            *set up an if condition to check if $word matches the test word*
            *break out of the loop if yes*

          done
        done
      done
    done 
  done < ~/textfilelocation
Chem-man17
  • 1,700
  • 1
  • 12
  • 27
  • `word=$(echo "$i""$j""$k""$l""$m")`? seriously? that's horrible! please use `word=$i$j$k$l$m` instead. Also you probably missed `read` somewhere in the while statement. – gniourf_gniourf Dec 05 '17 at 20:46