通过SHC加密Shell脚本

shc是一个加密shell脚本的工具.它的作用是把shell脚本转换为一个可执行的二进制文件

成都创新互联公司10多年企业网站建设服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,企业网站建设及推广,对成都阳光房等多个领域拥有多年设计经验的网站建设公司。

环境

Centos8

安装shc

[root@localhost ~]# yum -y install shc

创建一个shell脚本

下面创建一个脚本文件:

[root@localhost ~]# vim welcome.sh

#!/bin/sh
echo "Welcome to linux world"

使用shc加密该脚本文件

如下所示,使用shc加密welcome.sh脚本。

[root@localhost scripts]# shc -v -f welcome.sh
shc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc   welcome.sh.x.c -o welcome.sh.x
shc: strip welcome.sh.x
shc: chmod ug=rwx,o=rx welcome.sh.x

  • welcome.sh 是原始的未加密shell脚本
  • welcome.sh.x 是二进制格式的加密shell脚本
  • welcome.sh.x.c 是welcome.sh文件的C源代码。编译该C源代码以创建上面的加密的welcome.sh.x文件。

可以使用file命令查看文件的类型:

[root@localhost scripts]# file welcome.sh
welcome.sh: POSIX shell script, ASCII text executable
[root@localhost scripts]# file welcome.sh.x
welcome.sh.x: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=35e0e2569eca90774e379d6fef51ad6fedf346f5, stripped
[root@localhost scripts]# file welcome.sh.x.c
welcome.sh.x.c: C source, ASCII text
[root@localhost scripts]#

执行加密后的shell脚本

现在,让我们执行加密的Shell脚本,确保能够运行:

[root@localhost scripts]# ./welcome.sh.x
Welcome to linux world

指定Shell脚本的过期时间

使用shc,您还可以指定到期日期。即在这个到期日期之后,当有人尝试执行Shell脚本时,将收到错误消息。使用shc -e选项创建一个新的加密Shell脚本,指定到期日期。到期日期以dd/mm/yyyy 格式指定。

# 删除之前创建的.x , .x.c文件
[root@localhost scripts]# rm -rf welcome.sh.x*
# 创建带有过期时间的加密脚本
[root@localhost scripts]# shc -e 01/02/2021 -v -f welcome.sh
shc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc   welcome.sh.x.c -o welcome.sh.x
shc: strip welcome.sh.x
shc: chmod ug=rwx,o=rx welcome.sh.x

在此示例中,如果有人尝试执行welcome.sh.x脚本文件,会提示已过期。

[root@localhost scripts]# ./welcome.sh.x
./welcome.sh.x: has expired!
Please contact your provider jahidulhamid@yahoo.com

如果要指定自定义到期消息,需要加入-m选项。

[root@localhost scripts]# shc -e 01/02/2021 -m "Please contact admin@example.com!" -v -f welcome.sh
shc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc   welcome.sh.x.c -o welcome.sh.x
shc: strip welcome.sh.x
shc: chmod ug=rwx,o=rx welcome.sh.x

网站名称:通过SHC加密Shell脚本
标题URL:http://www.hantingmc.com/qtweb/news4/191504.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联