For shell script encryption you need to install shc package
1. install shc
https://drive.google.com/open?id=0BwPBGrPmbppAYm9JRmhwTEp4ck0
2. extract shc-3.8.7.tgz and compile
tar xvfz shc-3.8.7.tgz
cd shc-3.8.7/
make
How To Encrypt Shell Script ??
-rwxrw-r--. 1 purval purval 149 Mar 27 01:09 random.sh
-rwx-wx--x. 1 purval purval 11752 Mar 27 01:12 random.sh.x
-rw-rw-r--. 1 purval purval 10174 Mar 27 01:12 random.sh.x.c
1. install shc
https://drive.google.com/open?id=0BwPBGrPmbppAYm9JRmhwTEp4ck0
2. extract shc-3.8.7.tgz and compile
tar xvfz shc-3.8.7.tgz
cd shc-3.8.7/
make
How To Encrypt Shell Script ??
Create a sample bash shell script that you like to encrypt using shc for testing purpose.
For testing purpose, let us create the following random.sh shell script which generates random numbers. You have to specify how many random numbers you like to generate.
$ nano random.sh #!/bin/bash echo -n "How many random numbers do you want to generate? " read max for (( start = 1; start <= $max; start++ )) do echo -e $RANDOM done $ ./random.sh How many random numbers do you want to generate? 3 24682 1678 491
shc -r -T -f random.sh
This will create the following two files:
$ ls -l random.sh*-rwxrw-r--. 1 purval purval 149 Mar 27 01:09 random.sh
-rwx-wx--x. 1 purval purval 11752 Mar 27 01:12 random.sh.x
-rw-rw-r--. 1 purval purval 10174 Mar 27 01:12 random.sh.x.c
- random.sh is the original unencrypted shell script
- random.sh.x is the encrypted shell script in binary format
- random.sh.x.c is the C source code of the random.sh file. This C source code is compiled to create the above encrypted random.sh.x file. The whole logic behind the shc is to convert the random.sh shell script to random.sh.x.c C program (and of course compile that to generate the random.sh.x executable)
$ file random.sh random.sh: Bourne-Again shell script text executable $ file random.sh.x random.sh.x: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped $ file random.sh.x.c random.sh.x.c: ASCII C program text
Now, let us execute the encrypted shell script to make sure it works as expected.
$ ./random.sh.x How many random numbers do you want to generate? 3 7489 10494 29627
No comments:
Post a Comment