博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
对shell脚本进行加密
阅读量:6947 次
发布时间:2019-06-27

本文共 1997 字,大约阅读时间需要 6 分钟。

用shell脚本对系统进行自动化维护,简单,便捷而且可移植性好.

但shell脚本是可读写的,很有可能会泄露敏感信息,如用户名,密码,路径,IP等.
同样,在shell脚本运行时会也泄露敏感信息.
请问如何不影响脚本运行的前提下,对脚本进行加密?

一、shc方法

shc是一个加密shell脚本的工具.它的作用是把shell脚本转换为一个可执行的二进制文件,这就很好的解决了上述问题.

yum安装:

yum -y install shc

编译安装:

wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.7.tgztar xvfz shc-3.8.7.tgzcd shc-3.8.7make
验证shc是否正确安装
[root@martin shc-3.8.7]# ./shc -vshc parse(-f): No source file specifiedshc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script

创建一个示例Shell脚本

[root@martin shc-3.8.7]# vi random.sh#!/bin/bashread -p "How many random numbers do you want to generate?" maxfor (( start = 1; start <= $max; start++ ))do  echo -e $RANDOMdone

给脚本增加可执行权限

[root@martin shc-3.8.7]# chmod u+x random.sh

执行示例脚本

[root@martin shc-3.8.7]# ./random.shHow many random numbers do you want to generate?31423595557671

使用shc加密Shell脚本

[root@martin shc-3.8.7]# ./shc -v -r -T -f random.shshc shll=bashshc [-i]=-cshc [-x]=exec '%s' "$@"shc [-l]=shc opts=shc: cc  random.sh.x.c -o random.sh.xshc: strip random.sh.xshc: chmod go-r random.sh.x

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

script-name.x是加密后的可执行的二进制文件
script-name.x.c是生成script-name.x的原文件(c语言)

[root@martin shc-3.8.7]# ll random.sh*-rwxr-xr-x 1 root root   146 Aug  2 10:26 random.sh-rwx--x--x 1 root root  9424 Aug  2 10:30 random.sh.x-rw-r--r-- 1 root root 10080 Aug  2 10:30 random.sh.x.c

执行加密后的脚本

[root@martin shc-3.8.7]# ./random.sh.x How many random numbers do you want to generate?3289552148729513

还不完善,只能全路径执行shc命令或者进入目录内,加入全局环境变量/etc/profile未生效

二、gzexe

它是使用系统自带的gzexe程序,它不但加密,同时压缩文件

这种加密方式不是非常保险的方法,但是能够满足一般的加密用途,可以隐蔽脚本中的密码等信息。

使用方法:

[root@martin home]# gzexe random.sh random.sh:     20.5%
[root@martin home]# ll random.sh*-rwxr-xr-x 1 root root 953 Aug  2 10:45 random.sh-rwxr-xr-x 1 root root 146 Aug  2 10:45 random.sh~

它会把原来没有加密的文件备份为 file.sh~ ,同时 file.sh 即被变成加密文件

参考地址:

http://lidao.blog.51cto.com/3388056/1914205

https://yq.aliyun.com/ziliao/65848

 

转载于:https://www.cnblogs.com/jmaly/p/7272680.html

你可能感兴趣的文章
java多线程知识点汇总(四)多线程知识点脉络图
查看>>
nginx的upstream目前支持5种方式的分配
查看>>
android图像处理(3) 底片效果
查看>>
stl 之set图解
查看>>
4.自定义数据《jquery实战》
查看>>
HDU 3569 Imaginary Date 简单期望
查看>>
iOS开发之地域选择
查看>>
activity
查看>>
ROS+nfdump 用户上网日志
查看>>
CSDN日报20170411 ——《怎样给自己的私活项目标价》
查看>>
(转)背包9讲
查看>>
Linux_window与linux之间文件互传,上传下载
查看>>
GDB调试——常用的命令
查看>>
Disruptor多个消费者不重复处理生产者发送过来的消息
查看>>
vuejs_01项目启动
查看>>
[LeetCode] Candy Crush 糖果消消乐
查看>>
04.变量和常量
查看>>
图像采集调试总结
查看>>
iOS适配HTTPS,创建一个自签名的SSL证书(x509)具体步骤
查看>>
1111111
查看>>