Operating System - HP-UX
1752325 Members
5526 Online
108786 Solutions
New Discussion юеВ

Re: How to convert bash scripts into binary's, so no one can read it

 
SOLVED
Go to solution
Abii
Advisor

Re: How to convert bash scripts into binary's, so no one can read it

Hi Dennis,

>(You still haven't said why.)

I don`t want others to view/modify the shell script contents.


>Was this the gcc or cc run?

I belive it is cc ,Makefile has been attached along with reply

>Is shc executable?

I couldn`t find shc executable file in directory ,but shc.c and shc.1 is available

# pwd;ls shc;ls -l
/var/abi/shc1/shc-3.7
shc not found
total 272
-rwxrwxr-x 1 root sys 2474 Jun 18 2003 CHANGES
-rwxrwxr-x 1 root sys 17982 May 9 1996 Copying
-rwxrwxr-x 1 root sys 1564 Jan 14 12:00 Makefile
-rwxrwxr-x 1 root sys 256 Apr 16 2002 c2s.sed
-rwxrwxr-x 1 root sys 336 Feb 21 2003 match
-rwxrwxr-x 1 root sys 155 Jun 19 2003 pru.sh
-rwxrwxr-x 1 root sys 325 Apr 16 2002 s2c.sed
-rwxrwxr-x 1 root sys 3136 Jun 19 2003 shc.1
-rwxrwxr-x 1 root sys 1544 Jun 19 2003 shc.README
-rwxrwxr-x 1 root sys 21437 Jun 19 2003 shc.c
-rwxrwxr-x 1 root sys 3796 Jun 19 2003 shc.html
-rwxrwxr-x 1 root sys 138 Feb 21 2003 test.bash
-rwxrwxr-x 1 root sys 52 Jun 19 2003 test.csh


Abii
Advisor

Re: How to convert bash scripts into binary's, so no one can read it

Hi Dennis,

I apologize for the wrong reply for the 3rd query , please forgive me and have the correct reply

Is shc executable?
-rwxr-xr-x 1 root sys 39767 Jul 10 2006 shc

for more information :-

# pwd;ls -l;file shc
/var/abi/shc/shc-3.8.6
total 336
-rw-r--r-- 1 root sys 3549 Jul 10 2006 CHANGES
-rw-r----- 1 root sys 17982 May 9 1996 Copying
-rw-r----- 1 root sys 1525 Jun 16 2005 Makefile
-rwxr-x--- 1 root sys 336 Feb 21 2003 match
-rwxr-x--- 1 root sys 155 Jun 19 2003 pru.sh
-rwxr-xr-x 1 root sys 39767 Jul 10 2006 shc
-rw-r----- 1 root sys 3136 Jul 8 2004 shc.1
-rw-r----- 1 root sys 1544 Jun 19 2003 shc.README
-rw-r----- 1 root sys 24715 Jul 10 2006 shc.c
-rw-r----- 1 root sys 4558 Jul 8 2004 shc.html
-rwxr-xr-x 1 root sys 138 Nov 12 2004 test.bash
-rwxr-x--- 1 root sys 52 Jun 19 2003 test.csh

shc: ELF-32 executable object file
#

Thanks,
Abi
VK2COT
Honored Contributor

Re: How to convert bash scripts into binary's, so no one can read it

Hello,

Let me try to help.

I did not see you setting environment variable
CC to gcc or HP-UX acc.

You should firstly set it up and then
try to compile cleanly.

If you are going to use GCC, then set

CC=/usr/local/bin/gcc
(or wherever your gcc binary is)

Leave Makefile as it is because
it will use the last definition for:

# For GNU C compiler
CFLAGS = -Wall -O6 -pedantic


On the other hand, if you intend to use
acc, the set CC accordingly and
then comment out ALL but the following CFLAGS
line:

# For HPUX
CFLAGS = -Wall -O -Ae

I am not at my desk so I cannot check it
at the moment. But try this and let us know.

Interesting enough, I just found out
HP-UX Porting and Archive Centre
SHC bundles for a very old version of the
O/S and shc:

http://hpux.cs.utah.edu/hppd/hpux/Shells/shc-2.4a/

If there is enough interest, we could send an
email to the porting guys asking for
an updated version :)

Frankly, I would never advise anyone
to convert Shell script into binary.
No real benefits are achieved.

VK2COT
VK2COT - Dusan Baljevic
Dennis Handly
Acclaimed Contributor

Re: How to convert bash scripts into binary's, so no one can read it

>I believe it is cc, Makefile has been attached

Yes, cc, so those CFLAGS aren't valid.

>Is shc executable?
-rwxr-xr-x Jul 10 2006 shc

It shouldn't have this old date. It is probably for some foreign devil hardware. What does "file shc" show?
Try a "make cleanall".

>VK2COT: if you intend to use HP's C compiler, ... and then comment out ALL but the following CFLAGS line:
# For HPUX
CFLAGS = -Wall -O -Ae

No, this line is still garbage. You need "-Ae -O +wlint".
Dennis Handly
Acclaimed Contributor

Re: How to convert bash scripts into binary's, so no one can read it

>ME: What does "file shc" show?

Sorry, it looks like you did this:
shc: ELF-32 executable object file

So it should run and not get that error, since you are on IPF.
You still could cleanall and make everything.
Abii
Advisor

Re: How to convert bash scripts into binary's, so no one can read it

Hi Dusan/Dennis ,

Thanks for your advice , I will confirm you back on tomorrow

Thanks,
Abi
OldSchool
Honored Contributor

Re: How to convert bash scripts into binary's, so no one can read it

i notice that you keep answering the question "why you are trying to do this" with "what you are trying to do".

as noted above, if we knew the "why" then there may be better methods of accomplishing it then obfuscating the script.
Abii
Advisor

Re: How to convert bash scripts into binary's, so no one can read it

Hi Oldschool,

Why you are trying to do this ?

I want to encrypt the script ( health check script) and execute the same in many servers by copying the script.

I tried crypt command ,but its not encoding well ,so I feel better to compile the script and copy to many customer site. If you can suggest better method than this its really help full for me and well appreciated .



Thanks,
Abi
Abii
Advisor

Re: How to convert bash scripts into binary's, so no one can read it

Hi Dusan,

Thanks for your helping mind.

I tried what you said,but sorry to say I couldn`t succeed.Please have the below error and steps which I have performed.

# echo $CC
/usr/local/bin/gcc
# ldd /usr/local/bin/gcc
libintl.so => /usr/local/lib/hpux32/libintl.so
libc.so.1 => /usr/lib/hpux32/libc.so.1
libiconv.so => /opt/gtk2.6/lib/libiconv.so
libc.so.1 => /usr/lib/hpux32/libc.so.1
libdl.so.1 => /usr/lib/hpux32/libdl.so.1
# make cleanall
rm -f *.o *~ *.x.c
rm -f shc *.x
# make test
/usr/local/bin/gcc -Wall -O6 -pedantic shc.c -o shc
*** Compiling script "match"
CFLAGS="-Wall -O6 -pedantic" ./shc -v -f match
shc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: /usr/local/bin/gcc -Wall -O6 -pedantic match.x.c -o match.x
match.x.c:108: warning: string length '975' is greater than the length '509' ISO C90 compilers are required to support
match.x.c: In function 'untraceable':
match.x.c:289: error: too few arguments to function 'ptrace'
./shc: Error 0
*** Error exit code 1

Stop.

Thanks,
Abi

Dennis Handly
Acclaimed Contributor

Re: How to convert bash scripts into binary's, so no one can read it

>I couldn't succeed. Please have the below error and steps which I have performed.

(I only know and support cc, not gcc.)

>match.x.c: In function 'untraceable':
match.x.c:289: error: too few arguments to function 'ptrace'

This indicates you don't have have enough args for ptrace.
If this is ptrace(2), this isn't supported on IPF. See the man page.