LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Question about scripting (https://www.linuxquestions.org/questions/programming-9/question-about-scripting-256603/)

RitzContent 11-18-2004 06:10 PM

Question about scripting
 
Hello everyone
I have looked and haven't beable to find any answers that would help me..

So here I go..

I have writen up a korn script to be used in solaris and it works but I would like to protect it from it being edited because other people use it and I don't want to trouble shoot something they could of edited and messed up.

So is there away to encrypt the script so its not readable but yet still executeable? Or is there a way to complie it into a format to be used in solaris? Kind of like how you take a bat file for windows and turn it into a com file.

Or is there another lanuage that is close to korn that can be complied that someone can point me in the right direction?

thanks for any help

itsme86 11-18-2004 06:27 PM

You can just chmod it and remove their write permissions and leave the execute permissions.

RitzContent 11-18-2004 06:55 PM

Well the script is on a floppy so it won't really work if they happen to use a windows OS to mess it up.

jlliagre 11-18-2004 06:56 PM

If you want a stronger protection, try shc, at
http://www.datsi.fi.upm.es/~frosal/frosal.html

It wouldn't prevent truss/strace/dtrace or equivalent programs to snoop what's your program is doing, but the source code will be obfuscated.

Chrax 11-18-2004 09:03 PM

If nobody should be able to write to the disk at all, you could flick the little writable thing on the floppy (one of the corners, if it's open it's non-writable, if it's close it's writable). Otherwise keep a copy on your system and just copy it on everytime you want to give it to somebody new. I don't think there's any elegant solution to keeping windows machines from messing with it.

homey 11-18-2004 10:12 PM

You could take a small screwdriver and flip that write protect tab out completely. That way a user would have to purposely cover the hole ( tape ) in order to write to the disk. If the users aren't too savey, you might get by with that.

Chrax 11-18-2004 11:32 PM

I assumed it was to avoid accidents. But yeah, I forgot to mention that option.

Hko 11-19-2004 05:00 AM

If this is not about real encryption, but only obfuscating, why not use ROT13?
(Example in for sh here, but should be very similar in ksh.)

Say your script is called "skript.sh":
Code:

#!/bin/sh

echo "Hello"
echo "Hallo"
echo "Gutentag"
echo "Hola"
echo "Aloha"

Then you "encrypt" it with ROT13:
Code:

shell$ cat skript.sh | tr 'a-zA-Z' 'n-za-mN-ZA-M'
This outputs:
Code:

#!/ova/fu

rpub "Uryyb"
rpub "Unyyb"
rpub "Thgragnt"
rpub "Ubyn"
rpub "Nybun"

Then you create an obfucated script called "obfuskript.sh" from the output above like this:
Code:

#!/bin/sh
FIFO=/tmp/qwee_asdd
rm $FIFO >/dev/null 2>/dev/null
mkfifo $FIFO
sh $FIFO &
tr 'a-zA-Z' 'n-za-mN-ZA-M' >$FIFO <<EOF_EOF

#!/ova/fu

rpub "Uryyb"
rpub "Unyyb"
rpub "Thgragnt"
rpub "Ubyn"
rpub "Nybun"

EOF_EOF


RitzContent 11-19-2004 06:03 AM

The script writes files to the root dir and to the floppy disk both. So making the floppy locked isn't a real option because it has test reports. And people print those reports out on a windows machine.

but I will try shc today and see if that will do.

Thanks for everyone's help so far.

with the ROT13 do you have to "decrpyt" the script before you can use it? And if so can you give a example of the command line for it?

Hko 11-19-2004 06:45 AM

Quote:

Originally posted by RitzContent
with the ROT13 do you have to "decrpyt" the script before you can use it? And if so can you give a example of the command line for it?
The script I posted (the last code block) is the obfuscated script, and "decrypts" itself. It runs as posted. Just copy-paste it, and run it.

jlliagre 11-19-2004 11:37 AM

I just built shc-3.7 on Solaris, and had to change a couple a lines for it to work:

line 269, commented out the include
"/* #include <sys/ptrace.h> */",
line 290, replaced PTRACE_ATTACH by 0
" mine = !ptrace(0, pid, 0, 0);",

Compiling with gmake and gcc, I got a working shc. The generated binaries built from shell sources looks more difficult to hack that I thought before.

RitzContent 11-19-2004 04:32 PM

Well I wasn't able to get the shc working ( which from how it sounds is what I am looking for )

I even edited those lines out but to no luck.

jlliagre 11-20-2004 02:59 AM

I can help if you give more details about what fails.

What Solaris version are you using ?
What errors do you got ?

RitzContent 11-20-2004 12:58 PM

I will try again when I get to work..

I didnt' write down the errors.. I know bad me..

Its solaris 8.

But I did make a little script that uses the tr function to "decrpyt" to a new file. had to do it that way because it wasn't able to use any of the vars I had set.

I'll try again monday and post back.

RitzContent 11-22-2004 10:42 AM

cc -Wall -O6 -pedantic shc.c -o shc
gmake: cc: Command not found
gmake: *** [shc] Error 127


All times are GMT -5. The time now is 03:13 AM.