Search This Blog

Thursday, 8 December 2016

Encrypt shell script using shc in linux

For shell script encryption you need to install shc package

1. install shc

2. extract shc-3.8.7.tgz and compile

tar xvfz shc-3.8.7.tgz

cd shc-3.8.7/


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 shell script which generates random numbers. You have to specify how many random numbers you like to generate.

$ nano

echo -n "How many random numbers do you want to generate? "
read max

for (( start = 1; start <= $max; start++ ))
  echo -e $RANDOM

$ ./
How many random numbers do you want to generate? 3
shc -r -T -f
This will create the following two files:
$ ls -l*
-rwxrw-r--. 1 purval purval 149 Mar 27 01:09
-rwx-wx--x. 1 purval purval 11752 Mar 27 01:12
-rw-rw-r--. 1 purval purval 10174 Mar 27 01:12

  • is the original unencrypted shell script
  • is the encrypted shell script in binary format
  • is the C source code of the file. This C source code is compiled to create the above encrypted file. The whole logic behind the shc is to convert the shell script to C program (and of course compile that to generate the executable)
$ file Bourne-Again shell script text executable

$ file ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

$ file ASCII C program text

Now, let us execute the encrypted shell script to make sure it works as expected.
$ ./
How many random numbers do you want to generate? 3

No comments:

Post a Comment

Switch between multiple PHP version in Ubuntu

If you have two php versions (e.g. PHP7.2 and PHP 5.6 ) installed in your ubuntu system. Switch from PHP 5.6 to PHP 7.2 =====> Apac...