LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   convert shell script to a binary executable (https://www.linuxquestions.org/questions/programming-9/convert-shell-script-to-a-binary-executable-672503/)

madhi 09-26-2008 06:03 AM

convert shell script to a binary executable
 
Hi,

Need to convert a shell script to a binary executable form,so that script is not readable and should not be modifiable.

I used shc (the shell script compiler) , but shc is not working in cygwin.
I am using Cygwin as the linux simulator .

Is there any alternative approach in cygwin?

clvic 09-26-2008 07:42 AM

Are you using the binary version of shc? You can compile it from scratch in cygwin.
Then, it generates a .c file from a bash script, and you can compile it and that should do the trick

ghostdog74 09-26-2008 07:46 AM

if you are resorting to this, you most probably isn't using the correct method. The best way is to restrict who can or cannot use your script using permissions. you might also want to consider creating an interface, such as a web interface where you restrict user actions by a set of buttons and proper authentication.

madhi 09-26-2008 09:08 AM

Thanks for the reply

I have installed Generic Script Compiler(shc) Version 3.8.6 under cygwin env, but it is not encrypting the script file.

$ shc -v -r -T -f test.sh
/usr/local/bin/shc: /usr/local/bin/shc: cannot execute binary file

Not able to view help, but the shc binary is present in /usr/local/bin:

$ /usr/local/bin/shc --help
/usr/local/bin/shc: /usr/local/bin/shc: cannot execute binary file

The same setup works in Linux.

madhi 09-26-2008 09:15 AM

I have compiled the code from scratch under cygwin, Din't use any Binary version.

vikas027 06-25-2012 05:10 AM

Does not works for other server where binary is built
 
Dear All,

I am sitting on CentOS 5.4 64 Bit servers.

I need to convert a bash shell script to a binary since it has my passwords (for sudo / ssh) hardcoded.

I have found a way to get this done on the same server through this link.

Binary works well on the same server, but if I scp it to another server it works sometime and at time it does not. However, in the non working server if I execute the script (not binary) it works fine.

Any alternative method to get the binary working on all Linux servers (at least of same flavor) ?

dwhitney67 06-25-2012 05:24 AM

Quote:

Originally Posted by vikas027 (Post 4711157)
I need to convert a bash shell script to a binary since it has my passwords (for sudo / ssh) hardcoded.

I'm sorry I cannot help you with your request, but I'm replying because I want you to be aware that converting a shell-script to binary is not going to mask your hard-coded passwords. The string literals will still be visible to anyone who can read the binary file. All they would have to do is use /usr/bin/od or other similar tool for dumping the contents of the binary file.

Thus, as one person hinted at earlier in this thread, the best security to prevent someone from perusing your file is to set the file permissions to the most restrictive setting. But the better choice would be to remove the passwords from the file; surely there are alternatives.

vikas027 06-25-2012 05:34 AM

Quote:

Originally Posted by dwhitney67 (Post 4711169)
I'm sorry I cannot help you with your request, but I'm replying because I want you to be aware that converting a shell-script to binary is not going to mask your hard-coded passwords. The string literals will still be visible to anyone who can read the binary file. All they would have to do is use /usr/bin/od or other similar tool for dumping the contents of the binary file.

Thus, as one person hinted at earlier in this thread, the best security to prevent someone from perusing your file is to set the file permissions to the most restrictive setting. But the better choice would be to remove the passwords from the file; surely there are alternatives.

Thanks dwhitney67, I just checked through od and hexdump command, none of them showed the password.

$ hexdump swapcpu.sh.x | grep -i peter
$ od swapcpu.sh.x | grep -i peter

Surely, I can harden the permissions but I do not have an option to remove passwords.

Please help me with other alternatives. Thanks in advance.

pan64 06-25-2012 06:12 AM

you need to save the password in another file with minimal access rights and the shell will read info from that file. Also you can try to hide the path with some tricks (for example it is generated), but that can be catched by strace. Also you can use a server app to send such info, but you need to protect the communication also. And there can be other possibilities, but we do not know what this script do with that pw.

ntubski 06-25-2012 09:44 AM

Quote:

Originally Posted by dwhitney67 (Post 4711169)
I'm sorry I cannot help you with your request, but I'm replying because I want you to be aware that converting a shell-script to binary is not going to mask your hard-coded passwords. The string literals will still be visible to anyone who can read the binary file. All they would have to do is use /usr/bin/od or other similar tool for dumping the contents of the binary file.

Well the manpage for shc says it "encodes and encrypts" the shell script. Of course the decryption key is inside the resultant file so it's still easy to get the password but you need to do a bit more than just dump the contents.

dwhitney67 06-25-2012 10:01 AM

Quote:

Originally Posted by ntubski (Post 4711321)
Well the manpage for shc says it "encodes and encrypts" the shell script. Of course the decryption key is inside the resultant file so it's still easy to get the password but you need to do a bit more than just dump the contents.

Yes, my bad... thoughts entered my mind before I actually did any research on the shc application.

eschuch 07-24-2012 07:14 AM

Compile bash under cygwin
 
Ok. Realy old, but I was looking for it and decide to do my self and make it public.
http://goo.gl/M1NSY
Compile your bash script under cygwin!


Quote:

Originally Posted by madhi (Post 3292355)
Hi,

Need to convert a shell script to a binary executable form,so that script is not readable and should not be modifiable.

I used shc (the shell script compiler) , but shc is not working in cygwin.
I am using Cygwin as the linux simulator .

Is there any alternative approach in cygwin?


schneidz 07-24-2012 07:35 AM

Quote:

Originally Posted by vikas027 (Post 4711176)
Thanks dwhitney67, I just checked through od and hexdump command, none of them showed the password.

$ hexdump swapcpu.sh.x | grep -i peter
$ od swapcpu.sh.x | grep -i peter

Surely, I can harden the permissions but I do not have an option to remove passwords.

Please help me with other alternatives. Thanks in advance.

strings command would most likely work in this case.

ntubski 07-24-2012 09:36 AM

Quote:

Originally Posted by schneidz (Post 4736714)
strings command would most likely work in this case.

No, that won't work for the same reason grep won't work, see my post #10.


All times are GMT -5. The time now is 02:28 PM.