Why my SETUID does not work as expected?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why my SETUID does not work as expected?
# 1  
Old 11-16-2015
Why my SETUID does not work as expected?

Hi All,

Thanks for your help in advanced.

Could you please kindly help on why my SETUID does not work?

create a file, only root can read write it
Code:
/tmp>ls -l a.log
-rw------- 1 root root 3 Nov 12 18:57 a.log

create a script under root with SETUID
Code:
/tmp>ls -l a.sh
-rwsr-sr-x 1 root root 23 Nov 16 00:18 a.sh

the script will read above created file
Code:
/tmp>cat a.sh
#! /bin/bash
cat a.log

run under non-root account, but still failed? why?
Code:
/tmp>a.sh
cat: a.log: Permission denied


Is it due to 'cat' is not setuid? If so, how can I modify my script to let SETUID take effect?
# 2  
Old 11-16-2015
I vaguely remember having read that certain systems' shells can't be run setuid. Try printing the effective UID from within the script.
# 3  
Old 11-16-2015
Is this script in a non-SUID filesystem perhaps? Have a look at the mount options for the filesystem that the script is in. You can probably get it by:-
Code:
df /path/to/your/script

You can then review /etc/fstab, /etc/vfstab or /etc/filesystems as applicable to your operating system (you don't say which, so these are the most common)

You might also get the same information from the mount command by itself, but this may be OS specific, so I'd be less sure about that.


Does that help?
Robin
# 4  
Old 11-17-2015
Linux and most other Unix-like OSes by design ignore the setuid bit on an executable script.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script does not work as expected

Repeat this text in a file named notes.txt and run the script Before bash is a good language a blank line appears Also, the following notes are displayed incorrectly What is bad? ================================== Title : Note 1 ================================== Category: Computer Date... (3 Replies)
Discussion started by: cesar60
3 Replies

2. UNIX for Beginners Questions & Answers

What keeps me from abusing setuid(0) and programs with setuid bit set?

Just learning about the privilege escalation method provided by setuid. Correct me if I am wrong but what it does is change the uid of the current process to whatever uid I set. Right ? So what stops me from writing my own C program and calling setuid(0) within it and gaining root privileges ? ... (2 Replies)
Discussion started by: sreyan32
2 Replies

3. UNIX for Dummies Questions & Answers

sed command does not work as expected

Why when I use this command do I get "E123"? echo NCE123 | sed -n 's/\(.*\)\(\{1,\}\{1,5\}\)\(.*\)/\2/p' But when I used this command, I get NCE123? echo NCE123 | sed -n 's/\(.*\)\(\{3\}\{1,5\}\)\(.*\)/\2/p' I thought \{1,\} would mean any number of characters and \{1,5\ would mean 1-5... (1 Reply)
Discussion started by: newbie2010
1 Replies

4. Shell Programming and Scripting

Joining Two Files Does not Work as Expected

Hi, I would like some help with the above awk command. I am trying to use the join command to join two files, no luck. I need to put the second column from file2.txt into each matching field of file1.txt. It works OK up to the value of 1000 of the matching column (1at column in both... (13 Replies)
Discussion started by: yirgacheffe
13 Replies

5. Shell Programming and Scripting

Parsing XML in awk : OFS does not work as expected

Hi, I am trying to parse regular XML file where I have to reduce number of decimal points in some xml elements. I am using following AWK command to achive that : #!/bin/ksh EDITCMD='BEGIN { FS = ""; OFS=FS } { if ( $3 ~ "*\\.*" && length(substr($3,1+index($3,"."))) == 15 ) {... (4 Replies)
Discussion started by: martin.franek
4 Replies

6. Red Hat

/usr/bin/find && -exec /bin/rm never work as expected

hi there, Would you able to advise that why the syntax or statement below couldn't work as expected ? /usr/bin/find /backup -name "*tar*" -mtime +2 -exec /bin/rm -f {} \; 1> /dev/null 2>&1 In fact, I was initially located it as in crontab job, but it doesn't work at all. So, I was... (9 Replies)
Discussion started by: rauphelhunter
9 Replies

7. UNIX for Dummies Questions & Answers

For some reason, my grep doesn't work as expected

I am trying to find only those entries where 7018 and another number appear in the end of the line. 7018 2828 1423 2351 7018 2828 14887 2828 7018 1222 123 7018 1487 I am looking for a way to generate only the last two lines. I was trying to do just "grep '7018{1,5}" but it does not... (5 Replies)
Discussion started by: Legend986
5 Replies

8. Shell Programming and Scripting

Script doesn't work as expected when run on cron

The script checks for free space stats on Oracle. If there are any tablespaces with more than 85% usage it prints the details of the tablespace. If all the tablespaces have more than 15% free space, then "All tablespaces have more than 15 pct free space" must be printed on the screen. When I run... (2 Replies)
Discussion started by: RoshniMehta
2 Replies
Login or Register to Ask a Question