Friday, May 25, 2012

Sherlock Holmes: Secret of encrypted PowerShell Script files.. Password Protect .PS1 files using VIM.

 

sh_profile7

Hi,

This article is quite off from my regular PowerShell topic, but it's fun doing it .  So the situation is like that, One of my friend wrote a Powershell script but someone he wants to encrypt or password protected so that on one else {his fellow colleagues who just believes in COPYING & PASTING and make no efforts to learning technologies} use it, copy it .

When is asked me this question, i was not sure what to do,,as i always believe is sharing...then VIM come to my mind and in my one previous article i also mentioned about vim in this blog. You can find the article here:

 http://newdelhipowershellusergroup.blogspot.in/2011/11/hi-i-hope-some-of-you-know-about-what.html

Let's start.

so we have a enc.ps1 file in D drive and that file contains a two line script.

25-05-2012 12-24-39

run the script , So all is good... we have a script file and that file is running successfully.

25-05-2012 12-26-16

, I hope that you already have VIM on you laptop if not check my previous article which i mentioned in the beginning of this article.

now just open the enc.ps1 file in vim so that we can check that if file is opening in the vim or not.

25-05-2012 12-30-20

ok, file is opening, now press "ESCAPE" key and type q! in vim. {q means quit}

25-05-2012 12-31-01

now open the file again with -x parameter on vim. {small x not X (as VIM is based on Linux and Linux is case sensitive)}

25-05-2012 12-32-58

Now it ask you to enter a encryption password, provide it .

25-05-2012 12-33-28

Ok type the same password again.

25-05-2012 12-34-21

It open our .PS1 file,, now type,press "Escape" key again., in colon type wq! and press enter {w=write, q=quit}

25-05-2012 12-35-09

okies we are back to our Powershell console.

25-05-2012 12-36-51

Now lets open our enc.Ps1 Powershell script file in notepad.

Ooops,, i don't know this "Alien's" scripting language,, i think we need "Sherlock Holmes" to decode it..

25-05-2012 12-38-35

Mission accomplished :-)

Now whenever you open the same file in VIM it ask you for password first.

25-05-2012 12-41-02

asking for password to open the file.

25-05-2012 12-41-18

and if someone runs it. :)

Damn!!!!! :)

25-05-2012 12-42-30

oh !!!! and how to change or remove password :)

Open the file in VIM , Enter you password to open it . press "ESCAPE" key and type :X {capital } and hit enter.

25-05-2012 12-45-35

if you want to change password provide it , if you want to remove the password, jut keep it blank and press Enter.

25-05-2012 12-45-57

Press Enter again

25-05-2012 12-47-28

now press "Escape" , type wq! {write, quite, forcefully}

25-05-2012 12-47-59

Now we are back in Powershell console. now open the same file in "notepad"

25-05-2012 12-50-04

Wow !! we back from where we start.

I hope that you enjoyed this post.

Thanks

Aman Dhally

Buy-More-Twitter-Followers

00485s99

3 comments:

  1. The theme of your blog is very beautiful and the article is written very well, I will continue to focus on your blog.

    Pgp software

    ReplyDelete
  2. Quick question:

    I've encrypted a ps1 script using VIM as above, now i need to share this script on different computers, but i don't want to share the password or else it will easily decrypted. Is there any way to run it on a powershell providing the password as a secured string?

    ReplyDelete
    Replies
    1. Sorry, Tyrant,

      by using VIM , if you encrypted the script, then eother you have to share the password, or you have to decrypt it.
      :(

      i think these are the only tow ways,

      thanks
      aman

      Delete