Securily Compile ps1 to exe

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
aspersram
Posts: 7
Last visit: Sat Apr 08, 2023 8:01 am

Securily Compile ps1 to exe

Post by aspersram »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PS Studio 2021
Operating system: Windows 10
PowerShell version(s):5.1

Is it possible to use Powershell Studio to compile a ps1 script to an executable that can be sold without fear of decompilation? If not, is there another option to do this?
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Securily Compile ps1 to exe

Post by Alexander Riedel »

It is not a compiler. A compiler translates source code into machine code. C/C++ is a good example for that. Not easily reversible.
C# is translated into ILASM and only compiled at the endpoint. Very easy to de-compile.
The part in PowerShell Studio is called a "packager". It bundles your PowerShell code into an encrypted blob inside the executable.
Due to the nature of PowerShell, being an interpreted scripting language, it has to exist as clear code at the point of execution.
If you make sure you don't have script block logging and so forth enabled, you can make it so that a normal user will not see your code.
(There is an option for that when packaging)
Give that you use a SAPIEN Script Host engine, your code is executed in memory, not as a temporary file.

A fully authorized admin on a machine with a debugger or the ability to enable script block logging will be able to see your code.
You can employ an obfuscator to mangle your code before packaging, which will severely reduce the usefulness of any code recovered.

Is it 100% secure? No.
Can you make it so that regular users cannot see your code? Yes.
It all depends on where you want to deploy that and what level of users will have access.

Generally, if you sell software, you should have a license agreement which will prevent users from reverse engineering or disassembling your code by contract.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
aspersram
Posts: 7
Last visit: Sat Apr 08, 2023 8:01 am

Re: Securily Compile ps1 to exe

Post by aspersram »

Thank you Alexander for your response. I understand that the code is not compiled, but rather bundled. Ideally, I'm looking for something that will obfuscate the code and turn it into an executable from teh command line,(so I can automate deployment. Do you see any way to accomplish this? Thanks.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Securily Compile ps1 to exe

Post by Alexander Riedel »

A script would do that. :D
Use any obfuscator to obfuscate your script, say from
myscript.ps1 -> ObfusctatedMyScript.ps1
Copy the myscript.ps1.psbuild file to ObfusctatedMyScript.ps1.psbuild
run psbuild.exe /PACKAGE ObfusctatedMyScript.ps1.psbuild
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.