Aacini wrote: ↑27 Dec 2021 15:15
There is a simple method to "hide" values, like a password, in a Batch file that have proved to be effective against most intermediate Batch file users. I posted here such a method as a challenge: try to broke the code and get the password, but reviewing the Program.BAT file
only! You can NOT review the Installer.BAT file for now...
To start the challenge, run the Install.BAT file once so the Program.BAT file is created. After that, run the Program.BAT file.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
rem Install.BAT: Create Program.BAT file that include a "hidden" password
rem https://www.dostips.com/forum/viewtopic.php?f=3&t=6185
rem Antonio Perez Ayala aka Aacini (https://apaacini.com)
rem Do NOT review the code for now!!
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
for %%i in (A,B,C) do echo Protection scheme part %%i > %%i
> ".\C:passîð!BS!!BS!Word.txtÿ" echo Yes, You Did It
echo This is not the password > passWord.txt
(
echo @echo off
echo setlocal EnableDelayedExpansion
echo/
echo set /P "pass1=Enter password: "
echo set /P "pass2=" ^< ".\C:passîð!BS!!BS!Word.txtÿ"
echo if "^!pass1^!" equ "^!pass2^!" goto OK
echo echo Bad password
echo goto :EOF
echo/
echo :OK
echo echo You did it!
) > Program.bat
echo Program.bat file created
When you broke the password, please do NOT post what the protection scheme is! Just post that you did it, so other users keep interested in the challenge...
Although this scheme is used here to hide only a password, it can also be used to hide sections of Batch code. Further details about this point in a posterior post...
Antonio
Dear Aacini
First of all, I apologize for the delay in responding.
When I accepted the challenge, I commented that I am new to Batch because I do not have knowledge. So when I accepted the challenge I felt overwhelmed and with a feeling of not being able to solve it.
After a few days of pausing for the dates, I decided to look at the file and run it. I have to be honest, when I saw the files for the first time, I had no idea how the goal of hiding the key was achieved.
First I tried to find the key, and I have to admit that I had to cheat, inserting an additional line to know the value of the variable. But, it was of no use to me, since I did not understand where the key was coming from, or at least not with certainty.
After thinking and trying, thinking and trying, and a lot of thinking. The light bulb went on once again, so I did a Google search, and came up with the possible answer.
Now I just had to replicate the trick, and then visualize the key to the challenge.
Now that I have the key, I know how to see it, and I understand the trick of hiding it (I learned how to do it). It only remains for me to figure out how to apply this trick so that my code runs hidden.
In order to avoid losing interest in the challenge, I wonder if you could send me a link on how to run my code in a hidden way, I would greatly appreciate it.
Thankful as always to all of you for your teachings.