Encrypting a shell script

Go to the link https://www.datsi.fi.upm.es/~frosal/sources/ and download latest stable source for shc
in this case the latest source is  shc-3.8.9b.tgz

#cd /usr/local 
#sudo wget  https://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz
#sudo tar -zxvf shc-3.8.9b.tgz
#cd shc-3.8.9
#make test
#make strings
#make expiration
#mkdir -p /usr/local/man/man1
#make install

now shc in installed on your system in /usr/local/bin

to encrypt the script

#shc -help gives the complete information about how we can use the package

shc -help
shc Version 3.8.9b, Generic Script Compiler
shc Copyright (c) 1994-2015 Francisco Rosales <frosal@fi.upm.es>
shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script

 -e %s Expiration date in dd/mm/yyyy format [none]
 -m %s Message to display upon expiration ["Please contact your provider"]
 -f %s File name of the script to compile
 -i %s Inline option for the shell interpreter i.e: -e
 -x %s eXec command, as a printf format i.e: exec('%s',@ARGV);
 -l %s Last shell option i.e: --
 -r Relax security. Make a redistributable binary
 -v Verbose compilation
 -D Switch ON debug exec calls [OFF]
 -T Allow binary to be traceable [no]
 -C Display license and exit
 -A Display abstract and exit
 -h Display help and exit

 Environment variables used:
 Name Default Usage
 CC cc C compiler command
 CFLAGS <none> C compiler flags

 Please consult the shc(1) man page.

###### simple encryption ####
write a test script like below

echo Test Script

#shc -f test
This will create 2 files test.x (executable binary) and test.x.c(C source code) 

test.x is an executable file
test.x may or may not run on system depending upon kernel as it is non traceable

to overcome this problem we must compile our script as traceable and redistributable 
so that it can run on any system by any user.

#shc -Tf test (or you can write it in simple way shc -T -f test)

***** Encryption with expiration date and message *****

provide expiration date with -e in dd/mm/yyyy format and with -m type a message which you want to display after script expiration

#shc -e 01/01/2000 -m "This script expired.Contact your admin" -Tf test

Since the date is in past the encrypted script is already expired and after running ./test.x it will give message "This script expired.Contact your admin"

### The one more thing you can do with this is compile the C source code into the binary by below command.##

#gcc -o <binary-file-name> test.x.c

This will create c compiled binary file of your script. 
The only difference between the shc compiled binary and c compiled binary is shc compiled binary is stripped while the c compiled binary is not stripped. (non stripped binaries have debugging information built into it)
This is something different that you should try. 

Leave a Reply

Your email address will not be published. Required fields are marked *


* Copy This Password *

* Type Or Paste Password Here *

4,842 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>