Shell脚本加密


文章目录

  • Shell脚本加密
  • SHC - 加密等级高
  • 通过yum安装
  • 通过下载源码安装
  • 1 安装gcc及make,已安装的可略过,命令如下
  • 2 下载并编译安装shc-4.0.3
  • 3 进入shc压缩包所在目录,并解压包
  • 4 进入已解压目录并进行编译安装,编译安装全默认即可,并不需要创建任何目录,命令如下
  • 5 安装完成
  • 使用脚本
  • gzexe - 加密等级低


https://sunplayer.cn/?post=6

SHC - 加密等级高

注意:

  • CentOS7与CentOS8生成的脚本不通用,在哪个版本生成,在哪个版本使用

通过yum安装

  • 安装shc工具
yum install -y shc

通过下载源码安装

1 安装gcc及make,已安装的可略过,命令如下

yum -y install gcc make

2 下载并编译安装shc-4.0.3

因为是在GitHub上下载,所以你懂得,需要你用科学方法下来后,再传到需要安装的主机上,已附下载地址。
shc-4.0.3下载地址:https://github.com/neurobin/shc/archive/refs/tags/4.0.3.tar.gz

3 进入shc压缩包所在目录,并解压包

tar -xzvf shc-4.0.3.tar.gz

4 进入已解压目录并进行编译安装,编译安装全默认即可,并不需要创建任何目录,命令如下

cd shc-4.0.3
./configure && make install

5 安装完成

使用脚本

  • 创建一个shell脚本
[root@jast ~]# vim test-shc.sh

#!/bin/sh
echo `date`
  • 生成加密脚本
[root@10 ~]# shc -v -f test-shc.sh 
shc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc   test-shc.sh.x.c -o test-shc.sh.x
shc: strip test-shc.sh.x
shc: chmod ug=rwx,o=rx test-shc.sh.x

查看生成文件

[root@10 ~]# ll
total 36
-rw-r--r-- 1 root root    22 May 26 14:52 test-shc.sh
-rwxrwxr-x 1 root root 11120 May 26 14:52 test-shc.sh.x
-rw-r--r-- 1 root root 17592 May 26 14:52 test-shc.sh.x.c
  • shc.sh 是原始的未加密shell脚本
  • shc.sh.x 是二进制格式的加密shell脚本
  • shc.sh.x.c 是shc.sh文件的C源代码。编译该C源代码以创建上面的加密的welcome.sh.x文件

查看文件类型

[root@10 ~]# file test-jast.sh
test-jast.sh: POSIX shell script, ASCII text executable
[root@10 ~]# file test-jast.sh.x
test-jast.sh.x: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=65a9d57e8eb0a24f4a000fe680e030dbc23468f6, stripped
[root@10 ~]# file test-jast.sh.x.c
test-jast.sh.x.c: C source, ASCII text
  • 执行生成的加密文件
[root@10 ~]# ./test-jast.sh.x 
Thu May 26 14:56:30 CST 2022
  • 指定脚本过期时间,并设置提示信息
shc -e 06/10/2023 -m "error" -v -f test-jast.sh

执行脚本

[root@10 ~]# ./test-jast.sh.x                                
./test-jast.sh.x: has expired!
error

不指定-m默认提示

[root@10 ~]# ./test-jast.sh.x
./test-jast.sh.x: has expired!
Please contact your provider jahidulhamid@yahoo.com

gzexe - 加密等级低

gzexe:系统自带,无需另外安装,加密解密简单,适用于安全性不高的文件加密,支持除shell脚本外的其他文本加密。

gzexe加密/解密用法:

  • 加密
# 加密后会将源文件改名为 xxx.sh~
gzexe xxx.sh
  • 解密
# 解密后会将源文件改名为 xxx.sh~
gzexe -d Script-name.sh