Best way to obfuscate a Batch File?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: Best way to obfuscate a Batch File?

#31 Post by PaperTronics » 10 Aug 2017 05:52

@penpen I've followed ShadowThief's method and salted and hashed the password. So I guess the most popular topic of mine finishes here! :wink:



PaperTronics

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Best way to obfuscate a Batch File?

#32 Post by dbenham » 10 Aug 2017 08:37

PaperTronics wrote:@dbenham - I like your obfuscating batch file so much, that I may even use it on my new game! Do you mind if I post about it on my website?

Not at all. Just be sure to preserve my documentation and credits if you repost the ObfuscateBatch.bat code.

Also, it would be nice if any released game gave credit for the obfuscation technique (including my name, as well as the DosTips site) in a human readable comment within the code.


Dave Benham

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: Best way to obfuscate a Batch File?

#33 Post by PaperTronics » 11 Aug 2017 03:20

@dbenham - Of Course! I will give full credits to you in the header of the game and even in the readme documentation.


PaperTronics

Kvc
Posts: 26
Joined: 13 Jun 2017 06:44
Location: India
Contact:

Re: Best way to obfuscate a Batch File?

#34 Post by Kvc » 31 Aug 2017 10:01

:shock: :shock: :shock:

Sorry to bother You all. But, As PaperTronic has posted on TheBATeam Blog - about Dave's great plugin - A User has faced a problem of JS Error in the console. (See Here)http://www.thebateam.org/2017/08/properly-encode-obfuscate-your-code.html?showComment=1504078324080#c722512734334501697

Can You Please Sort out the issue. As, I don't know about the working method and kind of out of time understanding it first. :) Thanks for your time.

Kvc
Posts: 26
Joined: 13 Jun 2017 06:44
Location: India
Contact:

Re: Best way to obfuscate a Batch File?

#35 Post by Kvc » 31 Aug 2017 10:15

:shock: :shock: :shock:
Hey, Dave And PaperTronics - pardon me for bothering you here. But, I really don't know to use this system of the forum (trying hard to learn though). I think I've replied before - but, couldn't see my comment in the topic. So, trying again.

As promised - PaperTronics and I've posted the great plugin on the OurBatchblog (TheBATeam). And, a user recently commented about the JS Error they are facing while using the plugin. I don't know about the working of the plugin - so, I will be better if either of you can reply with a proper solution. http://www.thebateam.org/2017/08/properly-encode-obfuscate-your-code.html?showComment=1504195437642#c5951254323612374791

Thanks for your time. :)

"The strength of the team is each individual member. The strength of each member is the team." --Phil Jackson

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Best way to obfuscate a Batch File?

#36 Post by aGerman » 31 Aug 2017 10:20

Ask the user what exactly the error message is. JScript always outputs a nice message including line number and position in the line where the error occurred.

Steffen

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Best way to obfuscate a Batch File?

#37 Post by penpen » 31 Aug 2017 17:16

I've downloaded the example, executed "test.bat" to create "Hello_obfuscated.bat", which gives this output:

Code: Select all

 Hello World!
Parameterformat falsch - 708.


On a fast check i guess, that the error is in daves "ObfuscateBatch.bat" is located in line 123:

Code: Select all

echo @echo off^&(if defined @lo@ goto !hi:~0,1!)^&setlocal disableDelayedExpansion^&for /f "delims=: tokens=2" %%%%A in ('chcp') do set "@chcp@=chcp %%%%A>nul"^&chcp 708^>nul^&set ^^^^"@args@=%%*"

I think the for/f-loop is missing the dot character ('.') as a delimiter, so correct line should be:

Code: Select all

echo @echo off^&(if defined @lo@ goto !hi:~0,1!)^&setlocal disableDelayedExpansion^&for /f "delims=:. tokens=2" %%%%A in ('chcp') do set "@chcp@=chcp %%%%A>nul"^&chcp 708^>nul^&set ^^^^"@args@=%%*"

Although it might be, that the resulting "chcp 708>nul" also may lead to an error, so i would prefer ">nul chcp 708".

penpen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Best way to obfuscate a Batch File?

#38 Post by dbenham » 31 Aug 2017 18:53

One important limitation of JREPL that I have not documented - based on a private message I received, it appears JREPL does not support Asian languages that use multi-byte characters within cmd.exe. I wonder if Staszek Michal is running into that limitation :?: The opening lines of his posted hello_obfuscated.bat are certainly corrupted in a major way.

penpen wrote:I've downloaded the example, executed "test.bat" to create "Hello_obfuscated.bat", which gives this output:

Code: Select all

 Hello World!
Parameterformat falsch - 708.


On a fast check i guess, that the error is in daves "ObfuscateBatch.bat" is located in line 123:

Code: Select all

echo @echo off^&(if defined @lo@ goto !hi:~0,1!)^&setlocal disableDelayedExpansion^&for /f "delims=: tokens=2" %%%%A in ('chcp') do set "@chcp@=chcp %%%%A>nul"^&chcp 708^>nul^&set ^^^^"@args@=%%*"

I think the for/f-loop is missing the dot character ('.') as a delimiter, so correct line should be:

Code: Select all

echo @echo off^&(if defined @lo@ goto !hi:~0,1!)^&setlocal disableDelayedExpansion^&for /f "delims=:. tokens=2" %%%%A in ('chcp') do set "@chcp@=chcp %%%%A>nul"^&chcp 708^>nul^&set ^^^^"@args@=%%*"
:shock: Wow :!:
So the format of CHCP output must not be consistent across all languages. I was aware that the words would change, but I thought the punctuation would be consistent. On my US machine I get

Code: Select all

C:\test>chcp
Active code page: 437
But your output must have a period at the end. Adding the dot to delims should indeed fix that problem, assuming there are no other variations with other languages.

penpen wrote:Although it might be, that the resulting "chcp 708>nul" also may lead to an error, so i would prefer ">nul chcp 708".
Putting the redirection in front certainly can't hurt, but it should not be necessary. CMD.EXE redirection only recognizes single digit file streams. The 8 would only be a problem if it were a complete token, but it is part of the larger 708 token. So CMD.EXE knows it does not represent a file stream.


Dave Benham

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Best way to obfuscate a Batch File?

#39 Post by dbenham » 31 Aug 2017 23:25

I updated the code to add the dot to the delims option.

Dave Benham

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: Best way to obfuscate a Batch File?

#40 Post by PaperTronics » 01 Sep 2017 07:44

@dbenham - Perhaps posting the solution directly to the website may help. Can you please reply to Michal directly on the website since none of us, Kvc or me, understand JS.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Best way to obfuscate a Batch File?

#41 Post by aGerman » 01 Sep 2017 08:53

I don't want to speak for Dave. So the following is just my opinion.

You asked Dave if you can use/post his code on your website. You copied the code and uploaded it externally. This is the first point where you failed. Nobody but you can update this upload. Don't expect you get informed whenever Dave updates his code here at DosTips. So from my point of view it would have been much better to post a link to this thread instead. Also even that you told the people who developed the code you didn't tell them where to get help. Of course they will ask you if they get problems now. And of course you have to answer. Are you really trying to force Dave being responsible to answer in any forum or on any website his code might be copied or linked?

Just my 2 cents ...
Steffen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Best way to obfuscate a Batch File?

#42 Post by dbenham » 01 Sep 2017 09:07

Perfect response Steffen, thanks.

@PaperTronics - I'm almost positive the dot will not solve Staszek Michal's problem.

I suspect he is using a machine configured for a multi-byte character set, which JREPL does not support (unfortunately). I'll leave it up to you to follow up with him. Ask him what active code page he is using (execute CHCP from command line and report the result). Then look up that code value to determine if it is multi-byte.


Dave Benham

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Best way to obfuscate a Batch File?

#43 Post by aGerman » 01 Sep 2017 13:25

dbenham wrote: :shock: Wow :!:
So the format of CHCP output must not be consistent across all languages. I was aware that the words would change, but I thought the punctuation would be consistent.

Code: Select all

Aktive Codepage: 850.

So it's just the point at the end of the sentence. That's how I usually work around it:

Code: Select all

for /f "tokens=2 delims=:" %%i in ('chcp') do set /a "oemcp=%%~ni"

Steffen

Kvc
Posts: 26
Joined: 13 Jun 2017 06:44
Location: India
Contact:

Re: Best way to obfuscate a Batch File?

#44 Post by Kvc » 01 Sep 2017 18:08

aGerman wrote:I don't want to speak for Dave. So the following is just my opinion.

You asked Dave if you can use/post his code on your website. You copied the code and uploaded it externally. This is the first point where you failed. Nobody but you can update this upload. Don't expect you get informed whenever Dave updates his code here at DosTips. So from my point of view it would have been much better to post a link to this thread instead. Also even that you told the people who developed the code you didn't tell them where to get help. Of course they will ask you if they get problems now. And of course, you have to answer. Are you really trying to force Dave being responsible to answer in any forum or on any website his code might be copied or linked?

Just my 2 cents ...
Steffen


Pardon me for forgetting about - posting the related link of the forum in the article (My Bad). Handling lot of things together leads me to forget important things. I'll quickly update the article.

And, We are not forcing Dave - Just trying to get their help in understanding the working & solution for their complex work. We always change the source Link of the code with our own Media-fire link because of two reasons...

1. The BatchStore Project (http://www.thebateam.org/2017/06/batch-app-batch-store-v10-by-kvc.html)
And, BatchStore detects only Mediafire links as project download links... :)
2. If Someone removes the Code from the source - We'll need to update all those related articles again & again. (And, we'll know about the problem - only if someone complains... SO, didn't want to depend on such conditions - independent solution. Already faced some problems in this case - so,...)
3. Newbie programmers don't even know 'how to use these plugins?' so, Needed to provide a simple help file in the download link - such as 'Test.bat' in this case. So, they can get the result quickly. And, when the curiosity takes over their lazy brain... they'll try to know how it worked. And, then self-motivation will motivate them to know more about the plugin, its creator, and the method - how it works?

Can't do all 3 when we'll only provide the link to the source of the code. But, we can provide the link alongside with our download link. Thanks for the reminder - From next time We'll keep that in mind. :)

Kvc
Posts: 26
Joined: 13 Jun 2017 06:44
Location: India
Contact:

Re: Best way to obfuscate a Batch File?

#45 Post by Kvc » 01 Sep 2017 18:17

dbenham wrote:I suspect he is using a machine configured for a multi-byte character set, which JREPL does not support (unfortunately). I'll leave it up to you to follow up with him. Ask him what active code page he is using (execute CHCP from the command line and report the result). Then look up that code value to determine if it is multi-byte.


Dave Benham


:shock: :shock: :shock: :shock: Perfect. And, I'll also ask Michal to update the code from v.1.0 to v.1.1 (your recent update). But, Are you sure - it is not the problem of having java installed in the PC? (just curious)

If you can't stop thinking about it, never stop working for it.

Post Reply