Linux的Shell腳本加密

Linux的Shell腳本加密


如需轉載請標明出處:http://blog.csdn.net/itas109
QQ技術交流羣:129518033

相關問題:
1.linux腳本加密
2.腳本二進制化
3.同架構跨操作系統二進制腳本

相關文章:
glibc-static安裝
Linux Shell


前言

Linux Shell腳本簡單,易用,功能強大。但是,由於其基於類似文本的編寫方式,導致其容易泄露敏感信息。因此,對於Shell腳本的加密也是一個重要的需求。

本文將介紹一款Shell加密工具Shc。它可以用來對shell腳本進行加密,可以將shell腳本轉換爲一個可執行的二進制文件。

1.Shc的安裝

官網 : https://neurobin.org/projects/softwares/unix/shc/

Github : https://github.com/neurobin/shc

源碼編譯:

./configure
make
sudo make install

2.Shc參數簡介

2.1 常用參數

  • -f %s 需要編譯的腳本文件名稱
  • -o %s 輸出文件名稱
  • -r 寬鬆的安全性,可以製作可發行的二進制。同架構不同操作系統運行需要使用該參數
  • -e %s dd/mm/yyyy格式的腳本過期日期
  • -m %s 過期之後顯示的信息
  • -v 顯示編譯詳細過程

2.2 詳細參數

$ shc -h

shc Version 4.0.3, Generic Shell Script Compiler
shc GNU GPL Version 3 Md Jahidul Hamid <[email protected]>
shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-o outfile] [-rvDSUHCABh] -f script

    -e %s  Expiration date in dd/mm/yyyy format [none]
    -m %s  Message to display upon expiration ["Please contact your provider"]
    -f %s  File name of the script to compile
    -i %s  Inline option for the shell interpreter i.e: -e
    -x %s  eXec command, as a printf format i.e: exec('%s',@ARGV);
    -l %s  Last shell option i.e: --
    -o %s  output filename
    -r     Relax security. Make a redistributable binary
    -v     Verbose compilation
    -S     Switch ON setuid for root callable programs [OFF]
    -D     Switch ON debug exec calls [OFF]
    -U     Make binary untraceable [no]
    -H     Hardening : extra security protection [no]
           Require bourne shell (sh) and parameters are not supported
    -C     Display license and exit
    -A     Display abstract and exit
    -B     Compile for busybox
    -h     Display help and exit

    Environment variables used:
    Name    Default  Usage
    CC      cc       C compiler command
    CFLAGS  <none>   C compiler flags
    LDFLAGS <none>   Linker flags

    Please consult the shc man page.

3.Shc的使用

示例文件 a.sh

#!/bin/bash

echo 'hello'

3.1 編譯爲二進制

shc -f a.sh

3.2 編譯爲二進制,並重命名輸出文件

shc -f a.sh  -o a.bin

3.3 設置時間限制

shc -f a.sh -e 04/02/2020 -m '過期了'

3.4 跨操作系統靜態編譯,並重命名輸出文件

CFLAGS=-static shc -r -f a.sh -o a.bin

注意: -r參數對於同架構不同操作系統的運行很重要

查看靜態二進制信息

$ file a.bin 

a.bin: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=4064d60d8ae7a4ab39daa93fc62cf4f8f17d55da, stripped
$ ldd a.bin 
	不是動態可執行文件

4.其他

4.1 cannot find -lc

/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
shc: Success

安裝glic-static(libc.a)即可

4.2 反編譯爲Shell腳本

https://github.com/yanncam/UnSHc


License

License under CC BY-NC-ND 4.0: 署名-非商業使用-禁止演繹


Reference:
NULL

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