INTRODUCTION TO BASH SCRIPTING - Hack the box academy

Who can give me a hint about this question in this module? question: Create a “For” loop that encodes the variable “var” 28 times in “base64”. The number of characters in the 28th hash is the value that must be assigned to the “salt” variable. This is my content: for i in {1…28} do var=$(echo $var | base64) if [[i -eq 28]] then salt=${#var} fi done *** WARNING : deprecated key derivation used. Using -iter or -pbkdf2 would be better. bad decrypt 140343231202624:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:…/crypto/evp/evp_enc.c:610: Am I misunderstanding this question?

Same problem, have you found a solution?

try to use salt=$(echo $var | wc -c)

1 Like

> @jad2121 said: > try to use salt=$(echo $var | wc -c) Thanks!! The case lets me know what difference between wc -c and ${#var}

echo “string” | wc -c counts the exact number of characters in the string returned by echo, that is “string” plus a line break appended by echo, so 7 in that case. ${#var} returns the exact number of characters contained in the var variable. You can obtain the same behavior by specifying the -n flag to echo, which gets rid of the trailing \n. I don’t know what exercise you’re doing and what is the expected answer but just in case your answer is not accepted, this might be a cause of issues : var=$(echo $var | base64) Add the -n flag to echo, and also the “-w 0” flag to base64, otherwise every 76 characters base64 adds a line break, so it might mess up the number of characters in the end. Also, what is that error message you’re getting ? I can’t see how you can get that from the script you pasted here.

2 Likes

This is what I got to work. Hope this helps!

#!/bin/bash

var="8dm7KsjU28B7v621Jls"
value="ERmFRMVZ0U2paTlJYTkxDZz09Cg"

for i in {1..40}
do
        var=$(echo $var | base64)
        temp=$(echo $var | wc -c)
        if [[ $temp -gt 113469 ]]
        then
                if [[ "$var" == *"$value"* ]]
                then
                        echo $var |tail -c 20
                fi
        fi
done

I am getting the same error . the number of characters in the 28th hash I am getting is 46026. I assigned that number to salt but got the same error

ok I actually figured out the issue you need to encode the var 28 times so instead of using for i in {0…28} you use 0…27 as the 0 will actually count as an encode. the total number of character you get in this case is 34071

hey bro did you solve this problem?
Create a “For” loop that encodes the variable “var” 28 times in “base64”. The number of characters in the 28th hash is the value that must be assigned to the “salt” variable.
it gives me this error
Extra arguments given.
enc: Use -help for summary.
can u help me please?

I do not want to spoil here. You can DM me if you still need help.

2 Likes

im horribly stuck on this also

i did setup the loop at 0…27 and the converted base64 has a wordcount of 34071
am i on the right path for that component?

when i assign this number to the salt variable and run the script im getting error
bad decrypt
140171867060112:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:618:

any clues would be great

Just a note to all… ensure you run the code on the pwnbox. i was running it on my redhat server and getting the errors.
same code on the pwnbox, worked !

thanks to PayloadBunny for the advice.

Hey! anyone getting stuck at this question just make sure to use the virtual machine (pwnbox) , just make your for-loop as you know and submit the flag (use all the code).

(not all packages are installed at kali so use the docker machine)

Perhaps a stupid question, I always performed all the tasks through my own VM,
how do I copy the clipboard to pwnbox?)

I figured it out)
Brought it to full screen and saw an icon in the lower right corner.
It was not displayed in normal mode.(
HTB Academy

That’s just through pwnbox, the error is the same as on my VM, unfortunately.
What am I doing wrong?
The advice was to run the script on pwnbox.
strangely

The problem has been solved!
On the contrary, I removed the -n flag after echo.
And he gave me the correct value of the flag.

hello evryone as mentioned above by others is better to use echo $var | wc -c using the length count gives and error.hopefully your code is also well written