shell 脚本加密
想想好久没更新博客了,今天在群里看到讨论关于shell脚本加密的事情。
想想也是,我们在写脚本有时候会配置相关账号和密码的事情,这样只要能权限都能看到该信息,非常的不安全,有没有在正常运行的情况下对文件进行加密。大致有以下两个特点:
加密文件,防止别人看到我写的具体内容。
可以对隐藏敏感性知识点,比如脚本涉及到用户和密码,如mysql
我特意搜了一下,有两种方法,涨知识了,所以验证了一下,过程如下:
第一种方法(gzexe):基于ubuntu14.04
这种加密方式不是非常保险的方法,但是能够满足一般的加密用途。它是使用系统自带的gzexe程序,它不但加密,同时压缩文件。
使用方法: gzexe file.sh 它会把原来没有加密的文件备份为 xx.sh~ ,同时 xx.sh 即被变成加密文件
root@leco:~/test# ls test.sh root@leco:~/test# cat test.sh #!/bin/bash echo `date` root@loocha50:~/test# sh test.sh Mon Jul 17 15:08:01 HKT 2017 root@loocha50:~/test# gzexe test.sh test.sh: 25.0% root@loocha50:~/test# ls test.sh test.sh~ root@loocha50:~/test# sh test.sh Mon Jul 17 15:08:14 HKT 2017 root@loocha50:~/test# sh test.sh~ Mon Jul 17 15:08:18 HKT 2017 root@loocha50:~/test# cat test.sh~ #!/bin/bash echo `date` root@loocha50:~/test# cat test.sh #!/bin/bash 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; thengztmpdir=`mktemp -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); res=127 fi; exit $res
此时我们可以看出test.sh 文件已经被加密了,但是不影响运行。此时你删除test.sh~ 文件,别人就彻底看不到了(自己也看不到,请酌情删除)。
root@leco:~/test# ls test.sh test.sh~ root@leco:~/test# rm test.sh~ root@leco:~/test# ls test.sh root@leco:~/test# sh test.sh Mon Jul 17 15:10:36 HKT 2017
建议使用,一方面系统自带命令,达到目的即可,没人闲的破解你的脚本,就算要破解,先进入你系统再说。
我基于centos6.8 (ubuntu14.04有问题,没具体排查)
方法2: shc
shc 常用参数
-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/
[root@leco ~]# 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] [root@leco ~]# tar xf shc-3.8.6.tgz [root@leco ~]# mkdir -p /usr/local/man/man1
这步是必须的,不然安装过程中会报错,shc将安装命令到/usr/local/bin/目录下;
将帮助文档存放在/usr/local/man/man1/目录下,如果系统中无此目录,安装时会报错,可创建此目录后再执行安装。
[root@leco ~]# cd shc-3.8.6 [root@leco 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 [root@leco test]# cat test.sh #!/bin/bash echo `date` [root@leco 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 [root@leco 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
shell 脚本加密相关推荐
- shc加密(仅仅对shell脚本加密)
shc加密(仅仅对shell脚本加密) shc是一个专业的加密shell脚本的工具.它的作用是把shell脚本转换为一个可执行的二进制文件,这个办法很好的解决了脚本中含有IP. 密码等不希望公开的问题 ...
- Linux的Shell脚本加密
Linux的Shell脚本加密 如需转载请标明出处:http://blog.csdn.net/itas109 QQ技术交流群:129518033 文章目录 Linux的Shell脚本加密 @[toc] ...
- linux shc shell脚本_详解shell脚本加密解密软件—gzese和shc
概述 以我个人的需求为例,有时写一个脚本需要传密码,如果直接把密码写在脚本里会存在安全问题,一般是把密码写在脚本里,作为参数传给脚本,而保存密码的脚本,使用某种手段加密,令其不可读但是可执行.而常用的 ...
- c语言加密shell脚本,shell脚本加密
如何保护自己编写的shell程序 要保护自己编写的shell脚本程序,方法有很多,最简单的方法有两种:1.加密 2.设定过期时间,下面以shc工具为例说明: 一.下载安装shc工具 shc是一个加密s ...
- Shell脚本加密方法大全及案例演示
一.加密原因 当我们正式线上开发环境是基于Linux开发时,通常必不可少的就是shell脚本的编写. shell脚本的好处众多,可对系统进行自动化维护,简单,快捷而且可移植性强. 存在问题: 但是sh ...
- linux脚本解密,给shell脚本加密和解密的shell脚本
加密脚本内容: #!/bin/bash while read line;do echo $line|tr [a-m][n-z][A-M][N-Z][0-4][5-9] [n-z][a-m][N-Z][ ...
- shell实例第18讲:利用gzexe加密shell脚本
利用gzexe加密shell脚本 gzexe_test.sh内容如下: #!/bin/bashecho "gzexe test!" 结果: 使用gzexe加密shell脚本命令:g ...
- linux 脚本加密,Shell脚本的4种加密详细教程
这篇文章上次修改于 1159 天前,可能其部分内容已经发生变化,如有疑问可询问作者. 普及,shell脚本是什么? Shell Script,Shell脚本与Windows/Dos下的批处理相似,也就 ...
- Openldap配置TLS加密传输(完整版——shell脚本实现[即在客户端执行代码,即可实现TLS加密])
此脚本中只是负责实现了TLS加密配置部分,openLDAP的编译安装以及设置是前期已经配置好的! 具体的配置看上上篇文章openLDAP的编译安装以及配置. 注意slapd.conf中的配置,脚本中为 ...
最新文章
- com.android.phone已停止 vivo,oppo,vivo应用程序终止通知不在android fcm中出...
- IntelliJ IDEA 问题总结之中的一个 —— jar包、assets、maven、git
- 解读Java Class文件格式
- Mato的文件管理 (莫队)题解
- 21上海省赛 F-鸡哥的限币令
- java 日期函数转换_java 日期函数转换
- cv2.error: opencv(4.4.0)_【从零学习OpenCV 4】轮廓面积与长度
- Adobe应用网络体验管理解决方案
- ppt手动放映怎么设置_一键解决PPT的动画播放和动画排序问题!
- [openjudge6043]哆啦A梦的时光机
- 计算机音乐植物大战僵尸泳池,植物大战僵尸(泳池)
- android 15 activity跳转
- [转] Js获取 本周、本月、本季度、本年、上月、上周、上季度、去年时间段
- 必刷2022年辽宁最新消防设施操作员模拟题库及答案
- Delphi下使用并口控制打印机的方法
- Java: Hook技术
- 计算机组装图与名称,台式电脑组装硬件配置名称
- matlab对角替换,matlab矩阵对角最大化实现
- STC15单片机内部RAM讲解
- 就是要弄懂你之—— 同步 异步 阻塞 非阻塞