1[![build status image](https://travis-ci.org/neurobin/shc.svg?branch=release)](https://travis-ci.org/neurobin/shc) 2[![GitHub stars](https://img.shields.io/github/stars/neurobin/shc.svg)](https://github.com/neurobin/shc/stargazers) 3[![GitHub forks](https://img.shields.io/github/forks/neurobin/shc.svg)](https://github.com/neurobin/shc/network) 4[![GitHub issues](https://img.shields.io/github/issues/neurobin/shc.svg)](https://github.com/neurobin/shc/issues) 5 6# Shell Script Compiler 7 8A 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. 9 10The 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. 11 12shc 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. 13 14## Install 15 16```bash 17./configure 18make 19sudo make install 20``` 21 22**Note** If `make` fails due to *automake* version, run `./autogen.sh` before running the above commands. 23 24### Ubuntu-specific 25 26``` 27sudo add-apt-repository ppa:neurobin/ppa 28sudo apt-get update 29sudo apt-get install shc 30``` 31 32If the above installation method seems like too much work, then just download a compiled binary package from [release page](https://github.com/neurobin/shc/releases/latest) and copy the `shc` binary to `/usr/bin` and `shc.1` file to `/usr/share/man/man1`. 33 34## Usage 35 36``` 37shc [options] 38shc -f script.sh -o binary 39shc -U -f script.sh -o binary # Untraceable binary (prevent strace, ptrace etc..) 40shc -H -f script.sh -o binary # Untraceable binary, does not require root (only bourne shell (sh) scripts with no parameter) 41``` 42 43## The hardening flag -H 44 45This flag is currently in an experimental state and may not work in all systems. This flag only works for **default** shell. For example, if you compile a **bash** script with `-H` flag then the resultant executable will only work in systems where the default shell is **bash**. You may change the default shell which generally is `/bin/sh` which further is just a link to another shell like bash or dash etc. 46 47**Also `-H` does not work with positional parameters (yet)** 48 49## Testing 50 51```bash 52./configure 53make 54make check 55``` 56 57## Known limitations 58 59The one (and I hope the only) limitation using shc is the _SC_ARG_MAX system configuration parameter. 60It limits the maximum length of the arguments to the exec function, limiting the maximum length of the runnable script of shc. 61 62!! - CHECK YOUR RESULTS CAREFULLY BEFORE USING - !! 63 64## Links 65 661. [Man Page](http://neurobin.github.io/shc/man.html) 672. [Web Page](http://neurobin.github.io/shc) 68 69# Contributing 70 71If 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. 72 73If 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): 74 75```bash 76pandoc -s man.md -t man -o shc.1 77#also run this command to generate the html manual 78pandoc -s man.md -t html -o man.html 79``` 80 81If you change anything related to autotools, please run `./autogen.sh` afterwards. 82