SHELL脚本加密工具shc和gzexe

  有时候我们的shell脚本会包含一些敏感信息,例如:用户名、密码、文件的路径、IP地址等。如果不希望这些信息别人看到,或者在运行时泄露敏感信息。对shell脚本进行加密是个不错的选择。

 

方法一:shc  

  shc是一个加密shell脚本的工具.它的作用是把shell脚本转换为一个可执行的二进制文件.用shell脚本对系统进行自动化维护,简单,便捷而且可移植性好。

shc 安装 
yum -y install shc

wget http://down1.chinaunix.net/distfiles/shc-3.8.3.tgz

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

使用方法:

shc -r -f script-name 注意:要有-r选项, -f 后跟要加密的脚本名.

 

运行后会生成两个文件,script-name.x 和 script-name.x.c

script-name.x是加密后的可执行的二进制文件.

./script-name 即可运行.

script-name.x.c是生成script-name.x的原文件(c语言)

 

方法二:gzexe

系统自带,无需安装。
使用如下命令加密:
gzexe tesh.sh
加密完成后,test.sh即加密后的文件,同时源文件备份为test.sh~。
加密同时会压缩文件
加密功能比较弱,只能满足一般需求。
可能会有风险,即加密后脚本不能正常执行。下面测试结果表面加密后的文件可以运行。

# cat test.sh 
#!/bin/bash
echo "This is a test script of gzexe"
# sh test.sh 
This is a test script of gzexe
# gzexe test.sh 
test.sh:          0.0%
# ls -la
total 32
drwx------  2 root root 4096 Dec  2 21:29 .
drwxr-xr-x 13 root root 4096 Jun 28  2019 ..
-rw-r--r--  1 root root  877 Dec  2 21:29 test.sh
-rw-r--r--  1 root root   50 Dec  2 21:29 test.sh~
# cat test.sh~
#!/bin/bash
echo "This is a test script of gzexe"
# cat test.sh
#!/bin/sh
skip=44

tab=   
nl=‘
‘
IFS=" $tab$nl"

umask=`umask`
umask 77

gztmpdir=
trap res=$?
  test -n "$gztmpdir" && rm -fr "$gztmpdir"
  (exit $res); exit $res
 0 1 2 3 5 10 13 15

if type mktemp >/dev/null 2>&1; then
  gztmpdir=`mktemp -dt`
else
  gztmpdir=/tmp/gztmp$$; mkdir $gztmpdir
fi || { (exit 127); exit 127; }

gztmp=$gztmpdir/$0
case $0 in
-* | */*‘
‘) mkdir -p "$gztmp" && rm -r "$gztmp";;
*/*) gztmp=$gztmpdir/`basename "$0"`;;
esac || { (exit 127); exit 127; }

case `echo X | tail -n +1 2>/dev/null` in
X) tail_n=-n;;
*) tail_n=;;
esac
if tail $tail_n +$skip <"$0" | gzip -cd > "$gztmp"; then
  umask $umask
  chmod 700 "$gztmp"
  (sleep 5; rm -fr "$gztmpdir") 2>/dev/null &
  "$gztmp" ${1+"$@"}; res=$?
else
  echo >&2 "Cannot decompress $0"
  (exit 127); res=127
fi; exit $res
?–?_test.shSV?OêìóOJ,?àJM?èWP
éè,V¢D…’?a…a?¢ì?…ü4…?a??T%.?úJY2# 
# 
# sh test.sh
This is a test script of gzexe
# 

 

 

SHELL脚本加密工具shc和gzexe

上一篇:Linux用户及组相关文件介绍


下一篇:一、Linux开山篇