Operating System - HP-UX
1820475 Members
3236 Online
109624 Solutions
New Discussion юеВ

Re: How to hide shell programming source code

 
ROSDI BIN SAAD
Occasional Contributor

How to hide shell programming source code

Hi,

I would like to seek ITRC forum whom which have an idea on how to compile shell script as similiar likes c program to avoid intruder copy the source code and break the ownership and copyright.

Thanks.
10 REPLIES 10
Mark Grant
Honored Contributor

Re: How to hide shell programming source code

If this is an issue, your best bet is to just set permissions on your scripts so anuathorized people can't write to it. Or, don't use the shell.

Having said that, I have heard of shell compilers but have never actaully seen one. I would assume that, as they are not common, that they are not really up to date and therefore some scripts wouldn't work properly. Could be wrong though.
Never preceed any demonstration with anything more predictive than "watch this"
Nicolas Dumeige
Esteemed Contributor

Re: How to hide shell programming source code

Hello,

Don't look further, shell scripts are interpreted, thus, we cannot give the shell away and keep the source for yourself.

Nicolas
All different, all Unix
Steve Steel
Honored Contributor

Re: How to hide shell programming source code

Hi


chmod 111 script


Will execute but you cannot read or write it

Or copy it

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Sanjay Kumar Suri
Honored Contributor

Re: How to hide shell programming source code

I have following solution

1. Write a small 'C' code say test.c as below:

main()
{
system ("script_name_with_full_path");
}

2. #chmod 755 script_name_with_full_path

3. Compile test.c as below.

#cc test.c

4. Execute the output a.out which can be renamed as well.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Nicolas Dumeige
Esteemed Contributor

Re: How to hide shell programming source code

At least, the script must have read access to execute :
/bin/ksh: exemple.ksh: cannot open

All different, all Unix
Laurent Menase
Honored Contributor

Re: How to hide shell programming source code

Hi,


I have an idea,

try
#include
#include
main()
{
int i;
char fifoname[256];
sprintf(fifoname,"/tmp/fifoname_%d",getpid());
mkfifo(fifoname,0777);
signal(SIGCLD,SIG_IGN);
if(fork())
{/*parent process is ksh*/
execl("/usr/bin/ksh","/usr/bin/ksh",fifoname,0);
perror("exec");
kill(0,SIGHUP);
exit(1);
}
/*child process write to the pipe*/
i=open(fifoname,O_WRONLY);
/* you write your script, after some processing like crypto to the fifo*/
write(i,"echo oui\n",9);
close(i);
unlink(fifoname);


}

To test it in shell:

mkfifo /tmp/xxx$$
echo echo ok it works'$$':$$ >/tmp/xxx$$&
exec /usr/bin/ksh /tmp/xxx$$

# ksh titi
6651
ok it works6651:6651
#
Pete Randall
Outstanding Contributor

Re: How to hide shell programming source code

Links to several shell compilers are provided in this thread:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=151147


Pete

Pete
Laurent Menase
Honored Contributor

Re: How to hide shell programming source code

just a last thing,
If you really want it be not possible to read it even with a strings a.out, you will need to uncrypt the script before writing to the fifo
Elmar P. Kolkman
Honored Contributor

Re: How to hide shell programming source code

You could, indeed, try to use the crypt program. Test for your self:

# /usr/bin/crypt 'passwd'
# /usr/bin/crypt 'passwd'
So all you need to do is run crypt on all your shell scripts AND REMEMBER YOUR PASSWORD

You could also do something like this from a system command in a C-program.

system("/usr/bin/crypt
Every problem has at least one solution. Only some solutions are harder to find.
ROSDI BIN SAAD
Occasional Contributor

Re: How to hide shell programming source code

Hi all experts,,

Thanks for the ideas and it works fine. Close the case.