tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
Moderator: DosItHelp
-
- Posts: 36
- Joined: 02 May 2016 18:59
tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
Hi guys, here's a quick batch file from my project I'm working on ( BatFramework github.com/SirJosh3917/BatFramework - Don't expect it to be good yet )
tobat.bat is a batch file. It's part of the BatFramework project I'm making, but it's as easy as leaving it on your desktop.
Just drag and drop whatever file you want to turn into a batch file on top of it.
It uses certutil to convert the file into base64, then the batch file takes the certificate and modifies it to make it into perfection.
Of course you can do this in command line, but dragging and dropping is slightly easier.
tobat.bat is included as tobat.zip as an attatchment.
tobat.bat is a batch file. It's part of the BatFramework project I'm making, but it's as easy as leaving it on your desktop.
Just drag and drop whatever file you want to turn into a batch file on top of it.
It uses certutil to convert the file into base64, then the batch file takes the certificate and modifies it to make it into perfection.
Of course you can do this in command line, but dragging and dropping is slightly easier.
tobat.bat is included as tobat.zip as an attatchment.
- Attachments
-
- tobat.zip
- tobat.bat is included inside.
- (916 Bytes) Downloaded 622 times
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
You might want to explain what it actually does (converts a file to base64 and stores it in a separate batch file for later deconversion) instead of whatever "takes the certificate and modifies it to make it into perfection" is supposed to mean.
-
- Posts: 36
- Joined: 02 May 2016 18:59
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
ShadowThief wrote:You might want to explain what it actually does (converts a file to base64 and stores it in a separate batch file for later deconversion) instead of whatever "takes the certificate and modifies it to make it into perfection" is supposed to mean.
Isn't that what I said...?
SirJosh3917 wrote:It uses certutil to convert the file into base64, then the batch file takes the certificate and modifies it to make it into perfection.
Tool it uses: CHECK - Certutil
Proccess : CHECK - Converts it into base64, modifies certificate created by certutil into a batch file.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
"Modifies it to make it into perfection" is extremely vague and doesn't make any sense. You mention converting the file to base64, but you don't "turn the file into a batch file," you simply store the encoded file in a batch wrapper.
Also, certutil has a maximum input file size of 72727 KB, or just over 71 MB. You may want to mention this somewhere.
Also, certutil has a maximum input file size of 72727 KB, or just over 71 MB. You may want to mention this somewhere.
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
I use a similar code.
encode_b64.bat
I leave -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- because it doesn't matter ...
Steffen
encode_b64.bat
Code: Select all
@echo off
for /f %%i in ("certutil.exe") do if not exist "%%~$path:i" (
echo CertUtil.exe not found.
pause
exit /b
)
certutil.exe -f -encode "%~1" "temp.b64~" || (pause&exit /b)
>"decode_%~n1_b64.bat" (
echo(@echo off
echo(for /f %%%%i in ("certutil.exe"^) do if not exist "%%%%~$path:i" (
echo( echo CertUtil.exe not found.
echo( pause
echo( exit /b
echo(^)
echo(^>"temp.b64~" (
for /f "usebackq delims=" %%i in ("temp.b64~") do echo(echo(%%i
echo(^)
echo(certutil.exe -f -decode "temp.b64~" "%~nx1"
echo(del "temp.b64~"
echo(pause
)
del "temp.b64~"
I leave -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- because it doesn't matter ...
Steffen
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
What is this used for? I am not understanding the purpose.
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
Base64 encoded data consists of 64 different printable ASCII characters only. That way you are able to represent binary data as text.
Pro: You can use it wherever only printable ASCII characters are valid (e.g. inside of code tags in a forum post).
Con: 2 bytes of the original data become 3 bytes base64 code.
Steffen
Pro: You can use it wherever only printable ASCII characters are valid (e.g. inside of code tags in a forum post).
Con: 2 bytes of the original data become 3 bytes base64 code.
Steffen
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
The purpose of this program is convert a binary file (like an .exe, or a .jpg image, or whatever you want) into ASCII characters that can be posted in a text-only forum (like this one), so the text can be copied by any user and the original binary file be recovered.
Several methods had been used for this purpose, including a couple programs written by myself. The last version of my method uses 223 ASCII printable characters to encode the binary data, so the resulting text file may be even smaller than the original binary file in certain cases. For example, the cmd.exe file of my Windows 8.1 Spanish version that have an original size of 404,992 bytes is encoded into a "Set223" file of just 376,168 bytes (the 93% of the original size).
Antonio
Several methods had been used for this purpose, including a couple programs written by myself. The last version of my method uses 223 ASCII printable characters to encode the binary data, so the resulting text file may be even smaller than the original binary file in certain cases. For example, the cmd.exe file of my Windows 8.1 Spanish version that have an original size of 404,992 bytes is encoded into a "Set223" file of just 376,168 bytes (the 93% of the original size).
Antonio
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
Now I understand. I actually just started doing this last week. I wanted to embed an executable into my batch file for portability purposes.
I took the my executable which was 61,952 bytes and encoded it with certutil and this made it into a file of 85,242 bytes.
Thought that was a little to big so I used makecab to compress it first. That made it 24,154 bytes and then I ran it through certutil which made it 33,766 bytes.
I took the my executable which was 61,952 bytes and encoded it with certutil and this made it into a file of 85,242 bytes.
Thought that was a little to big so I used makecab to compress it first. That made it 24,154 bytes and then I ran it through certutil which made it 33,766 bytes.
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
@Squashman: I invite you to use my BinToBat223.bat program to encode your .exe file and post the result. After the MakeFiles.bat is created, open it with Notepad, extract the encoded text that appear between "<resource id=..." and "</resource>" lines at end of the file, and save it in a separate file. The size of this file is the size of the "Set223" encoded text.
You may also do this on both the .exe and the .cab files.
Antonio
You may also do this on both the .exe and the .cab files.
Antonio
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
Aacini wrote:@Squashman: I invite you to use my BinToBat223.bat program to encode your .exe file and post the result. After the MakeFiles.bat is created, open it with Notepad, extract the encoded text that appear between "<resource id=..." and "</resource>" lines at end of the file, and save it in a separate file. The size of this file is the size of the "Set223" encoded text.
You may also do this on both the .exe and the .cab files.
Antonio
Seem to be having problems.
Code: Select all
I:\>bin2bat223.bat unix2dos_Original.exe
Note that the encoding of each file will start *after* the corresponding FC
command had ended; this may take awhile depending on file size...
Encoding unix2dos_Original.exeFC: cannot open ZERO.TMP - No such file or folder
done
File MakeFiles.bat created
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
Using a for loop takes forever on large files. Thankfully, certutil only processes the parts of files that are between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- so you can just append the base64 data to the end of your reversal script with type instead of needing to go line by line.
The largest file that works with certutil (74472684 bytes) takes 6.5 seconds to process. For comparison, the code in the first post takes the same file 5 hours to complete and creates a reversal script that is 13 MB larger than mine.
Code: Select all
::------------------------------------------------------------------------------
:: Converts a file to base64 using a heredoc instead of a for loop for speed.
:: The script allows for a file with a maximum size of 72726 KB.
::
:: Arguments: %1 - The file to convert
::------------------------------------------------------------------------------
@echo off
setlocal enabledelayedexpansion
cls
:: Determine if a parameter was passed in and quit if one wasn't
if "%~nx1"=="" (
echo No file specified. Exiting.
exit /b
)
if %~z1 GTR 74472684 (
echo Maximum file size of 74472684 bytes exceeded. Exiting.
exit /b
)
:: Create a new output file based on the file name of the input file,
:: converting spaces to underscores if necessary
set base64_output_file=%~n1.b64
set base64_output_file=%base64_output_file: =_%
if exist %base64_output_file% del /q %base64_output_file%
:: Convert the file to base64
set /p "=Converting file..." <nul
certutil -encode "%~nx1" %base64_output_file% >nul
echo DONE
:: Generate reversal script
set /p "=Generating reversal script..." <nul
set batch_output_file=%base64_output_file%.bat
>%base64_output_file%.bat (
echo(@echo off
echo(certutil -decode "%%~0" Fonts.rar
echo(exit /b
echo/
)
type %base64_output_file% >>%base64_output_file%.bat
del %base64_output_file%
echo DONE
echo Process complete.
The largest file that works with certutil (74472684 bytes) takes 6.5 seconds to process. For comparison, the code in the first post takes the same file 5 hours to complete and creates a reversal script that is 13 MB larger than mine.
Last edited by ShadowThief on 03 Oct 2016 16:34, edited 2 times in total.
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
Squashman wrote:Seem to be having problems.Code: Select all
I:\>bin2bat223.bat unix2dos_Original.exe
Note that the encoding of each file will start *after* the corresponding FC
command had ended; this may take awhile depending on file size...
Encoding unix2dos_Original.exeFC: cannot open ZERO.TMP - No such file or folder
done
File MakeFiles.bat created
I don't understand what happen. The ZERO.TMP file is created by this line:
Code: Select all
fsutil file createnew zero.tmp "%~Z1" > NUL
I know that FSUTIL does not require admin privileges in order to create a file this way (I just tested it again), so I don't understand what could be the error here...
Could you test if this command correctly create a 1000 bytes size file?
Code: Select all
fsutil file createnew zero.tmp "1000"
If so, perhaps you may remove the "> NUL" part from the line above in order to see any message from fsutil...
Antonio
Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch
Aacini wrote:I know that FSUTIL does not require admin privileges in order to create a file this way (I just tested it again), so I don't understand what could be the error here...
Could you test if this command correctly create a 1000 bytes size file?Code: Select all
fsutil file createnew zero.tmp "1000"
If so, perhaps you may remove the "> NUL" part from the line above in order to see any message from fsutil...
Antonio
Code: Select all
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
H:\>fsutil /?
The FSUTIL utility requires that you have administrative privileges.
H:\>fsutil file createnew zero.tmp "1000"
The FSUTIL utility requires that you have administrative privileges.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States