Shc (shell script compiler)
shc is a shell script compiler for Unix-like operating systems written in the C programming language. The Shell Script Compiler encodes and encrypts shell scripts into executable binaries. Compiling shell scripts into binaries provides protection against accidental changes and source code modification, and is a way of hiding shell script source code.
Mechanism
shc takes a shell script which is specified on the command line by the -f option and produces a C source code of the script with added encryption. The generated source code is then compiled and linked to produce a binary executable. It is a two step process where, first, it creates a filename.x.c file of the shell script file filename. Then it is compiled with cc -$CFLAGS filename.x.c to create the binary from the C source code with the default C compiler.The compiled binary will still be dependent on the shell specified in the shebang, thus
shc does not create completely independent binaries.shc itself is not a compiler such as the C compiler, it rather encodes and encrypts a shell script and generates C source code with the added expiration capability. It then uses the system C compiler to compile the source shell script and build a stripped binary which behaves exactly like the original script. Upon execution, the compiled binary will decrypt and execute the code with the shells' -c option.Versions
| Version | Release date | Changes |
| 01-Jul-2019 |
| |
| 01-Jul-2019 | ||
| 20-Nov-2018 | Add LDFLAGS environment variable | |
| 17-Nov-2018 | ||
| 12-Nov-2018 | Add setuid option -S | |
| 12-Nov-2018 | Fix -U option not working on macOS | |
| 05-Jun-2017 | Fix shc causes exec output and aborts processing of bash scripts. | |
| 31-May-2017 | Fix running shc compiled binary in different shell | |
| 17-May-2017 | Fix executable not working on Debian | |
| 31-Jul-2016 | ||
| 25-Aug-2015 | Added BusyBox support with patch. | |
| 03-Apr-2015 | Renamed option -T to -U and reversed its logic. | |
| 02-Apr-2015 | Added output file option with and fixed bug on make install | |
| shc-3.8.9 | 04-Dec-2013 | Fixing a long-standing bug making the source not hidden. |
| shc-3.8.7 | 10-Feb-2010 | Bug on 64bit systems with expiration dates. |
| shc-3.8.5 | 10-Feb-2010 | Fixed untraceable problems on FreeBSD. |
| shc-3.8.3 | 10-Jul-2006 | Fixed bug: "vfork" fails on multiprocessor systems. |
| shc-3.8.2 | 06-Jul-2006 | |
| shc-3.7 | 28-Jun-2005 | |
| shc-3.6 | 16-Jun-2005 | Two new options: |
| shc-3.4 | 19-Jun-2003 | Remove "bad alignment" problem on AIX and other systems.Where exists, use /proc/ |
| shc-3.3 | 21-Apr-2003 | Prevent to ptrace the process. |
| shc-3.2 | 05-Aug-2002 | Find ancient pclose that must be fclose. |
| shc-3.1 | 05-Aug-2002 | Fixed a misbehavior on scripts with a in-first-line option equal to "end of options" GCC "warning: return type of `main' is not `int'" removed. |
| shc-2.4 | 05-Aug-2002 |
Alternatives
- shellcrypt