shc的官网下载地址http://www.datsi.fi.upm.es/~frosal/sources/
shc是一个专业的加密shell脚本的工具.它的作用是把shell脚本转换为一个可执行的二进制文件,这个办法很好的解决了脚本中含有IP、
密码等不希望公开的问题。
如果你的shell脚本包含了敏感的口令或者其它重要信息, 而且你不希望用户通过ps
-ef(查看系统每个进程的状态)捕获敏感信息. 你可以
使用shc工具来给shell脚本增加一层额外的安全保护. shc是一个脚本编译工具, 使用RC4加密算法, 它能够把shell程序转换成二进制可执
行文件(支持静态链接和动态链接). 该工具能够很好的支持: 需要加密, 解密, 或者通过命令参数传递口令的环境.
wget http://www.datsi.fi.upm.es/~frosal/sources/shc-38.9b.tgz
tar -zvxf shc-3.8.9b.tgz
cd shc-3.8.9
mkdir -p /usr/local/man/man1
make & make install --这是要回答yes
或者y,不能直接回车,否则会报错
shc密使用方法: shc -rf text.sh
text.sh text.sh.x text.sh.x.c
注意:要有-r选项, -f 后跟要加密的脚本名。
运行后会生成两个文件,script-name.x 和 script-name.x.c,script-name.x是加密后的可执行的二进制文件。 ./script-name
.x 即可运行。script-name.x.c是生成script-name.x的原文件(c语言)
通常:使用sch命令对shell脚本文件进行加密后,只需保留.x的二进制文件即可,其他两个文件均可以删除!
另外,shc还提供了一种设定有效执行期限的方法,可以首先使用shc将shell程序转化为二进制,并加上过期时间,如:
shc -e 31/12/2021 -m "测试失效" -v -r -f text.sh
解释:
-e:指定过期时间为2021年12月31日
-m:过期后打印出的信息;
-
v
: verbose
-r: 可在相同操作系统的不同主机上执行
-f: 指定源shell
如果在过期后执行,则会有如下提示:
.
/text
.sh.x: this script
file
is about to expire
shc的帮助命令:
shc -help
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 (指定要编译的shell的路径及文件名)
-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.