一般用到的shell或是perl脚本有个问题
就是明文,用户可读,这样有些例如密码、ip地址等信息就非常的不安全,为了解决这个问题,向大家介绍个一个好工具---shc。
=======shc相关资料======= shc主页: http://www.datsi.fi.upm.es/%7Efrosal/
shc帮助文件如下 shc Version 3.8.6, Generic Script Compiler shc Copyright (c) 1994-2006 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. ==============================
这里以shell脚本为例,介绍shc的基本使用方法,如下: $ 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定义的信息返回给终端用户. |