A generic shell script compiler. Shc takes a script, which is specified on the command line and produces C source code. The generated source code is then compiled and linked to produce a stripped binary executable.
The compiled binary will still be dependent on the shell specified in the first line of the shell code (i.e shebang) (i.e. #!/bin/sh), thus shc does not create completely independent binaries.
shc itself is not a compiler such as cc, it rather encodes and encrypts a shell script and generates C source code with the added expiration capability. It then uses the system compiler to compile a stripped binary which behaves exactly like the original script. Upon execution, the compiled binary will decrypt and execute the code with the shell -c option.
- ./configure
- make
- sudo make install
Note If make
fails due to automake version, run ./autogen.sh
before running the above commands.
sudo add-apt-repository ppa:neurobin/ppa
sudo apt-get update
sudo apt-get install shc
If the above installation method seems like too much work, then just download a compiled binary package from release page and copy the shc
binary to /usr/bin
and shc.1
file to /usr/share/man/man1
.
shc [options]
shc -f script.sh -o binary
shc -U -f script.sh -o binary # Untraceable binary (prevent strace, ptrace etc..)
shc -H -f script.sh -o binary # Untraceable binary, does not require root (only bourne shell (sh) scripts with no parameter)
shc -H -s -f script.sh -o binary # Untraceable binary running in a singe process, does not require root (only bourne shell (sh) scripts with no parameter)
cd
totest
directory:cd test
- Try:
shc -f test.bash -o test
, where test.bash is the bash source. - output binary file will be test. If no output file is specified
by the
-o
option, then it will create an executable with.x
extension by default.
The one (and I hope the only) limitation using shc is the _SC_ARG_MAX system configuration parameter. It limits the maximum length of the arguments to the exec function, limiting the maximum length of the runnable script of shc.
!! - CHECK YOUR RESULTS CAREFULLY BEFORE USING - !!
If you want to make pull requests, please do so against the master branch. The default branch is release which should contain clean package files ready to be used.
If you want to edit the manual, please edit the man.md file (available in the master branch) instead and then generate the manual file from it with the command (requires pandoc
to be installed):
pandoc -s man.md -t man -o shc.1
#also run this command to generate the html manual
pandoc -s man.md -t html -o man.html
If you change anything related to autotools, please run ./autogen.sh
afterwards.