LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2008, 11:48 PM   #16
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41

If you set the scripts to be owned and only writeable by root, other users will not be able to modify them. Why does it matter if they can read them or not? I find it ironic that you would want to keep a user from reading a shell script on an open source OS.
 
Old 10-05-2008, 01:08 AM   #17
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
This probably won't help, but maybe worth looking at:
http://comp.eonworks.com/scripts/obf...-20011012.html
 
Old 10-05-2008, 01:17 AM   #18
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Would this work? Keep the "secret" scripts on a restricted filesystem and set with execute permissions only. Then only give the users a wrapper script that calls up the main scripts when run. That way they can't see anything about the real script except the name and location, and messing with the wrapper is unlikely to do anything except break it.

Although I also agree with the above comments. What's so important about keeping the contents of a script secret? I doubt highly that there's anything in there that can't also be learned through other means. It's not like Linux administration techniques are classified information or anything.
 
Old 10-05-2008, 02:37 AM   #19
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Quote:
Originally Posted by David the H. View Post
Would this work? Keep the "secret" scripts on a restricted filesystem and set with execute permissions only. Then only give the users a wrapper script that calls up the main scripts when run. That way they can't see anything about the real script except the name and location, and messing with the wrapper is unlikely to do anything except break it.
The fly in the ointment is that execute-only permissions means no read permission. No read permission means the kernel won't open the script to read the contents for execution.

Code:
$ ls -l foo.sh
-rwxr-xr-x 1 root root 29 Oct  5 00:32 foo.sh
$ ./foo.sh
I'm alive

$ chmod a-r foo.sh
$ ls -l foo.sh
--wx--x--x 1 root root 29 Oct  5 00:32 foo.sh
$ ./foo.sh
./foo.sh: ./foo.sh: Permission denied
It doesn't matter if it is called directly by you, the user, or via another program. A script is nothing more than commands for a named interpreter opened as STDIN for the interpreter by the kernel upon execution. The command file (script) must be readable.

Last edited by Mr. C.; 10-05-2008 at 02:39 AM.
 
Old 10-05-2008, 02:51 AM   #20
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Are the other admin users on the same machine? Is it your password that you are trying to protect. If so, consider using sudo to control what they can execute instead of giving them root access. Otherwise, I don't see what the problem is with administrators being able to read scripts. They might improve on them. Also, why should an admin rely on blind trust that the scripts don't contain errors or do something malicious. If they can't be trusted, why do they have root access in the first place?
 
Old 10-05-2008, 02:56 AM   #21
WorldIsNotFair
Member
 
Registered: Jun 2008
Location: Jakarta
Distribution: CentOS 5
Posts: 89

Rep: Reputation: 17
i have tried the program (shc),

it convert the script to binary, in other way, user can't read this but still have read + execute permission.

so it can be solved with this program.

be positive & take the benefit.
 
Old 10-05-2008, 03:02 AM   #22
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I really don't think there's a need to question why it shouldn't be read. There are plenty of possible legitimate reasons and OP shouldn't need to explain that.

I think sudo is a reasonable option, though not very maintainable if you plan to incorporate various scripts of the same sort. If you plan to do this with many scripts indefinitely, I'd look into making some sort of remote access system (like I mentioned before with a client/server system) and just have an initiation script on the remote machine that requests the server perform one of the actions. This would allow you to update the actions available just on the server; the initiation script would never have to be changed.
ta0kira
 
Old 10-05-2008, 03:13 AM   #23
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
It is often necessary to ask the why because questions often incorrectly suggest solutions rather than clearly focusing on and stating problems. For example, in this case, the perceived problem may have been "how do I prevent others from seeing my embedded passwords?", so the proposed solution-question is "how do I make my script unreadable, but still executable". In this example, a better question would have been "how do I securely setup command X to be run by non-privileged users?" Without asking the why, respondents blindly suggest solutions that may not be optimal or correct.

I do agree that there is too much challenging of other people's intentions.

Last edited by Mr. C.; 10-05-2008 at 08:05 PM.
 
Old 10-05-2008, 03:17 AM   #24
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Re: shc

Quote:
In the October 2005 Linux Journal, Nalneesh Guar reports that he was able to break the encryption very easily. The man page seems to agree:

You can use it if you wish to distribute your scripts
but don't want them to be easily readable by other people.
Not quite what one would call robust security.
 
Old 10-05-2008, 07:41 PM   #25
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I agree it sounds like a typical sudo solution. If the other users are in fact sysadmins (ie with root access) its a pointless exercise.
 
Old 10-10-2008, 04:03 AM   #26
arunabh_biswas
Member
 
Registered: Jun 2006
Posts: 92

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by kirtimaan_bkn View Post
I see this as a genuine requirement. Someone wrote a shell script which do something related to system administration. He need to give that to some one else for the purpose of execution. Now he don't want to share the 'code' (or secret, how he achieved to do that task with shell script) and thats why he want to restrict others to view or modify the script, but at the same time allow them to execute the script.

So in my view, it shouldn't be consider as either 'attempt to either spread malicious software' or 'bad scripts'.

Thanks Kirtimaan,

Kirtimaan Explains the whole issue in just 6 lines...

I hope now I'll get a proper solution in one go.
 
Old 10-10-2008, 07:37 AM   #27
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Proper solution is not to use shell scripts.

While I dont believe that a person who has subordinates, really owns the shell script code (as opposed to his company owning it), I agree, it could be a genuine concern to be sure that the correct shell script is running.

So, I would suggest a simple C program that acts like a script controller. something like:

{
while not over
returnvalue=system("command1 ...") ;
while not over
returnvalue=system("command1 ...") ;
while not over
returnvalue=system("command1 ...") ;
while not over
returnvalue=system("command1 ...") ;
..
..
system("commandlast ...") ;
}

may do.

End
 
Old 10-10-2008, 02:52 PM   #28
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
And what prevents a user from running strace on that stealthy C solution you provide?

Let's be clear - if the code can be executed, it can be read and understood.
 
Old 10-11-2008, 02:59 AM   #29
ciden
Member
 
Registered: Dec 2006
Location: New Delhi, India
Distribution: PCLinuxOS 2010
Posts: 246
Blog Entries: 1

Rep: Reputation: 31
I guess OP just does not want to share his source code. Nothing wrong with that. Open source is an option not a compulsion.
 
Old 10-11-2008, 05:12 AM   #30
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by ciden View Post
I guess OP just does not want to share his source code. Nothing wrong with that. Open source is an option not a compulsion.
I think you should be careful with posting just "drive by" statements. Possibly you haven't read the thread well enough? The OP was asked for the reasons why and stated that
Quote:
Originally Posted by arunabh_biswas View Post
These scripts contains root previledged commands and I suspect that it might be used by other users or can be manipulate the scripts.
so this has nothing to do with OSS but with access restrictions. Obfuscation and Shc-like encryption are weak "solutions", this question has been asked (not that frequently but perfectly searchable in LQ) and the default answer for allowing unprivileged users access still is Sudo as stated before in this thread.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 06:24 AM
Editing PDF from CLI with shell scripts hamtavs Linux - Software 1 04-27-2008 12:35 PM
Restrict a Shell Script to run from a shell bharaniks Linux - Security 7 08-26-2007 10:57 PM
restrict root shell using sudo ElectroLinux Linux - Security 2 03-30-2007 05:07 PM
Editing files from shell scripts? SirRobbin Linux - Newbie 6 03-23-2004 10:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration