0

My bash dictionary attack function will select the first word from the dictionary and see if it compares with my hash but then stop, and if it doesn't, it will search the whole dictionary but not actually return the password. When it stops the password is always "1080", no matter what the hash is

I don't understand what's happening, but I've researched quite a lot

dict_attack(){
TARGET_HASH=$1
while read WORD; do
    WORD_HASH=$(echo $WORD | sha256sum | awk '{print $1}')
    if [ "$WORD_HASH"=="$TARGET_HASH" ]; then
            echo "Guessed it!"
            echo "Password is : $WORD"
            exit
    fi
done < /usr/share/dict/linux.words

Here is the call in the rest of the script.

dict_attack $1
Ryan Bargholz
  • 163
  • 1
  • 1
  • 7

2 Answers2

0

if [ "$WORD_HASH"=="$TARGET_HASH" ] does not do what you expect. It always evaluates to true, since the string "$WORD_HASH"=="$TARGET_HASH" is always non-empty. Add some whitespace around the == operator and write it:

if [ "$WORD_HASH" == "$TARGET_HASH" ]
William Pursell
  • 204,365
  • 48
  • 270
  • 300
0

You need spaces around == (or =) in [ (test) command (and also in [[ keyword):

if [ "$WORD_HASH" == "$TARGET_HASH" ]

Otherwise you are just doing the -n test i.e. check if the string is non-zero which will always be true as you have ==:

if [ -n "$WORD_HASH"=="$TARGET_HASH" ]
heemayl
  • 39,294
  • 7
  • 70
  • 76