Is it possible to mangle a Bash script such that it becomes unreadable by any human? If so, can it be de-mangled? Or, can I view what commands are being executed when I run the script?
2 Answers
Code obfuscation is just a layer of false sense of security. You could learn and write the code in a c or c++ language that is compiled. Plus, if you can deobfuscate it, then probably someone else will.
Nevertheless, some obfuscation scripts are mentioned here:
http://www.linuxquestions.org/questions/linux-general-1/can-i-encrypt-a-shell-script-828096/
http://www.datsi.fi.upm.es/~frosal/ (shc used to exist in debian/ubuntu repositories but has been removed since it's easy to decrypt and exploitable)
On the other hand, you could set up the script permissions so that it cannot be read by other users except for the root (or setup the sudoers file and configure it with sudo).
-
"Code obfuscation is just a layer of false sense of security." - Not when someone is looking over your shoulder it isn't. As long as you know its limitations and purpose, you're fine. Nov 17, 2019 at 20:28
You can use shc
for purpose.
So you can use this command to encode:
shc -f script.sh
And it makes two files:
script.sh.x
script.sh.x.c
That .c
is in C programming language file. And .x
is executable file.
So for run it use:
chmod +x script.sh.x
./script.sh.x
shc
which compiles your bash script to a binary.base64
to encode and save the script, and to decode it at run time.