Printf or any other method to put long string of spec characters - passing passwords

Hello,

I am looking for a method to use in my bash script which allows me to use long strings with all special characters.

I have found that printf method could be helpful for me but unfortunately, when I trying

root@machine:~# tevar=`printf "%s%c" "'``fF/0,g_V/Y)>^.(a0(,%<A.`8N:q*Rd|lCy0t9N'FDPs|S,$2(^$/*>5Ush*w87L#m@t~:[Ple+=Od633Z3m3xGV.zX+a-N%x1K=J7gOO=?1c$HZU78iVtJG1N[s@-eH#DwH]V5l}??XWI.YJ;4%:LmAEML9%4jm'Y6GXTc{DT7Iia$!+/[x.),b]5`iO3E,-+,44+9Fke45Z=m^ba.EP^)+GqZ.uQNF*sU9'Kxq6i19+ie*6rZjjCC.2`rSYVqlmHlHqeFBCapXXSxXROXUrljMWGsicEdCdPJuvbXnPXlENaBzpMBnRgtGsFtTYbHsyilugLrTSTMvGDGqSIhXhJISqnIuBwxfqr`'" ; echo $tevar
-bash: bd skadni przy nieoczekiwanym znaczniku `)'

I am getting error

-bash: bd skadni przy nieoczekiwanym znaczniku `)'

What is important - I need to pass different length strings, I don't know the length, and the positions of special characters.
This is a password from my password list and I need find working pass to archive.

What can I do to pass very long stream with any special character as a string and put it as variable in bash script?

Or - maybe I can make it outside the bash ? I am using 7 zip command line tool where I need to put the password as parameter like

7z t -pP@55w0rd!

where P@55w0rd! is my password.

What was my fault before (long time ago)- I have had used almost 5000 characters in passwords. I have lot of possible passes in my dictionary, and I am sure, that one of them will be correct.

Try:

var=$( 
cat << "EOF"
'``fF/0,g_V/Y)>^.(a0(,%<A.`8N:q*Rd|lCy0t9N'FDPs|S,$2(^$/*>5Ush*w87L#m@t~:[Ple+=Od633Z3m3xGV.zX+a-N%x1K=J7gOO=?1c$HZU78iVtJG1N[s@-eH#DwH]V5l}??XWI.YJ;4%:LmAEML9%4jm'Y6GXTc{DT7Iia$!+/[x.),b]5`iO3E,-+,44+9Fke45Z=m^ba.EP^)+GqZ.uQNF*sU9'Kxq6i19+ie*6rZjjCC.2`rSYVqlmHlHqeFBCapXXSxXROXUrljMWGsicEdCdPJuvbXnPXlENaBzpMBnRgtGsFtTYbHsyilugLrTSTMvGDGqSIhXhJISqnIuBwxfqr`'
EOF
)
printf "%s\n" "$var"

--
To read a text that you do not want prompted and put it in variable passw , you can use:

read -s passw
1 Like

The "here document" is the correct method of storing a password in the script.
--
If you have a pwlist with one password per line then you can do

while IFS= read -r pw
do
  printf "%s\n" "$pw"
  echo 7z t -p"$pw"
done < pwlist

Remove the echo to run the 7z command.