Possible to obfuscate Bash scripts?
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?
Solution 1:
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).
Solution 2:
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