shell脚本加密工具shc
这是我参与8月更文挑战的第12天,活动详情查看:8月更文挑战
SHc (SHell compiler) is a fabulous tool created and maintained by Francisco Javier Rosales Garcia (www.datsi.fi.upm.es/~frosal/). This tool protect any shell script with encryption (ARC4).
shc安装
wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz
tar -vxf shc-3.8.9b.tgz
cd shc-3.8.9b
make test
make strings
sudo mkdir -p /usr/local/man/man1/
sudo make install
验证是否安装完成
which shc
常用参数解析
-e date (指定过期日期)
-m message (指定过期提示的信息)
-f script_name(指定要编译的shell的路径及文件名)
-r Relax security. (可以相同操作系统的不同系统中执行)
-v Verbose compilation(编译的详细情况)
具体用法
生成动态链接的二进制可执行文件
shc -r -f deploy.sh
-f 指定要解密的文件
-r 指定一种安全的加密方式。
生成两个文件,deploy.sh.x和deploy.sh.x.c,前者是动态链接的二进制可执行文件,后者相应的是C程序。 注:这里产生一个问题,因为动态链接属性,前者deploy.sh.x运行时需要对应库的链接的支持,也就是说,目标运行环境也需要安装shc或者安装shc的库。具体解决办法见下后面的:生成静态链接的二进制文件。
运行
./deploy.sh.x
可以直接
mv deploy.sh.x deploy
把.sh.x的文件类型信息简单隐藏掉。 使用
file deploy.sh.x #可能会报错
设置脚本过期时间
shc -e 14/09/2016 -f deploy.sh
生成静态链接的二进制可执行文件
CFLAGS=-static shc -r -f deploy.sh
自定义返回信息
shc -m "hello world " -f deploy.sh
报错处理
原因:
You have to put the sha-bang (e.g. #!/bin/bash) at the beginning of the script, since shc need to know which shell is using. Here is an excerpt from the manual page
解释: 在脚本的第一行添加上
#!/bin/bash