Shell Scripting Encryption

Source: Internet
Author: User
Tags mysql backup

How to protect a shell program you've written
To protect your own shell scripting program, there are many methods, the simplest way there are two: 1, encryption 2, set the expiration time, following the SHC tool as an example description:

I. Download and install the SHC tool
SHC is a tool for encrypting shell scripts. Its role is to convert the shell script into an executable binary file.

# wget Http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.7.tgz

Installation:
# tar ZXVF shc-3.8.7.gz

# CD shc-3.8.7


# mkdir/usr/local/man/man1/(Install the man file into the directory, if the directory does not exist need to be built in advance) This step requires root permissions

# Make Test
# make
# Make Test
# Make Strings
# make install this step requires root privileges


Second, the encryption method:
Shc-r-F script-name Note: To have the-r option, the-F followed by the name of the script to encrypt.
Two files will be generated after running, script-name.x and SCRIPT-NAME.X.C
Script-name.x is an executable binary file after encryption.
./script-name can be run.
SCRIPT-NAME.X.C is the original file that generated the script-name.x (C language)


# shc-v-F test.sh

-V is the verbose mode, output more detailed compilation log;

-f Specifies the name of the script.

# ll Test*

-rwxr-xr-x 1 Oracle Oinstall 1178 10:00am test.sh
-rwx--x--x 1 Oracle oinstall 8984 18:01 test.sh.x
-rw-r--r--1 Oracle oinstall 14820 18:01 test.sh.x.c

# file test.sh.x

Test.sh.x:elf 32-bit LSB executable, Intel 80386, version 1 (SYSV), for Gnu/linux 2.2.5, dynamically linked (uses shared LIBS), stripped

You can see the generated dynamic link executable binaries test.sh.x and C source file testup.sh.x.c, note that the generated binaries are not run on other platforms because they are dynamic link forms.

Generating a statically linked binary executable file

You can generate a statically linked binary executable file by using the following method:

$ cflags=-static shc-r-F test.sh

$ file testup.sh.x


Three. Is it safe to use SCH-encrypted script files?

It's generally safe, but you can use GDB and other debugging tools to get the original source code. If you need a more secure approach, consider using WZSHSDK. In addition the SHC can also set the runtime and custom return information for the script:

$ shc-e 03/31/2007-m "The MySQL backup scrīpt is now out of date."-F test.sh

-e means that the script will expire before March 31, 2007 and be returned to the end user based on the information defined by-M.


Outside the question:

If you just can't see the content, you can use
Gzexe a.sh

The original a.sh is saved as a.sh~, the new a.sh is garbled, but can be run in SH mode

Shell Scripting Encryption

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.