SUID works for shell scripts??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SUID works for shell scripts??
# 1  
Old 08-21-2015
SUID works for shell scripts??

SUID works for shell scripts (bash)??

I'm user user1 need to execute a shell script (script.sh) which is owned by user2.
Code:
-rwsrwxrwx 1 user2 aduser 3518 Aug 21 05:33 script.sh

Only user2 has write privileges to write/copy a file in directory /dir1/subdir. Hence SUID bit permissions are set to that script.sh. But still not able to run the script from user1 account. It says permissions denied to /dir1/subdir.

But the same script (script.sh) runs successfully from user2 account and able to copy/write a file in /dir1/subdir.

I don't have any clue.. Please help me..

Last edited by rbatte1; 08-21-2015 at 09:17 AM.. Reason: Changed BOLD output to CODE
# 2  
Old 08-21-2015
SUID for shell scripts will not work on most modern unix/linux systems.
This is due security reasons.

What you can do is to make a C program calling shell script and put a SUID on that compiled binary.

Can you perhaps use standard (or ACL) unix permissions to achieve the result you want to make ?
This User Gave Thanks to Peasant For This Post:
# 3  
Old 08-21-2015
You may find that the filesystem containing your script prevents SUID being recognised.

You don't tell us your actual OS, but can you show us the output from:-
Code:
df  /path/to/script
grep  file-system  /etc/?fstab  /etc/filesystems

The file-system will be the right-most column from the df command. I've asked it to search in various places (some of which won't exist) to try to cover all operating systems.


Robin
# 4  
Old 08-21-2015
As has been said before, it is always a good idea to tell us what operating system you're using (in addition to the shell you're using) when you ask a question here. We can give you much more responsive suggestions if we know the environment you're using...

Even on systems that allow set-UID and/or set-GID scripts, most of them won't allow it when users other than the file's owner (especially for set-UID scripts) and/or groups other than the file's group (especially for set-GID scripts) can write to the file containing the script.

If you can get user2 to change the mode of script.sh from mode 4777 to mode 4755, you might get it to work on some systems.
# 5  
Old 08-21-2015
sudo is another approach. It allows users to run code as other users. Your sysadmin has to set this up.

See (linux example): https://www.linux.com/learn/tutorial...uction-to-sudo

sudo is available for a lot of UNIX platforms
# 6  
Old 08-21-2015
Quote:
Originally Posted by Peasant
...

What you can do is to make a C program calling shell script and put a SUID on that compiled binary.

...
Except you have to be really careful when you do that. A simple

Code:
int main()
{
    return ( system( "/path/to/some/command" ) );
}

is NOT secure.
# 7  
Old 08-24-2015
Thank you all for your comments..
I'm using Unix (solaris 5.10)

I tried the following c program:
Code:
 #include <stdio.h>
#include <stdlib.h>
 #define SHELLSCRIPT "\
/home/user1/script_test/test_script_v1 \n\
"
 int main()
{
    puts(SHELLSCRIPT);
    system(SHELLSCRIPT);
    return 0;
}

Note: /home/user1/script_test/test_script_v1 --> script to copy a file in /dir1/subdir where user1 (me) don't have access to write/copy a file

The program is compiled and I had set the SUID permissions. After setting SUID for that executable I tried to execute it from my home dir, It executed successfully and copied the file in the directory /dir1/subdir.
But I need to pass 5 input parameters to shell script, The scenario just tested is just executing the shell script from c program.. But I need to pass input parameters to shell script. Can anyone please tell me how to change the above c program to pass inputs to shell script.
Thanks in advance.

Last edited by vbe; 08-24-2015 at 09:40 AM.. Reason: code tags please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between inbuilt suid programs and user defined root suid programs under bash shell?

Hey guys, Suppose i run passwd via bash shell. It is a suid program, which temporarily runs as root(owner) and modifies the user entries. However, when i write a C file and give 4755 permission and root ownership to the 'a.out' file , it doesn't run as root in bash shell. I verified this by... (2 Replies)
Discussion started by: syncmaster
2 Replies

2. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

3. Shell Programming and Scripting

variable assigment not works in shell script

Hi, The following assigment is not working within shell script but is working from command line. Could anybody advise why? OS - solaris 8 APPL=`grep "$Application" ldapapps |awk '{print $1}'` echo $APPL (5 Replies)
Discussion started by: urello
5 Replies

4. Shell Programming and Scripting

How does a if works in shell

Hi, I need to compare and get an output for values greater than "X10" (values contain both characters and numbers) using if loop... FOR EG: I want to export values greater than X10, i.e., in-case if the value is X11 and greater than the "if" part to be executed if the value is X9 and... (2 Replies)
Discussion started by: shivashankar_S
2 Replies

5. UNIX and Linux Applications

Rsync works in shell but not in cron

So I have this rsync script I wrote to grab some sql files and import them to a database. I left in the mysql stuff just give context to the situation. The real problem is with my rsync code. script.sh (chmod 744) #!/bin/sh rsync -av --rsh="sshpass -p'PASSWORD' ssh -l'USERNAME'"... (3 Replies)
Discussion started by: noPermissions
3 Replies

6. Shell Programming and Scripting

how the typeset command works in shell script

typeset -l section section=${2:-.} what does these 2 lines meaning? (1 Reply)
Discussion started by: venkatababu
1 Replies

7. Shell Programming and Scripting

Works in shell but not script UNIX

ok i have a very simple UNIX script #!/bin/bash TERM=ansi;export TERM PFCMARK=25;export PFCMARK umask 0000 PFUMASK=000;export PFUMASK #run for filepro menus and exectuables echo "###########File Modification Log.############\r" > "/public/appl-fp$(date +%m-%d-%Y).txt" find /appl/fp/... (10 Replies)
Discussion started by: dunpealslyr
10 Replies

8. Shell Programming and Scripting

Execution issue with shell script - works in a different environment

Hi I get the following error while executing the shell script. I did not get an error when I ran the script in a different environment (unix server). str-token.ksh: 0403-057 Syntax error at line 20 : `(' is not expected. This is the line which gives error string=(${pos_array}) Please find... (3 Replies)
Discussion started by: hidnana
3 Replies

9. Shell Programming and Scripting

substring command works but only in BASH shell

I am having trouble running a .sh file. The code 'x=${file_name:0:$z-11}' is giving me a bad substitution error. However when I run in BASH it works. Thing is when this goes to production the .sh will not be running in BASH. Is there a way to substring a string not in BASH or a way to invoke... (2 Replies)
Discussion started by: edwardtk11
2 Replies

10. UNIX for Advanced & Expert Users

is SUID disabled for shell

Hi, I have two file in my directory. "catter" file contains "cat ./file". And "file" contails "Hi ashish". I have SUID bit set for catter file. But when a different user in my group runs file catter, shell displays "Permission denied" message. I just want to know can use of suid bit be... (3 Replies)
Discussion started by: shriashishpatil
3 Replies
Login or Register to Ask a Question