Linux的Shell脚本加密
如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033
相关问题:
1.linux脚本加密
2.脚本二进制化
3.同架构跨操作系统二进制脚本
相关文章:
glibc-static安装
Linux Shell
前言
Linux Shell脚本简单,易用,功能强大。但是,由于其基于类似文本的编写方式,导致其容易泄露敏感信息。因此,对于Shell脚本的加密也是一个重要的需求。
本文将介绍一款Shell加密工具Shc。它可以用来对shell脚本进行加密,可以将shell脚本转换为一个可执行的二进制文件。
1.Shc的安装
官网 : https://neurobin.org/projects/softwares/unix/shc/
Github : https://github.com/neurobin/shc
源码编译:
./configure
make
sudo make install
2.Shc参数简介
2.1 常用参数
- -f %s 需要编译的脚本文件名称
- -o %s 输出文件名称
- -r 宽松的安全性,可以制作可发行的二进制。
同架构不同操作系统运行需要使用该参数
- -e %s dd/mm/yyyy格式的脚本过期日期
- -m %s 过期之后显示的信息
- -v 显示编译详细过程
2.2 详细参数
$ shc -h
shc Version 4.0.3, Generic Shell Script Compiler
shc GNU GPL Version 3 Md Jahidul Hamid <jahidulhamid@yahoo.com>
shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-o outfile] [-rvDSUHCABh] -f script
-e %s Expiration date in dd/mm/yyyy format [none]
-m %s Message to display upon expiration ["Please contact your provider"]
-f %s File name of the script to compile
-i %s Inline option for the shell interpreter i.e: -e
-x %s eXec command, as a printf format i.e: exec('%s',@ARGV);
-l %s Last shell option i.e: --
-o %s output filename
-r Relax security. Make a redistributable binary
-v Verbose compilation
-S Switch ON setuid for root callable programs [OFF]
-D Switch ON debug exec calls [OFF]
-U Make binary untraceable [no]
-H Hardening : extra security protection [no]
Require bourne shell (sh) and parameters are not supported
-C Display license and exit
-A Display abstract and exit
-B Compile for busybox
-h Display help and exit
Environment variables used:
Name Default Usage
CC cc C compiler command
CFLAGS <none> C compiler flags
LDFLAGS <none> Linker flags
Please consult the shc man page.
3.Shc的使用
示例文件 a.sh
#!/bin/bash
echo 'hello'
3.1 编译为二进制
shc -f a.sh
3.2 编译为二进制,并重命名输出文件
shc -f a.sh -o a.bin
3.3 设置时间限制
shc -f a.sh -e 04/02/2020 -m '过期了'
3.4 跨操作系统静态编译,并重命名输出文件
CFLAGS=-static shc -r -f a.sh -o a.bin
注意: -r参数对于同架构不同操作系统的运行很重要
查看静态二进制信息
$ file a.bin
a.bin: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=4064d60d8ae7a4ab39daa93fc62cf4f8f17d55da, stripped
$ ldd a.bin
不是动态可执行文件
4.其他
4.1 cannot find -lc
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
shc: Success
安装glic-static(libc.a)即可
4.2 反编译为Shell脚本
https://github.com/yanncam/UnSHc
License
License under CC BY-NC-ND 4.0: 署名-非商业使用-禁止演绎
Reference:
NULL