Shell script to Binary executable file Conversion

If you wise to distribute your script but don’t want anyone to modification or inspection, follow the below procedure to protect the script by converting to binary executable format.

  1. Write a shell script. eg. my_script.sh
  2. If your system runs on RHEL5, Download & Install “shc” rpm from ftp://ftp.is.co.za/mirror/ftp.rpmforge.net/redhat/el5/en/i386/dag/RPMS/shc-3.8.6-1.el5.rf.i386.rpm  For other version of OS, download & install the appropriate rpm version
  1. Execute the following commandshc –v –e 20/03/2011 –m “Command expired” –r  –T  –f  <my_script.sh>
    • v Verbose compilation
    • -r Relax security. Make a redistributable binary which executes on different systems running the same operating system.
    • -T Allow binary to be traceable (using strace, ptrace, truss, etc.)
    • -f <script name> File name of the script to compile
    • -e <dd/mm/yyyy> Expiration date in dd/mm/yyyy format
    • -m <message> message to display upon expiration

  1. Upon the compilation, you will get output similar to this

                    shc shll=bash
                    shc [-i]=-c
                    shc [-x]=exec ‘%s’ “$@”
                    shc [-l]=
                    shc opts=
                    shc: cc  my_script.sh.x.c -o my_script.sh.x
                    shc: strip my_script.sh.x
                    shc: chmod go-r my_script.sh.x

  1. Verify the file type

                  $file my_script.sh.x

                    my_script.sh.x: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped

  1. Now you can execute the command & check the result

                   $./my_script.sh.x

  1. Backup your original script and distribute the executable file.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s