Home > Mobile >  Echoing a Space Character Into a File
Echoing a Space Character Into a File

Time:02-05

I want to make a batch obfuscator with no outside tools, but I have a problem with echoing the spaces into the 'obfuscated' code('obfuscated' as in separating the code letter by letter between hundreds of random characters). I have found batch obfuscators that are used with CertUtil, but they can be de-obfuscated with another file, so I really want to get this working, and I haven't really found any unique ones.

When I run my file with the input file (contains @echo off and echo test), I get the obfuscated code:

$zz$j?$z?$#z#?$z?$z###$j?j#zz?$?##j$?$?$#z$$#zjj#zzz?j#jzj#zjjzj?$#$jj?j##z##?#$$$#zjz?$zj#j$zz#jzj#@#$z#j#j#??##zj#z#j$?$jzjz?$j?$?##zzz#???z$$jzj#??###jz$?$j$z$?$?$?j$j?$jzzj#j#z$zz$jzz#z#$jz#?z?$$$?e$?$j?$##?#zjjjjz#j$$zjjz##$?jzjj?$##?##j$#z#zj?zzjzj$$j#$j$????$z#j#$?j?#j$$$$#jzj$$j#z#z###?j#zjz#jc$#jjz$j#$zj?#z$$?j$z$#?zz$$zz#z?##j#zz#j#z##?$#z$j?$j?z$#?#$$z??j?zj#j$##?#$zz#$$$z?z$z?jz#?j?j#z$?jhj??z?zzj##$?#j$$j#j?#$?$j$$zzzzjjz?z?##$?$$j$zz#?j#?##z#jz$z#jz$z?zzj$###z#jzjzz$##?$j??$??#?zz##?$$ojj#$j$j##?#?jzj$z#?zz##$jjjj#j#?$##j?$?j$#jzzj#?$?jz#$#z#$j???z#$?z?jzzzj$?#jzj#j$#j#??j$?jj?jzz?$#$##z$jjj#?jjz#??jz$?###$j$##$$#$$#?$?j$?z$j?j##?z$#jj?#jzjjjzz$jzjj$##z$?#$##z#$#z##$z?zz##$z?jj$#??jo#$##jjjj?$z$?#z?$##zjz$#j#zz#z?$#$##$j#j?#$#$zz$zj#j?$jjz#jjzjjz#$$j#jjz$?z?j?j#?j$#?zj?jjzzz#$?$##jfzj#?##?jjzjjz$??#zjj??j#????#z#$$$?$?##z$#$zj?jj?#?z$jzj?$j?#??zzj#$jj$?z#j???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$j$???z?$jz$z?z???z?j#j??$z$$#$#$#j??$$##zjj#j#$$z$$?jj?jzjzjz$$z#zz?$?j$zjzjzz$j#j$#??j???jjj##z#$$$#j$#?j?#z$#$?#zj#?$$??jj?#z#?$##jzzz?$$$zjjjzzjz#$#?#$#jz$z?$z##jjjzj?z?j???j??##$zj$zj?#zjzj##j#z$$???#$jzj#z?z??jj##??z####?#?#z??j$????$$zz#jzj?z?j?z?#z$zz??j$?zz#jj##zz##??zj?#z??$?j###?zz#zjjzj$$z#??#?$?#$jj#j?$$$j?zzjz?$?#z#z$#jj#jz$???zj$jjjz$jz#j#$zz?jj#jj?#jj###?z#$j?zzj#jz?$#zj?#?j#?z??$z??jzz?#zj??j?$z##z#j$zjz#zz?$zj$?jjz?jjj$?j$$#z#?#j?zj$$j#jj#z?z#j#?jzzz$jjj$jzjz$j#j#j#?zzzz??z#z$jz#$#z$$?jz$j#?jz??jj#jj$z#z##j$j$##$???z??j?zzjz$??j#zzz#$jj#jzj#z$z$$?$z$jzzj#$#z$#z?z$###???$$?zz$#??j$?$j#j$#?zj$jzzj??j?z?zzz##?j$?z?j$jjz$jj?z#?j##$$?zjzjj#jjj??z$?#zzj$j#??z#zz$$j?jzj#j

However, when I manually remove all of the characters, I am left with:

@echooff
echotest

Is there a way to echo spaces into a file by itself so this problem will be fixed?

My code:

@echo off
set /a N=0
:file
set /p "file=Enter filename: "
if not exist %file% echo Please try again. The file you specified does not exist.
if not exist %file% pause>nul
if not exist %file% cls
if not exist %file% goto file
cls
echo Please wait.
set /a overallfirst=1
set /a double=0
for /F "usebackq tokens=*" %%f in ("%file%") do goto start
:start
set /a "tamp=%random%"
set /a loop2=0
set /a rand=%random% %%5  1
if %rand%==1 echo #> %tamp%
if %rand%==2 echo $> %tamp%
if %rand%==3 echo ?> %tamp%
if %rand%==4 echo z> %tamp%
if %rand%==5 echo j> %tamp%
:chars
if %loop2%==100 goto next
set /a rand=%random% %%5  1
if %rand%==1 <nul set /p=#>> %tamp%
if %rand%==2 <nul set /p=$>> %tamp%
if %rand%==3 <nul set /p=?>> %tamp%
if %rand%==4 <nul set /p=z>> %tamp%
if %rand%==5 <nul set /p=j>> %tamp%
set /a loop2 =1
goto chars
:next
for /f "usebackq tokens=*" %%f in ("%tamp%") do set chars=%%f
set "start=^<nul set /p=%chars%^>^> Obfuscated.bat"
del %tamp%
set /a loop=-1
set /a first=1
for %%i in (%file%) do @set count=%%~zi
echo @echo off> Chars.bat
if %double%==0 echo empty^> Obfuscated.bat>> Chars.bat
echo for /f "tokens=*" %%%%a in (%file%) do set id=%%%%a ^& call :processline %%%%a >> Chars.bat
echo cls>>Chars.bat
echo echo Obfuscated code:>>Chars.bat
echo echo -------------------------->>Chars.bat
echo type Obfuscated.bat>>Chars.bat
echo pause^>nul>>Chars.bat
echo exit >> Chars.bat
echo goto :eof >> Chars.bat
echo :processline >> Chars.bat
:loop
set /a loop=%loop% 1
if %loop%==%count% goto end
if %first%==1 set first=0 & goto other
set "command=^<nul set /p=%%id:~%loop%,1%%"
echo %command%^>^> Obfuscated.bat>> Chars.bat
goto next1
:other
set "command=%start%"
echo %command%>> Chars.bat
set /a loop=%loop%-1
goto loop
:next1
set /a "tamp=%random%"
set /a loop2=0
set /a rand=%random% %%5  1
if %rand%==1 echo #> %tamp%
if %rand%==2 echo $> %tamp%
if %rand%==3 echo ?> %tamp%
if %rand%==4 echo z> %tamp%
if %rand%==5 echo j> %tamp%
:chars
if %loop2%==100 goto next2
set /a rand=%random% %%5  1
if %rand%==1 <nul set /p=#>> %tamp%
if %rand%==2 <nul set /p=$>> %tamp%
if %rand%==3 <nul set /p=?>> %tamp%
if %rand%==4 <nul set /p=z>> %tamp%
if %rand%==5 <nul set /p=j>> %tamp%
set /a loop2 =1
goto chars
:next2
for /f "usebackq tokens=*" %%f in ("%tamp%") do set chars=%%f
set "command=^<nul set /p=%chars%"
echo %command%^>^> Obfuscated.bat>> Chars.bat
del %tamp%
goto loop
:end
echo echo. ^>^> Obfuscated.bat>> Chars.bat
echo goto :eof >> Chars.bat
echo :eof >> Chars.bat
start Chars.bat
if %overallfirst%==1 set /a overallfirst=0 & set /a double=1

I have looked for a solution, but I was unable to find one. (I am fairly new to Batch coding so this script is not very efficient)

CodePudding user response:

Try using <nul set /p and echo/. This post may help: Preserve spaces with <Nul set /p

  • Related