Jump to content

Shc (shell script compiler)

From Wikipedia, the free encyclopedia
Shc
Original authorFrancisco Javier Rosales García
Initial release20 November 1991; 34 years ago (1991-11-20)
Final release
4.0.3[1] / 1 July 2019
Repository
Written inC
Operating systemLinux
LicenseGPL-2.0-only
Websiteneurobin.org/projects/softwares/unix/shc/ Edit this on Wikidata

shc is a shell script compiler for Unix-like operating systems written in the C programming language. The Shell Script Compiler (SHC) 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.[2]

Mechanism

[edit]

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.[2]

The compiled binary will still be dependent on the shell specified in the shebang (eg. #!/bin/sh), thus shc does not create completely independent binaries.[3]

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.[3]

Versions

[edit]
Available Versions[4][5]
Version Release date Changes
shc-4.0.3 01-Jul-2019
  • Enhance -H flag (Hide commands arguments from ps and cmdline)
  • Remove -s flag (experimental feature not working as expected)
shc-4.0.2 01-Jul-2019
  • Fix typo
  • Fix NULL-ptr dereference in shll string
shc-4.0.1 20-Nov-2018 Add LDFLAGS environment variable
shc-4.0.0 17-Nov-2018
  • Add -H option for extra security without root. It protects against dumping, code injection, `cat /proc/pid/cmdline`, ptrace, etc.. (only works with Bourne shell (sh) scripts with no parameter)
  • Add -s option to force single process for hardening features (requires -H). (only works with Bourne shell (sh) scripts with no parameter)
  • dash support
shc-3.9.8 12-Nov-2018 Add setuid option -S
shc-3.9.7 12-Nov-2018 Fix -U option not working on macOS (10.13.6 High Sierra)
shc-3.9.6 05-Jun-2017 Fix shc causes (null) exec output and aborts processing of bash scripts.
shc-3.9.5 31-May-2017 Fix running shc compiled binary in different shell
shc-3.9.4 17-May-2017 Fix executable not working on Debian (debian bug #861180)
shc-3.9.3 31-Jul-2016
  • zsh support
  • Fix shc not working with ksh 93u+
shc-3.9.2 25-Aug-2015 Added BusyBox support with patch (-B flag to compile for Busybox[3]).
shc-3.9.1 03-Apr-2015 Renamed option -T to -U and reversed it's logic.
shc-3.9.0 02-Apr-2015 Added output file option with [-o filename] and fixed bug on make install (manual install failed)
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
  • Fixed bug: "rlax" used after encryption.
  • Read permision of the script.x exposes it to disassembling.
  • Group and others read permision is now removed by default.
shc-3.7 28-Jun-2005
  • Removed all strings in the compiled script.
  • Improved program output and error messages.
  • The -m option allows to define the *complete* expiration message.
  • Updated manpage shc.1.
  • Fix wrong $0 on ksh.
shc-3.6 16-Jun-2005 Two new options:
  • -D switch on Debug exec calls.
  • -T switch off unTraceable.
shc-3.4 19-Jun-2003 Remove "bad alignment" problem on AIX and other systems.

Where exists, use /proc/<pid>/as in untraceable.

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" (i.e. #!/bin/sh -- )

GCC "warning: return type of `main' is not `int'" removed.

shc-2.4 05-Aug-2002

Alternatives

[edit]

References

[edit]
  1. ^ "Release 4.0.3". 1 July 2019. Retrieved 13 November 2025.
  2. ^ a b Günther, Karsten. "SHC Shell Compiler". www.linux-magazine.com. Linux Magazine. Retrieved 2025-11-15.
  3. ^ a b c "Man page of shc". GitHub. Retrieved 2025-11-15.
  4. ^ Francisco Javier Rosales García. "Index of /~frosal/sources". www.datsi.fi.upm.es. Technical University of Madrid. Retrieved 2025-11-15.
  5. ^ Jahidul Hamid. "neurobin/shc/ChangeLog". GitHub. Retrieved 2025-11-15.
[edit]