shell加密工具shc的安裝和使用



1)工具說明

  shell腳本是可讀寫的, 很有可能會泄露敏感信息, 如用戶名/密碼/路徑/IP等. 同樣在shell腳本運行時會也泄露敏感信息. shc是一個加密shell腳本的工具, 它的作用是把shell腳本轉換爲一個可執行的二進制文件. 這就很好的解決了上述問題.



2)下載安裝

  下載: http://www.datsi.fi.upm.es/~frosal/

 安裝:


  # tar xf shc-3.8.9.tgz

  # make test

  # make strings

  # make install

   ***     Installing shc and shc.1 on /usr/local

   ***     Do you want to continue? <輸入y>

   install -c -s shc /usr/local/bin/

   install -c -m 644 shc.1 /usr/local/man/man1/

  # 

 用法:

  # which shc //查找程序在哪,也可以用“whereis shc”。

   /usr/local/bin/shc

  # shc //查看幫助可以用shc -h或shc --help,不過參數錯的話,程序會自動把使用說明能你,不過不全。

   shc parse(-f): No source file specified

   shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script


3) 加密腳本

  # shc -v -f test.sh //“加密”文件“test.sh”。

      -v是verbose模式, 輸出更詳細編譯日誌; 

      -f 指定腳本的名稱.

  $ ll test* //查看文件詳細信息,這個命令的原型是“ls -l”。

   -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”的文件類型

   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, 注意生成的二進制文件因爲是動態鏈接形式, 所以在其它平臺上不能運行.


4) 生成靜態鏈接的二進制可執行文件

  可以通過下面的方法生成一個靜態鏈接的二進制可執行文件:

  $ CFLAGS=-static shc -r -f test.sh

  $ file testup.sh.x


5) 通過sch加密後的腳本文件很安全嗎?

  一般來說是安全的, 不過可以使用gdb和其它的調試工具獲得最初的源代碼. 如果需要更加安全的方法, 可以考慮使用wzshSDK. 另外shc還可以設置腳本的運行期限和自定義返回信息:


  $ shc -e 09/05/2010 -m "the mysql backup scrīpt is now out of date." -f test.sh

      -e表示腳本將在2010年9月5日前失效, 並根據-m定義的信息返回給終端用戶.

  說明:關於MySQL可以參考我的“MySQL管理”中的備份操作或者“Crontab”文末的備份腳本例子。


補充:Win下轉爲二進制並且可以在命令行下執行的工具名爲“bat2exe”。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章