shell 腳本寫起來很方便,身為腳本的問題就是保密性不行,寫了什麼內容編輯器一打開看看就知道了, 腳本里面完全不能放用戶名,密碼什麼的, shc 可以解決你的這一部分問題。
安裝shc
* ubuntu
<code>sudo add-apt-repository ppa:neurobin/ppa
sudo apt-get update
sudo apt-get install shc/<code>
* mac(需要使用原生的/usr/bin/strip, brew 安裝的/usr/local/bin/strip會讓程序啟動不了)
<code>brew install shc/<code>
加密腳本
<code>shc -v -f test.sh/<code>
-v是verbose模式, 輸出更詳細編譯日誌;
-f 指定腳本的名稱.
<code> ll test*/<code>
-rwxr-xr-x 1 oracle oinstall 1178 Aug 18 10:00 test.sh
-rwx--x--x 1 oracle oinstall 8984 Aug 18 18:01 test.sh.x
-rw-r--r-- 1 oracle oinstall 14820 Aug 18 18:01 test.sh.x.c
<code> file test.sh.x/<code>
test.sh.x: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), stripped
可以看到生成了動態鏈接可執行二進制文件test.sh.x和C源文件testup.sh.x.c, 注意生成的二進制文件因為是動態鏈接形式, 所以在其它平臺上不能運行.
生成靜態鏈接的二進制可執行文件
可以通過下面的方法生成一個靜態鏈接的二進制可執行文件:
<code>CFLAGs=-static shc -r -f test.sh
file testup.sh.x/<code>
通過sch加密後的腳本的有效時間
一般來說是安全的, 不過可以使用gdb和其它的調試工具獲得最初的源代碼. 如果需要更加安全的方法, 可以考慮使用wzshSDK. 另外shc還可以設置腳本的運行期限和自定義返回信息:
<code>shc -e 03/31/2007 -m "the mysql backup scrīpt is now out of date." -f test.sh/<code>
-e表示腳本將在2007年3月31日前失效, 並根據-m定義的信息返回給終端用戶.
工具地址 :
https://github.com/neurobin/shc
閱讀更多 cheatsheet 的文章