This article will help you create a binary file of your Shell Scripting, so that no one can see the source code of your script and we can use it as a command. To create a binary file from a script, we use the SHC compiler .
shc, a Shell Script compiler, produces the source code in C. The generated source code is then compiled and linked to produce a separate binary executable.
The compiled binary will continue to be dependent on the shell specified in the first line of the shell code (ie, shebang) (ie #!/bin/sh)
, so shc does not create completely independent binaries.
shc itself is not a compiler like gcc, it encodes and encrypts a shell script and generates the C source code with the added expiration feature. It then uses the system compiler to compile a separate binary that behaves exactly like the original script. After execution, the compiled binary will decrypt and execute the code with the shell -c
option.
In Gentoo and similar, use the portage that shc is already available on the tree:
For other distributions, for example derived from APT, first install the necessary dependencies:
Then download the package, decompress and compile the code:
Create a test file to see how it works: vim script.sh
:
Then use shc to transform it into binary:
And just run the program: ./binary
If you try to see the contents of the binary file, you will see everything encoded, example: cat binary
Para mais informações e opções via linha de comando, utilize a ajuda e o manual:
Official page shc: https://neurobin.org/projects/softwares/unix/shc/
Thanks for reading!