Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Encrypt Batch  (Read 11568 times)

0 Members and 1 Guest are viewing this topic.

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Encrypt Batch
« on: March 26, 2014, 11:49:39 AM »
Dear all

I want to encrypt my batch file , i mean that i want users can use it but can't edit it or see the content the batch and if any one could open it will see strange characters and symbols.
Could any one help me or have a program to encrypt the Batch file as i mean .

patio

  • Moderator


  • Genius
  • Maud' Dib
  • Thanked: 1769
    • Yes
  • Experience: Beginner
  • OS: Windows 7
Re: Encrypt Batch
« Reply #1 on: March 26, 2014, 12:05:49 PM »
For what purpose ? ?
" Anyone who goes to a psychiatrist should have his head examined. "

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Encrypt Batch
« Reply #2 on: March 26, 2014, 12:16:21 PM »
We have a long Discussion thread about this over on DosTips.com
http://www.dostips.com/forum/viewtopic.php?f=3&t=4459

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Encrypt Batch
« Reply #3 on: March 26, 2014, 02:15:47 PM »
Because this is a public forum I am hesitant to tell you how.  I will however tell you that it is possible.  Keep looking.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Salmon Trout

  • Guest
Re: Encrypt Batch
« Reply #4 on: March 26, 2014, 02:17:56 PM »
Bottom line, if you want to write code that people cannot see, move up to a proper language. Even Visual Basic Script supports encryption. Scripts with the .vbs extension can be encrypted using the native Scripting Encoder to a .vbe file which executes just like the original script but which is difficult for ordinary users to decode.

Anyone who is serious about coding can manage the move from batch scripting to Visual Basic Script.

1. VBScript which uses the Scripting Encoder to create a .vbe file: drag a vbs script onto it and a file of the same name but with a .vbe extension will be created:

Option Explicit
 
dim oEncoder, oFilesToEncode, file, sDest
dim sFileOut, oFile, oEncFile, oFSO, i
dim oStream, sSourceFile
 
set oFilesToEncode = WScript.Arguments
set oEncoder = CreateObject("Scripting.Encoder")
For i = 0 to oFilesToEncode.Count - 1
    set oFSO = CreateObject("Scripting.FileSystemObject")
    file = oFilesToEncode(i)
    set oFile = oFSO.GetFile(file)
    Set oStream = oFile.OpenAsTextStream(1)
    sSourceFile=oStream.ReadAll
    oStream.Close
    sDest = oEncoder.EncodeScriptFile(".vbs",sSourceFile,0,"")
    sFileOut = Left(file, Len(file) - 3) & "vbe"
    Set oEncFile = oFSO.CreateTextFile(sFileOut)
    oEncFile.Write sDest
    oEncFile.Close
Next


2. Example simple VBScript

Set WshShell = WScript.CreateObject("WScript.Shell")
Dim aMsgBoxTextLines()

For S = 0 to 49
    Redim Preserve aMsgBoxTextLines(S)
    aMsgBoxTextLines(S) = "This is message box line......" & (S + 1000000)
Next

sMsgBoxMessage        = ""
For J = 0 To Ubound(aMsgBoxTextLines)
    sMsgBoxMessage    = sMsgBoxMessage & aMsgBoxTextLines(J) & vbcrlf
Next

iMsgBoxButtons        = 0
iMsgBoxButtons        = iMsgBoxButtons + vbAbortRetryIgnore
iMsgBoxButtons        = iMsgBoxButtons + vbExclamation
iMsgBoxButtons        = iMsgBoxButtons + vbDefaultButton1
sMsgBoxTitle          = "Message Box demo"
iMsgBoxTimeOutSeconds = 5
iMsgBoxRetVal         = WshShell.Popup(sMsgBoxMessage, iMsgBoxTimeOutSeconds,  sMsgBoxTitle, iMsgBoxButtons)

Select Case iMsgBoxRetVal
    case -1 Wscript.Echo "Timeout"
    case  1 Wscript.Echo "OK    "
    case  2 Wscript.Echo "Cancel"
    case  3 Wscript.Echo "Abort "
    case  4 Wscript.Echo "Retry "
    case  5 Wscript.Echo "Ignore"
    case  6 Wscript.Echo "Yes   "
    case  7 Wscript.Echo "No    "
End Select


3. Same script encoded

#@~^cwQAAA==jY~q/4?tV^~',jmMk2OcZDCYr4Nn^YvJq?^Dr2DRjtsVr#@#@&Gk:~Ct/LAKa:+aDSbx+k`*@#@&@#@&oWMPj~{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UYBAA==^#~@



 
« Last Edit: March 26, 2014, 03:05:30 PM by Salmon Trout »

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Encrypt Batch
« Reply #5 on: March 26, 2014, 02:22:34 PM »

...can be encrypted using the native Scripting Encoder...

Not supported in Windows Vista or Windows 7 sadly.
http://msdn.microsoft.com/en-us/library/d14c8zsc%28v=vs.84%29.aspx
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Salmon Trout

  • Guest
Re: Encrypt Batch
« Reply #6 on: March 26, 2014, 02:30:48 PM »
Not supported in Windows Vista or Windows 7 sadly.
http://msdn.microsoft.com/en-us/library/d14c8zsc%28v=vs.84%29.aspx

What? I just did it in Windows 7. Encoded the script and ran it. That's how I got the material for my post above.



Salmon Trout

  • Guest
Re: Encrypt Batch
« Reply #7 on: March 26, 2014, 02:43:47 PM »
To clarify:

There used to be a command line script encoding tool included with Windows NT, 2000 and XP called the Script Encoder (screnc.exe) which was not supported in Windows Vista and later. However the same functionality is provided in Windows Scripting Host from version 5.6 (XP) and later which includes scrrun.dll which exposes the Scripting Encoder Object (which you can see being used in my script above in this line set oEncoder = CreateObject("Scripting.Encoder"))

As far as screnc.exe is concerned, I believe that "not supported" in the case of Vista and later simply means "not included", "withdrawn", "retired", etc and I think the executable works on Vista and later (I have not tried it, and given there is no official way to download it, I don't expect to). There are 3rd party apps with the same name around which may or may not produce identically obfuscated code.





« Last Edit: March 26, 2014, 03:04:35 PM by Salmon Trout »

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Encrypt Batch
« Reply #8 on: March 26, 2014, 06:02:20 PM »
Thank you for the clarification.  I had not looked that closely at your code and was confused when my search didn't turn up any hits for the scripting editor. I'll have to get back into learning vbs after I finish java.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Encrypt Batch
« Reply #9 on: March 26, 2014, 10:42:21 PM »
I seem to recall finding a website that decoded .vbe files - and google has plenty of material https://www.google.com.au/search?hl=en&q=decode+.vbe+file

Batch files can be converted to exe files, but it's not 100% effective.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Encrypt Batch
« Reply #10 on: March 27, 2014, 12:42:38 PM »
Anyone play with VbsEdit.  Has some compile to exe option.  I tried it on a basic VBscript and it seems to work but I am not sure if it is doing the same thing as all those Bat2Exe programs are doing.  Is it just extracting the VBS to a temp file and then running it?

Salmon Trout

  • Guest
Re: Encrypt Batch
« Reply #11 on: March 27, 2014, 01:04:37 PM »
Is it just extracting the VBS to a temp file and then running it?

Yes. Autoit, VbsEdit, you name it. They all work that way. Scripts are wrapped or appended to a stub which extracts the script and runs it. There are some script wrappers which obfuscate the script and/or run it from memory, but it is always the script which is being run. No compilation or conversion to machine code is taking place.

Abo-Zead

    Topic Starter


    Beginner
  • Thanked: 1
  • Experience: Familiar
  • OS: Windows 10
Re: Encrypt Batch
« Reply #12 on: March 27, 2014, 03:35:41 PM »
thank you all for your support.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Encrypt Batch
« Reply #13 on: March 27, 2014, 07:14:26 PM »
Yes. Autoit

I haven't used AutoIt but was it that or another tool with a similar name that creates executables that are stand alone? 
The main program doesn't need to be installed so they must be proper compiled binaries...

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Encrypt Batch
« Reply #14 on: March 27, 2014, 10:06:06 PM »
The main program doesn't need to be installed so they must be proper compiled binaries...

In the case of these programs, the "compiler" just takes a stub program and sticks the script on the end of the executable. The executable knows to read the script from the end of itself rather than expect a separate file.

I was trying to dereference Null Pointers before it was cool.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Encrypt Batch
« Reply #15 on: March 27, 2014, 10:24:56 PM »
In the case of these programs, the "compiler" just takes a stub program and sticks the script on the end of the executable.

I see.  Thanks.


Salmon Trout

  • Guest
Re: Encrypt Batch
« Reply #16 on: March 28, 2014, 02:04:28 AM »
I haven't used AutoIt but was it that or another tool with a similar name that: creates executables that are stand alone? 
The main program doesn't need to be installed so they must be proper compiled binaries...

Auto-it produces executables which are scripts accompanied by a runtime script execution engine. The produced executable can be compressed using UPX and also the embedded script can be obfuscated, but it is always there. It is what gets executed. One of the strictest rules of the Auto-it discussion forum is "No. discussion of decompilers"
« Last Edit: March 28, 2014, 02:15:53 AM by Salmon Trout »

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Encrypt Batch
« Reply #17 on: March 28, 2014, 02:41:28 AM »
Gotcha.  Ta!

powlaz



    Beginner
  • Thanked: 1
    Re: Encrypt Batch
    « Reply #18 on: March 28, 2014, 07:48:55 AM »
    I use http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html for this. 

    I recall someone telling me that there is nothing on the market that completely obfuscates batch files but for the average user this will keep your script out of view.

    Note that if a user figures out that the script is unpacked from the .exe before it is run then they'll be able to track it down and see everything.  I've been using it for years though and no one's figured it out yet ;)

    MJ