首页 > 技术文章 > Shell脚本加密--shc/gzexe

lixuebin 2015-10-12 13:52 原文

Shell脚本加密--shc/gzexe

官方网站:http://www.datsi.fi.upm.es/~frosal/

说明:shc是一个脚本编译工具, 使用RC4加密算法, 它能够把shell程序转换成二进制可执行文件(支持静态链接和动态链接)。当shell脚本存在敏感信息如账号密码,想加强脚本的安全性又或是不想让别人查看及修改您shell核心代码等情况。都可使用以下工具进行加密。


安装
wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz
yum -y install gcc gcc-c++
mkdir -p /usr/local/man/man1
make install

常用参数:
-e date
-m message
-f script_name
-r Relax security
-v Verbose compilation

使用说明
shc -v -r -T -f test.bash
运行后会生成两个文件:
test.bash.x 和 test.bash.x.c
test.bash.x为二进制文件,赋予执行权限更改名字mv test.bash.x test.sh
test.bash.x.c 是c源文件,可以删除

Shell脚本加密--shc/gzexe

注意:生成的二进制文件是动态链接形式, 所以在其它平台上不能运行

编译参数来生成静态链接库的脚本

CFLAGS=-static shc -v -r -T -f test.bash

Shell脚本加密--shc/gzexe

错误解决:


/usr/bin/ld: cannot find -lc

collect2: ld returned 1 exit status

如果编译静态脚本时出错,说明没有找到静态链接库lib.a,请yum -y install glibc-static



过期时间

shc -e 01/01/2016 -m "liujun_live@icloud.com" -f test.csh
如果在过期后执行,则会有如下提示:
root@db:shc-3.8.9b#./test.csh.x
./test.csh.x: has expired!
liujun_live@icloud.com
提示:以上方法需防止用户更改系统时间,可通过在程序中加入自动更新系统时间(ntpdate time.nist.gov)来解决。



gzexe
gzexe foo.sh
原来的 foo.sh 就被存为 foo.sh~,新的 foo.sh 是乱码,但是可以用 sh 的方式运行

Shell脚本加密--shc/gzexe

推荐阅读