日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

shell 脚本加密

發(fā)布時間:2023/12/6 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 shell 脚本加密 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

? ? 想想好久沒更新博客了,今天在群里看到討論關于shell腳本加密的事情。

? ? 想想也是,我們在寫腳本有時候會配置相關賬號和密碼的事情,這樣只要能權限都能看到該信息,非常的不安全,有沒有在正常運行的情況下對文件進行加密。大致有以下兩個特點:

  • 加密文件,防止別人看到我寫的具體內容。

  • 可以對隱藏敏感性知識點,比如腳本涉及到用戶和密碼,如mysql

    我特意搜了一下,有兩種方法,漲知識了,所以驗證了一下,過程如下:


  • 第一種方法(gzexe):基于ubuntu14.04

    ? ? 這種加密方式不是非常保險的方法,但是能夠滿足一般的加密用途。它是使用系統(tǒng)自帶的gzexe程序,它不但加密,同時壓縮文件。

    使用方法: gzexe file.sh 它會把原來沒有加密的文件備份為 xx.sh~ ,同時 xx.sh 即被變成加密文件

    root@leco:~/test#?ls test.sh root@leco:~/test#?cat?test.sh? #!/bin/bash echo?`date` root@loocha50:~/test#?sh?test.sh? Mon?Jul?17?15:08:01?HKT?2017 root@loocha50:~/test#?gzexe??test.sh? test.sh:?25.0% root@loocha50:~/test#?ls test.sh??test.sh~ root@loocha50:~/test#?sh?test.sh Mon?Jul?17?15:08:14?HKT?2017 root@loocha50:~/test#?sh?test.sh~ Mon?Jul?17?15:08:18?HKT?2017 root@loocha50:~/test#?cat?test.sh~ #!/bin/bash echo?`date` root@loocha50:~/test#?cat?test.sh #!/bin/bash skip=44 tab='' nl=' ' IFS="?$tab$nl" umask=`umask` umask?77 gztmpdir= trap?'res=$?test?-n?"$gztmpdir"?&&?rm?-fr?"$gztmpdir"(exit?$res);?exit?$res '?0?1?2?3?5?10?13?15 if?type?mktemp?>/dev/null?2>&1;?thengztmpdir=`mktemp?-dt` elsegztmpdir=/tmp/gztmp$$;?mkdir?$gztmpdir fi?||?{?(exit?127);?exit?127;?} gztmp=$gztmpdir/$0 case?$0?in -*?|?*/*' ')?mkdir?-p?"$gztmp"?&&?rm?-r?"$gztmp";; */*)?gztmp=$gztmpdir/`basename?"$0"`;; esac?||?{?(exit?127);?exit?127;?} case?`echo?X?|?tail?-n?+1?2>/dev/null`?in X)?tail_n=-n;; *)?tail_n=;; esac if?tail?$tail_n?+$skip?<"$0"?|?gzip?-cd?>?"$gztmp";?thenumask?$umaskchmod?700?"$gztmp"(sleep?5;?rm?-fr?"$gztmpdir")?2>/dev/null?&"$gztmp"?${1+"$@"};?res=$? elseecho?>&2?"Cannot?decompress?$0"(exit?127);?res=127 fi;?exit?$res

    此時我們可以看出test.sh 文件已經被加密了,但是不影響運行。此時你刪除test.sh~ 文件,別人就徹底看不到了(自己也看不到,請酌情刪除)。

    root@leco:~/test#?ls test.sh??test.sh~ root@leco:~/test#?rm?test.sh~ root@leco:~/test#?ls test.sh root@leco:~/test#?sh?test.sh? Mon?Jul?17?15:10:36?HKT?2017

    建議使用,一方面系統(tǒng)自帶命令,達到目的即可,沒人閑的破解你的腳本,就算要破解,先進入你系統(tǒng)再說。


    我基于centos6.8 (ubuntu14.04有問題,沒具體排查)

    方法2: shc

    shc 常用參數

    -e date???
    ? Expiration date in dd/mm/yyyy format [none](指定過期日期)


    -m message
    ? message to display? upon? expiration? ["Please? contact your provider"](指定過期提示的信息)
    ?
    -f script_name
    ? File name of the script to compile(指定要編譯的shell的路徑及文件名)
    ?
    -r?? Relax security.?
    ?? Make? a? redistributable? binary? which executes? on different systems running the same operat-ing system.(可以相同操作系統(tǒng)的不同系統(tǒng)中執(zhí)行)
    ?
    -v?? Verbose compilation(編譯的詳細情況)

    shc是一個專業(yè)的加密shell腳本的工具.它的作用是把shell腳本轉換為一個可執(zhí)行的二進制文件,這個辦法也很好的解決了腳本中含有IP、密碼等不希望公開的問題

    包下載鏈接:

    http://www.datsi.fi.upm.es/~frosal/sources/

    [root@leco?~]#?wget?http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.6.tgz --2017-07-17?15:23:39--??http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.6.tgz Resolving?www.datsi.fi.upm.es...?138.100.9.22 Connecting?to?www.datsi.fi.upm.es|138.100.9.22|:80...?connected. HTTP?request?sent,?awaiting?response...?200?OK Length:?35071?(34K)?[application/x-gzip] Saving?to:?“shc-3.8.6.tgz” 100%[=============================================================================================================================>]?35,071??????21.9K/s???in?1.6s???? 2017-07-17?15:23:46?(21.9?KB/s)?-?“shc-3.8.6.tgz”?saved?[35071/35071] [root@leco?~]#?tar?xf?shc-3.8.6.tgz? [root@leco?~]#?mkdir?-p?/usr/local/man/man1

    這步是必須的,不然安裝過程中會報錯,shc將安裝命令到/usr/local/bin/目錄下;

    將幫助文檔存放在/usr/local/man/man1/目錄下,如果系統(tǒng)中無此目錄,安裝時會報錯,可創(chuàng)建此目錄后再執(zhí)行安裝。

    [root@leco?~]#?cd?shc-3.8.6 [root@leco?shc-3.8.6]#?make?install ***Installing?shc?and?shc.1?on?/usr/local ***Do?you?want?to?continue??y??#此時等待輸入y install?-c?-s?shc?/usr/local/bin/ install?-c?-m?644?shc.1?/usr/local/man/man1/ 使用方法:-f? [root@leco?test]#?cat?test.sh #!/bin/bash echo?`date` [root@leco?test]#??shc?-r?-f?test.sh test.sh.x.c:?In?function?'chkenv': test.sh.x.c:211:?warning:?cast?from?pointer?to?integer?of?different?size You?have?new?mail?in?/var/spool/mail/root [root@leco?test]#?ls test.sh??test.sh.x??test.sh.x.c 運行后會生成兩個文件,xx.x?和?xx.x.c.

    ?

    其中xx.x是加密后的可執(zhí)行的二進制文件;用./xx.x即可運行,xx.x.c是生成xx.x的原文件(c語言).

    不建議使用,需要單獨安裝管理,比較麻煩。如果安全性要求極高,倒是可以參數。


    轉載于:https://blog.51cto.com/caimengzhi/1948227

    總結

    以上是生活随笔為你收集整理的shell 脚本加密的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。