c语言加密shell脚本,shell脚本加密
如何保護自己編寫的shell程序
要保護自己編寫的shell腳本程序,方法有很多,最簡單的方法有兩種:1、加密 2、設定過期時間,下面以shc工具為例說明:
一、下載安裝shc工具
shc是一個加密shell腳本的工具.它的作用是把shell腳本轉換為一個可執行的二進制文件.
# wget ~frosal/sources/shc-3.8.7.tgz
安裝:
# tar zxvf shc-3.8.7.gz
# cd shc-3.8.7
# mkdir /usr/local/man/man1/ (install時會把man文件放入該目錄,如果該目錄不存在需提前建好) 這一步需要root權限
# make test
# make
# make test
# make strings
# make install?? 這一步需要root權限
二、加密方法:
shc -r -f script-name?? 注意:要有-r選項, -f 后跟要加密的腳本名.
運行后會生成兩個文件,script-name.x 和 script-name.x.c
script-name.x是加密后的可執行的二進制文件.
./script-name 即可運行.
script-name.x.c是生成script-name.x的原文件(c語言)
# shc -v -f test.sh
-v是verbose模式, 輸出更詳細編譯日志;
-f 指定腳本的名稱.
# ll test*
-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
# file test.sh.x
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, 注意生成的二進制文件因為是動態鏈接形式, 所以在其它平臺上不能運行.
生成靜態鏈接的二進制可執行文件
可以通過下面的方法生成一個靜態鏈接的二進制可執行文件:
$ CFLAGS=-static shc -r -f test.sh
$ file testup.sh.x
三. 通過sch加密后的腳本文件很安全嗎?
一般來說是安全的, 不過可以使用gdb和其它的調試工具獲得最初的源代碼. 如果需要更加安全的方法, 可以考慮使用wzshSDK. 另外shc還可以設置腳本的運行期限和自定義返回信息:
$ shc -e 03/31/2007 -m "the mysql backup scrīpt is now out of date." -f test.sh
-e表示腳本將在2007年3月31日前失效, 并根據-m定義的信息返回給終端用戶.
題外:
如果你僅僅是看不見內容就行了的話,不妨用
gzexe a.sh
原來的 a.sh 就被存為 a.sh~,新的 a.sh 是亂碼,但是可以用 sh 的方式運行
閱讀(2025) | 評論(0) | 轉發(4) |
總結
以上是生活随笔為你收集整理的c语言加密shell脚本,shell脚本加密的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 九宫格封装,Androi
- 下一篇: android 获取蓝牙设备id_【报B