1. 程式人生 > 其它 >shell指令碼加密工具

shell指令碼加密工具

前奏

Linux下的shell指令碼用途廣泛,經常包含IP、Pwd等關鍵資訊,可讀可寫的特點很容易造成資訊洩露,導致嚴重後果。基於這些原因,對指令碼實施加密便變得很有必要
shc是一個加密shell指令碼的工具.它的作用是把shell指令碼轉換為一個可執行的二進位制檔案.


應用場景
用shell指令碼對系統進行自動化維護,簡單,便捷而且可移植性好.但shell指令碼是可讀寫的,很有可能會洩露敏感資訊,如使用者名稱,密碼,路徑,IP等.
對於指令碼中含有一些敏感資訊的,通常我們都想做成二進位制程式,不讓使用者看到原始碼,對於有這種需求的通常我們一般採用shc或者gzexe,推薦shc

shc安裝和使用

# 安裝
yum -y install epel-release
yum -y install shc 
或者
apt install -y shc


# 使用
~]# vim test.sh
#!/bin/bash -
echo "this is shc test"


~]# bash test.sh 
this is shc test


# 注:要有-r選項, -f後跟要加密的指令碼名
~]# shc -rvf test.sh             
~]# ll
-rw-r--r--. 1 root root    38 3月  10 08:16 test.sh            ===> 原始檔
-rwxrwxr-x. 1 root root 11136 3月  10 08:16 test.sh.x          ===> 加密後二進位制檔案
-rw-r--r--. 1 root root 17660 3月  10 08:16 test.sh.x.c        ===> 指令碼對應的C語言版本原始碼

# 執行一下加密後文件
~]# ./test.sh.x 
this is shc test

~]# mv test.sh{,-bak}
~]# mv test.sh.x test.sh
~]# ./test.sh 
this is shc test

shc解密(測試的有問題,不過作者在README.md中也有寫明原因)

I will not decrypt any file for people.
Issues on GitHub are only to discuss about bug and/or improvement of the tool "UnSHc".

# https://github.com/yanncam/UnSHc/
# 支援x86、mips、arm架構CPU

x86版本
[email protected]:yanncam/UnSHc.git
unshc-arm版本
https://github.com/cliffalbert/UnSHc-arm



~]# git clone --depth=1 [email protected]:yanncam/UnSHc.git
~]# cd UnSHc/latest/
latest]# ./unshc.sh ~/test.sh  -o test.sh
 _   _       _____ _   _      
| | | |     /  ___| | | |     
| | | |_ __ \ `--.| |_| | ___ 
| | | | '_ \ `--. \  _  |/ __|
| |_| | | | /\__/ / | | | (__ 
 \___/|_| |_\____/\_| |_/\___|

--- UnSHc - The shc decrypter.
--- Version: 0.8
------------------------------
UnSHc is used to decrypt script encrypted with SHc
Original idea from Luiz Octavio Duarte (LOD)
Updated and modernized by Yann CAM
- SHc   : [http://www.datsi.fi.upm.es/~frosal/]
- UnSHc : [https://www.asafety.fr/unshc-the-shc-decrypter/]
------------------------------

[*] Input file name to decrypt [/root/test.sh]
[+] Output file name specified [test.sh]
[-] Unable to define arc4() call address...             =====> 報錯

gzexe加密與解密shell指令碼

gzexe支援bash a.sh 和 ./a.sh,但shc只支援./a.sh這種方式執行

~]# vim test.sh
#!/bin/bash
echo "this is shc test"


~]# gzexe test.sh
test.sh:	  0.0%


~]# ll test.sh*
-rw-r--r--. 1 root root 865 3月  10 09:25 test.sh       ===> 壓縮後的二進位制檔案
-rw-r--r--. 1 root root  38 3月  10 09:24 test.sh~      ===> 原檔案


~]# bash test.sh
this is shc test

歡迎加入QQ群一起討論Linux、開源等技術