外贸网站制作广州,2020广东黄页,莱芜房产网新房,国外免费域名申请想想好久没更新博客了#xff0c;今天在群里看到讨论关于shell脚本加密的事情。想想也是#xff0c;我们在写脚本有时候会配置相关账号和密码的事情#xff0c;这样只要能权限都能看到该信息#xff0c;非常的不安全#xff0c;有没有在正常运行的情况下对文件进行加密。大… 想想好久没更新博客了今天在群里看到讨论关于shell脚本加密的事情。 想想也是我们在写脚本有时候会配置相关账号和密码的事情这样只要能权限都能看到该信息非常的不安全有没有在正常运行的情况下对文件进行加密。大致有以下两个特点加密文件防止别人看到我写的具体内容。可以对隐藏敏感性知识点比如脚本涉及到用户和密码如mysql我特意搜了一下有两种方法涨知识了所以验证了一下过程如下:第一种方法(gzexe)基于ubuntu14.04 这种加密方式不是非常保险的方法但是能够满足一般的加密用途。它是使用系统自带的gzexe程序它不但加密同时压缩文件。使用方法: gzexe file.sh 它会把原来没有加密的文件备份为 xx.sh~ ,同时 xx.sh 即被变成加密文件rootleco:~/test# ls
test.sh
rootleco:~/test# cat test.sh
#!/bin/bash
echo date
rootloocha50:~/test# sh test.sh
Mon Jul 17 15:08:01 HKT 2017
rootloocha50:~/test# gzexe test.sh
test.sh: 25.0%
rootloocha50:~/test# ls
test.sh test.sh~
rootloocha50:~/test# sh test.sh
Mon Jul 17 15:08:14 HKT 2017
rootloocha50:~/test# sh test.sh~
Mon Jul 17 15:08:18 HKT 2017
rootloocha50:~/test# cat test.sh~
#!/bin/bash
echo date
rootloocha50:~/test# cat test.sh
#!/bin/bash
skip44
tab
nlIFS $tab$nl
umaskumask
umask 77
gztmpdir
trap res$?test -n $gztmpdir rm -fr $gztmpdir(exit $res); exit $res0 1 2 3 5 10 13 15
if type mktemp /dev/null 21; thengztmpdirmktemp -dt
elsegztmpdir/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; thenumask $umaskchmod 700 $gztmp(sleep 5; rm -fr $gztmpdir) 2/dev/null $gztmp ${1$}; res$?
elseecho 2 Cannot decompress $0(exit 127); res127
fi; exit $res此时我们可以看出test.sh 文件已经被加密了但是不影响运行。此时你删除test.sh~ 文件别人就彻底看不到了(自己也看不到请酌情删除)。rootleco:~/test# ls
test.sh test.sh~
rootleco:~/test# rm test.sh~
rootleco:~/test# ls
test.sh
rootleco:~/test# sh test.sh
Mon Jul 17 15:10:36 HKT 2017建议使用一方面系统自带命令达到目的即可没人闲的破解你的脚本就算要破解先进入你系统再说。我基于centos6.8 (ubuntu14.04有问题没具体排查)方法2 shcshc 常用参数-e date Expiration date in dd/mm/yyyy format [none]指定过期日期-m message message to display upon expiration [Please contact your provider]指定过期提示的信息 -f script_name File name of the script to compile指定要编译的shell的路径及文件名 -r Relax security. Make a redistributable binary which executes on different systems running the same operat-ing system.可以相同操作系统的不同系统中执行 -v Verbose compilation编译的详细情况shc是一个专业的加密shell脚本的工具.它的作用是把shell脚本转换为一个可执行的二进制文件这个办法也很好的解决了脚本中含有IP、密码等不希望公开的问题包下载链接http://www.datsi.fi.upm.es/~frosal/sources/[rootleco ~]# wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.6.tgz
--2017-07-17 15:23:39-- http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.6.tgz
Resolving www.datsi.fi.upm.es... 138.100.9.22
Connecting to www.datsi.fi.upm.es|138.100.9.22|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 35071 (34K) [application/x-gzip]
Saving to: “shc-3.8.6.tgz”
100%[] 35,071 21.9K/s in 1.6s
2017-07-17 15:23:46 (21.9 KB/s) - “shc-3.8.6.tgz” saved [35071/35071]
[rootleco ~]# tar xf shc-3.8.6.tgz
[rootleco ~]# mkdir -p /usr/local/man/man1这步是必须的不然安装过程中会报错shc将安装命令到/usr/local/bin/目录下将帮助文档存放在/usr/local/man/man1/目录下如果系统中无此目录安装时会报错可创建此目录后再执行安装。[rootleco ~]# cd shc-3.8.6
[rootleco shc-3.8.6]# make install
***Installing shc and shc.1 on /usr/local
***Do you want to continue? y #此时等待输入y
install -c -s shc /usr/local/bin/
install -c -m 644 shc.1 /usr/local/man/man1/
使用方法-f
[rootleco test]# cat test.sh
#!/bin/bash
echo date
[rootleco test]# shc -r -f test.sh
test.sh.x.c: In function chkenv:
test.sh.x.c:211: warning: cast from pointer to integer of different size
You have new mail in /var/spool/mail/root
[rootleco test]# ls
test.sh test.sh.x test.sh.x.c
运行后会生成两个文件,xx.x 和 xx.x.c. 其中xx.x是加密后的可执行的二进制文件用./xx.x即可运行xx.x.c是生成xx.x的原文件(c语言).不建议使用需要单独安装管理比较麻烦。如果安全性要求极高倒是可以参数。 转载于:https://blog.51cto.com/caimengzhi/1948227