Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

encryption - Is it possible to encrypt/Hash a password in a BAT file?

:start
echo Try to hack this password!
set/p "pass=>"
if not %pass% == Ebaturvaline177 goto vale
echo Correct!!
pause
 start "" https://stackoverflow.com
exit
:vale
echo Wrong.
goto :start

How can I encrypt/hash the password so people just cant view the code and see the code?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was interested after reading your question so i decided to make a batch-file that is kind of accomplishing what you are trying to do. instead of storing raw password i am storing MD5 Hash in a file and then i am comparing user input that is also hashed with the hash stored in a file named pass.txt.

Crackme.bat:

@echo off & setlocal
:loop
set userinput=
set /p userinput=Try Crack me:
set "plaintext=%userinput%"
set "file=%temp%\%~n0.tmp"
set md5=

if not defined plaintext set /P "plaintext="

if exist "%plaintext%" (
    set "file=%plaintext%"
) else for %%I in ("%file%") do if %%~zI equ 0 (
    <NUL >"%file%" set /P "=%plaintext%"
)

for /f "skip=1 delims=" %%I in ('certutil -hashfile "%file%" MD5') do (
    if not defined md5 set "md5=%%I"
)

2>NUL del "%temp%\%~n0.tmp"

echo %md5: =% >>file.txt
set /p passhash=<file.txt
ping localhost -n 2 >nul
del file.txt
set /p passtocrackhash=<pass.txt
if %passhash% equ %passtocrackhash% ( goto cracked) else ( goto  error)
:error
echo Wrong pass
goto loop
:cracked
echo Hurrah!you cracked the password it was %userinput%


This batch file will take user input and compare it with the hash stored in pass.txt,if the password is correct then a success message is shown otherwise an error is thrown and is looped back for another try

pass.txt:

8b1a9953c4611296a827abf8c47804d7

Just make a file named as pass.txt and type the md5 hash of your password and save it.you can create an md5 hash from following batch-file or online . Just save the code as .bat open cmd in same directory and give the string that you want to hash as an argument to batch file

Well anyone is welcomed to edit the code for improvement...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...