Hide code in shell script???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Hide code in shell script???
# 8  
Old 07-31-2003
On Solaris 5.8 after "chmod 711 testme" and switching to another user:

Can't open perl script "./testme": Permission denied

Is there a ksh--->exe tool? Perhaps that would be one way to be able to use permissions of 711.
# 9  
Old 07-31-2003
This is very odd. Yes, my uname -r is B.11.00.
What is the first line of your script? I have:
#! /usr/bin/ksh


First line of my script is: #!/bin/ksh <<==could THAT be the 'problem'? I do:

[acb@k903]/home/acb% echo $SHELL
/usr/bin/ksh

Could you post the results of a ls -ln script or whatever you called your script. And a id -u

[acb@k903]/home/acb% ls -ln dmake.ksh
-rwx--x--x 1 7073 50 1379 Jul 31 01:03 dmake.ksh*
[acb@k903]/home/acb% id -u
7073

The numeric uids control access. If your current uid as displayed by "id -u" is not zero or equal to numeric uid that owns the script you should not be able to run it.

Are you saying that, based on the results of "ls -ln dmake.ksh", I should not be able to run my script? I am so confused...

Unless the interpreter itself is suid to either root or the owner of the script. My ksh is 555.

Can you please explain this last statement?
# 10  
Old 07-31-2003
You're signed on as numeric id 7073 and numeric id 7073 owns the script. That means that you can read you own file. No surpise there, the user read bit is on.

Now log off and log back on as someone else. Make sure that your uid is different. That is "id -u" must return some number besides 7073. And it can't be zero either. Uid zero is root and has special powers. Once your uid is 7070 or something, now try to run that script which is continueing to be owned by uid 7073. Since the uid's do not match you should fail.

You said that tried this with 3 different logins. Do you have three logins all with 7073 as the uid???

No problem with /bin/ksh verses /usr/bin/ksh, they are the same file.

A suid program assumes the effective uid of it owner. A "ls -l /usr/bin/passwd" will show an example. Anyone can use that program to modify their password, but only root can actually write to /etc/passwd. Because the program is suid to root, it can do that.
# 11  
Old 08-01-2003
Okay...I screwed up (forgive my language)! Only `chmod 777` was applied on `dmake.ksh` when I ran my 3 tests successfully and not `chmod 711` (I thought my brain was turned on?). As you wrote earlier, it is therefore logical that all can see, execute and/or edit it.

Now log off and log back on as someone else. Make sure that your uid is different. That is "id -u" must return some number besides 7073.

Correct. I logged in as user `egroup` and did this:

[egroup@k903]/home/acb% ls -ln dmake.ksh (same result!)
-rwx--x--x 1 7073 50 1379 Jul 31 01:03 dmake.ksh*
[egroup@k903]/home/acb% id -u (different number!)
7073

And it can't be zero either. Uid zero is root and has special powers. Once your uid is 7070 or something, now try to run that script which is continueing to be owned by uid 7073. Since the uid's do not match you should fail.

You are correct. It failed (`cannot open`). For all 3 users. I have now applied `chmod 711`.

You said that tried this with 3 different logins. Do you have three logins all with 7073 as the uid???

Nope...All 3 logins have different uid values.

A suid program assumes the effective uid of it owner.
"ls -l /usr/bin/passwd" will show an example. Anyone can use that program to modify their password, but only root can actually write to /etc/passwd. Because the program is suid to root, it can do that.


This shows me that I have to pay close attention when deploying a simple script to my users. Not considering every points e.g. which bit is on/off ... may lead to a lot of confusion. I am going to talk to my boss and explain to him the situation: I need more time to review the whole solution...

Thanks for taking the time to teach me!

Al.
# 12  
Old 08-02-2003
Possibly the best workaround for you is to transform your script into a C/C++ program with username/password inside. This is not good either, but may work out for you.

Another option you may think about is to write a dummy C wrapper which is made setuid to the script owner and invoke the script in the program. The script can then be made off limits to other users by using the permission bits. However, as of other setuid programs you need to program it very carefully or you are inviting even more problems.

But I agree, you should take a close examination of the whole situation and find out if you can evade this by using some alternative means if at all possible.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to hide password in shell script?

I am writing a shell script for sql loader (just copy part of the code) : For security reason, I have to put the below loginName and password into another separate file instead of in the same file of this script. Anyone can give me a hand. Thanks. Shell Script :... (12 Replies)
Discussion started by: Jaewong
12 Replies

2. Programming

How to hide from UNIX strings - obfuscate or hide a literal or constant?

Hi, I need to somehow pipe the password to a command and run some SQL, for example, something like echo $password | sqlplus -s system @query01.sql To make it not so obvious, I decided to try out writing a small C program that basically just do echo $password. So now I just do x9.out | sqlplus... (8 Replies)
Discussion started by: newbie_01
8 Replies

3. Shell Programming and Scripting

Hide bash code which is inside C plus plus program

I am embedding bash in cpp. Can the bash code be hidden (when we cat the executable to not be able to see the bash code) The simple code I am using: #include <iostream> #include <cstdlib> using namespace std; #define test1 "\ #!/bin/sh --posix \n\ echo... (1 Reply)
Discussion started by: frad
1 Replies

4. Shell Programming and Scripting

Help to hide shell terminal and run prompt program after ssh login for specified user

Hey guys, I have some task from my office to lock user on the specified directory after the user logged on using ssh. And then run prompt program to fill the required information. Yeah, just like an ATM system. My question: How could I do those?? AFAIK I have to edit the ~./bashrc. But the... (1 Reply)
Discussion started by: franzramadhan
1 Replies

5. Shell Programming and Scripting

Hide my shell commands

I am writing a tool that connects using SSH to a remote server and perform some actions (through root) However - I would like to hide my operations so they will be hard to track. I tried STRACE on the SSHD process and saw all the traffic going there so I am quite transparent to STRACE ... (1 Reply)
Discussion started by: yamsin789
1 Replies

6. Shell Programming and Scripting

How Do I Hide the Password in a Script

Hi, I am writing a UNIX .ksh script and need to send the login password of the login id that is executing the script to a command that I am executing in the script. I don't want that password to be seen by anyone except whoever is executing the script. Does anyone know how I can accomplish... (6 Replies)
Discussion started by: samd
6 Replies

7. Shell Programming and Scripting

Hide a script ?

Hi all, i have a perl script for my users to run. My sys admin created an account for the users to log in and execute the script. They just type "perl myscript.pl" at the unix prompt to run it. Is there any way that i can hide my script? ,ie, do not allow my users to view the script. either... (5 Replies)
Discussion started by: new2ss
5 Replies

8. Shell Programming and Scripting

How to hide user inputted text for interactive unix shell script?

Hi everybody, Do you know how to hide the text for interactive unix shell script? Just like the case for inputting password during logon. Patrick (1 Reply)
Discussion started by: patrickpang
1 Replies
Login or Register to Ask a Question