#Bash Scripting

1 messages · Page 1 of 1 (latest)

desert gust
#

Anyone good with bash scripting?

I am attempting to loop through a word list and test it using blowfish ofb encryption against the encrypted file called catalina and Ive gotten it to loop through the entire wordlist but it doesnt return the password which I know is in the wordlist and now it just returns garbage

graceful axle
desert gust
#

Yeah my bad lmao

#
#!/bin/bash

ENFILE="catalina.txt.secret"
OUTPUT="output_password"
WORDLIST="word_list.txt"

while IFS= read -r PASSWORD; do
    echo "Trying password: $PASSWORD"
    openssl enc -bf-ofb -d -in "$ENFILE" -out "$OUTPUT" -pass pass:"$PASSWORD" -nosalt 2>/dev/null
    
    STATUS=$?

    echo "exit status: $STATUS"

    if [ $STATUS -eq 0 ]; then
        if grep -q "[[:print:]]" "$OUTPUT"; then
            echo "Success Password is: $PASSWORD"
            cat "$OUTPUT" | strings
            exit 0
        fi
    fi

done < "$WORDLIST"

echo "No password found"
exit 1```
graceful axle
#

What's in the catalina.txt.secret file? Is this an encrypted file that you don't know the password to?

desert gust
#

Yeah

#

Exactly

#

The password is in the wordlist tho

slim knoll
#
openssl enc -bf-ofb -d -in "$ENFILE" -out "$OUTPUT" -pass pass:"$PASSWORD" -nosalt 2>/dev/null
``` Its getting garbled here because it looks like you're trying to pass one file through another.

```bash
while IFS= read -r PASSWORD; do
    echo "Trying password: $PASSWORD"

this isn't typically used like this, and IFS is generally used as a variable. $IFS. I cannot find any reference to any command, and you don't have it saved as a variable prior to saving the read command as its value, while not referencing it later in your script. it's also not a saved variable in bash.

secondly, while, although it doesn't have to be, typically has other commands piped into it ```bash
cat output_password | cut -d: -f2 | while read -r PASSWORD ; do
echo "$PASSWORD"
done


I do not mean to sound rude, but please tell me you are not trying to use AI to help you write this script? New people often make that mistake and often break their Linux installs as a result. The AI, or LLMs generally are just out putting what others have put into them, and have no deeper understanding of these commands, that a human generally would. *I advise against it if you are.*

and finally: this looks like you're trying to set up a brute force attack on a password protected file, that may or may not be encrypted. The encryption would garble the information anyways, so you wouldn't be able to read the password file if you tried. while at the same time, I myself, and many others, are not entirely comfortable helping with this because it seems like a brute force attack, aka black hat work.

Best of luck in the future.
plain flume
#

this isn't typically used like this, and IFS is generally used as a variable. $IFS. I cannot find any reference to any command, and you don't have it saved as a variable prior to saving the read command as its value, while not referencing it later in your script. it's also not a saved variable in bash

IFS is the string separator value in bash. This is probably intended to allow spaces in the entered password, while still treating it as a single string, rather than an array. They're modigying the standard IFS value as interpreted by the read command. I am not sure if IFS= without any string after it is valid, but it was pretty easy to find an example of this while loop structure using IFS.

slim knoll
plain flume
#

Nah, because of the space, this is just a standard runtime-environment-variable-override

#

I'm just unclear on the value it's actually saving

plain flume
#

I've abused IFS like this several times in the past: IFS=$"\n" for f in $(ls) which allows spaces in filenames. Not a perfect solution, but works sometimes.

slim knoll
slim knoll
plain flume
slim knoll
plain flume
#

value being saved would be the read command, read -r PASSWORD
This is not happening, because the space here: "IFS= " breaks up the evaluation of the command. It would need to be IFS=\ read, which would still then break at that point because of the next space. Because of that space, I figure this syntax is either: A. Just wrong, and won't work, or B. Is evaluating to a null value. Either way, the read command is not being consumed by the IFS= statement, read is the one comsuming the value of IFS, and using it to interpret the ingestion of the values being passed to it farther down the script here:

done < "$WORDLIST"

which it is storing as the PASSWORD temporary variable that is used inside the while loop.