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版本
git@github.com:yanncam/UnSHc.git
unshc-arm版本
https://github.com/cliffalbert/UnSHc-arm



~]# git clone --depth=1 git@github.com: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群:905201396
不要嫌啰嗦的新手QQ群:756805267
Debian適應QQ群:912567610


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM