2

I use PowerGUI to convert my PowerShell scripts to executables, and it is working fine.

I'd like to prevent my compiled script from being extracted or decompiled by users I distribute the generated executable to.

Is it possible to view my PowerShell script inside the generated executable? If so, how do I prevent this?

Kev
  • 118,037
  • 53
  • 300
  • 385
Sreehari Babu
  • 61
  • 1
  • 3
  • 2
    That depends on how your converter works. It could just be an exe wrapper that calls the ps1. Or it could be a binary in which case reverse engineering it could be hard. You are not trying to hide something like a password in there are you? – Matt Mar 20 '15 at 13:56
  • Thanks for quick reply Matt. I am not calling ps1 file with exe. its complete .exe file and it contains powershell code. – Sreehari Babu Mar 20 '15 at 15:11
  • After [reading this blog](https://dmitrysotnikov.wordpress.com/2011/08/22/compile-powershell-scripts-to-exe/) I saw the comment from a user that decompressed the EXE and found the script. _Nevermind I extracted the text file with 7 zip, and low and behold there is my script._. A previous team member can also be quoted as saying _This depends on whether you select the “__Protect source code__” checkbox._ – Matt Mar 20 '15 at 15:17
  • Not sure why all the downvotes, perfectly sane question about a PowerShell development tool. :/ – Kev Mar 20 '15 at 15:52

3 Answers3

1

Unfortunately with PowerGUI it's not possible to prevent users of your executable from viewing your script, even if you use the "Protect script source code with a password" option.

The executable that PowerGUI generates is a self extracting ZIP file so it's possible to use 7-zip or WinRAR to open this file and view the original PowerShell script.

If you set a password using the "Protect script source code with a password" option all this does is password protect the files inside the ZIP container. However when launching the generated executable you'll be prompted for said password which can then be used to access the original script.

Kev
  • 118,037
  • 53
  • 300
  • 385
  • Thanks for the detail explanation Kev. is there any way to convert ps1 to exe apart from Powergui and protect code ? – Sreehari Babu Mar 22 '15 at 04:25
  • @SreehariBabu - I'm not aware of any tools to do this. you might want to google around to see if there's any PowerShell "obfuscators", I did for a few minutes and didn't come up with anything. Your best bet would be to rewrite whatever PS functionality you want to protect as a compiled C# or VB.NET console exe. – Kev Mar 23 '15 at 18:46
1

If you want to somewhat obfuscate the code, look at PS2EXE:

http://ps2exe.codeplex.com/

which points to:

https://gallery.technet.microsoft.com/PS2EXE-Convert-PowerShell-9e4e07f1

Mr. Annoyed
  • 541
  • 3
  • 18
1
  1. download the ps2exe http://ps2exe.codeplex.com/

  2. run power shell cd the folder of ps2exe

  3. run: .\yourfile.ps1 -inputFile C:\Users\franc\Desktop\temp\ps2exe\Install.ps1 C:\Users\franc\Desktop\temp\ps2exe\Install.exe

  4. check the folder, the exe will be there

Francisco
  • 31
  • 1
  • 4