shc简介

shc,全称 shell script compiler,可以将shell脚本编译为二进制可执行文件,从而达到隐藏源代码的目的

shc的工作过程分为两步:

  • 将shell脚本转化为C语言源码
  • 将C语言源码进行编译链接得到二进制文件

shc网站

安装方式

sudo apt-get install shc

使用

vim hello.sh

写入:

#!/bin/bash
echo "hello,world~"
$ shc -f hello.sh

$ ls
hello.sh  hello.sh.x  hello.sh.x.c
  • hello.sh是我们最初编辑的sh脚本
  • hello.sh.x是可执行文件
  • hello.sh.x.c是hello.sh转化的C语言文件

运行测试:

  • 先用hello.sh.x
  • 再用hello.sh.x.c编译为二进制文件
  • 两次结果相同都是hello,world~
$ ./hello.sh.x
hello,world~

$ gcc -static hello.sh.x.c
$ ./a.out
hello,world~

参数&环境

OPTIONS
       -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 path of the script to compile

       -i inline_option : Inline option for the shell interpreter i.e: -e

       -x command : eXec command, as a printf format i.e: exec(\\'%s\\',@ARGV);

       -l last_option : Last shell option i.e: --

       -o outfile : output to the file specified by outfile

       -r : Relax security.  Make a redistributable binary which executes on different systems running the same operating system.  You can release your binary
       with this option for others to use

       -v : Verbose compilation

       -S : Switch ON setuid for root callable programs [OFF]

       -D : Switch on debug exec calls

       -U : Make binary to be untraceable (using strace, ptrace, truss, etc.)

       -H : Hardening.  Extra security flag without root access requirement that protects against  dumping,  code  injection,  cat /proc/pid/cmdline,  ptrace,
       etc..  This feature is experimental and may not work on all systems.  it require bourne shell (sh) scripts any positional parameters.

       -C : Display license and exit

       -A : Display abstract and exit

       -B : Compile for BusyBox

       -h : Display help and exit

ENVIRONMENT VARIABLES
       CC : C compiler command [cc]

       CFLAGS : C compiler flags [none]

       LDFLAGS : Linker flags [none]

EXAMPLES
       Compile a script which can be run on other systems with the trace option enabled (without -U flag):

              shc -f myscript -o mybinary

       Compile an untraceable binary:

              shc -Uf myscript -o mybinary

       Compile an untraceable binary that doesn't require root access (experimental):

              shc -Hf myscript -o mybinary
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐