当前位置: > shell编程 >

使用shc加密shell、perl等脚本

时间:2014-04-29 01:36来源:linux.it.net.cn 作者:IT网
官网下载 http://www.datsi.fi.upm.es/~frosal/

Shc用来对shell脚本进行加密,可以将shell脚本转换为一个可执行的二进制文件。经过shc对shell脚本进行加密后,会同时生成两个新的文件,一个是加密后的可执行的二进制文件(name.sh.x),另一个是C语言的原文件(name.sh.x.c)

wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgz
tar zxvf shc-3.8.9.tgz
cd shc-3.8.9
make && make install

make报错处理
make: *** No rule to make target `shc.c', needed by `shc'.  Stop.
cat makefile
shc: shc.c
        $(CC) $(CFLAGS) $@.c -o $@

mv mv shc-3.8.9.c shc.c

shc Version 3.8.9, Generic Script Compiler
shc Copyright (c) 1994-2012 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 #显示帮助和退出

实例

shc -e 31/8/2012 -m ExpireTime:31/8/2012 -v -r -f name.sh

==============================

基本使用方法是这样的 以shell脚本为例
shc -r -f test.sh
生成了动态链接可执行二进制文件test.sh.x和C源文件test.sh.x.c, 注意生成的二进制文件因为是动态链接形式, 所以在其它平台上不能运行。
不过, 我们可以通过下面的方法生成一个静态链接的二进制可执行文件:
# CFLAGS=-static shc -r -f test.sh
# file test.sh.x
test.sh.x: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
statically linked, for GNU/Linux 2.6.9, stripped
提示: 通过sch加密后的脚本文件很安全吗?
一般来说是安全的, 不过可以使用gdb和其它的调试工具获得最初的源代码. 如果你需要更加安全的方法, 可以考虑使用wzshSDK.
另外, sch还可以设置脚本的运行期限和自定义返回信息:
shc -e 03/31/2008 -m “the test script is now out of date.” -f test.sh
-e表示脚本将在2007年3月31日前失效, 并根据-m定义的信息返回给终端用户.
二进制文件的剖析
有兴趣的朋友可以参阅下面的文章:
Paranoid Penguin - Limitations of shc, a Shell Encryption Utility
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容