Please explain setuid bit clearly!


 
Thread Tools Search this Thread
Operating Systems Linux Please explain setuid bit clearly!
# 1  
Old 02-23-2012
Please explain setuid bit clearly!

Dear all,

I am newbie with linux, i dont understand any code. I have googled a long time. Please help me explain about setuid bit on linux (Centos 6)

Here:
1/ I chmod u+s for /sbin/iptables but normal user still cannot perform command (ex: /sbin/iptables -L)

2/Someone says : setuid only set on binaries not scripts. But i dont know a way to determine this.

With file /sbin/iptables, it is a script or bin ?
with file /bin/ping, it is a script or bin ( because this file has setuid)

Thanks all,

Sorry for my English.
# 2  
Old 02-23-2012
Every thing in Linux is considered as file.

you can run following command to know the type of the file.

Code:
$ file /sbin/iptables
/sbin/iptables: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped
$file /bin/ping
/bin/ping: setuid ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

the above result says that they are binary files and all information about those binaries are given.

lets take example of a script.

Code:
$file update.sh
update.sh: Bourne-Again shell script text executable

this meand update.sh is a borne shell script.

lets take simple text file.
Code:
$file setup.conf
subversion.conf: ASCII text

some other format.

Code:
$file ldap.tar
ldap.tar: POSIX tar archive (GNU)

I think now you must have understood the file concept and how to know the file type.

Note- In Linux file extension does not matter and it may not give a exact picture of file type.

Last edited by vishal_vsh1; 02-23-2012 at 07:29 AM.. Reason: adding code format
This User Gave Thanks to vishal_vsh1 For This Post:
# 3  
Old 02-23-2012
Thanks Vishal,

But i want to know why setuid bit not working with /sbin/iptables though this file is binaries

As i said i have chmod u+s /sbin/iptables however normal user still cannot perform this command. You can explain me more clearly!!
# 4  
Old 02-23-2012
It is possible that iptables is refusing to run because the user executing the process doesn't match the owner of the binary. A process can check both the user's real ID, and the effective user ID (set as a result of the state of the SUID bit on the binary). Some programmes exit if both user IDs don't match.

I cannot say for sure about iptables, but if you can successfully set the bit, then that'd be my guess.
This User Gave Thanks to agama For This Post:
# 5  
Old 02-24-2012
Hi Agama,

Thanks for your reply! But i always think:

ex:
* user with id =500
* /sbin/iptables with owner = root
* chmod /sbin/iptables with permission: chmod u+s
* when user with id =500 run /sbin/iptables, program iptable will do user's ID= ruid = euid = root >> perform program (iptables -L) will success.


As your means is: user's ID= euid=root but differ ruid(root) of program iptables so normal user cannot perform command (iptables -L).

Sorry for my English. Hope you understand my english.

thanks all,
# 6  
Old 02-24-2012
The euid in this case would be root (0) and the uid would be the users real id (500). Some programmes check this and if they are not the equal they stop.

I just found a system with iptables installed and tried it. Without the suid bit on, it does fail with an error, but it was successful when I flipped suid on, so I don't think it is doing what I suggested.

Something that I noticed when I set the permissions is that iptables is actually a sim link that points to iptables-multi. Is this the case in your environment? If so, did you try setting the suid bit on iptables-multi as it doesn't make sense to set it on the simlink (chmod shouldn't allow it anyway).

Not sure what else to suggest.
# 7  
Old 02-24-2012
Why not try sudo?
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

How to handle 64 bit arithmetic operation at 32 bit compiled perl interpreter?H

Hi, Here is the issue. From the program snippet I have Base: 0x1800000000, Size: 0x3FFE7FFFFFFFF which are of 40 and 56 bits. SO I used use bignum to do the math but summing them up I always failed having correct result. perl interpreter info, perl, v5.8.8 built for... (0 Replies)
Discussion started by: rrd1986
0 Replies

3. UNIX for Dummies Questions & Answers

setuid & sticky bit

Can anyone explain me difference between setuid and sticky bit? and also between setuid and chown? (3 Replies)
Discussion started by: kkalyan
3 Replies

4. Red Hat

process fails if setuid bit is set

Hi, OS : Linux I have an executable (P1) owned by user say "abcd" and the setuid bit is set. And there is another executable (P2) which brings up the process (P1). When the setuid bit is set, the process P1 is failing, if the setuid bit is not set there is no issue. I was wondering if... (6 Replies)
Discussion started by: ahamed101
6 Replies

5. HP-UX

setuid bit - error

hi i have written small script which will login 2 two different users with su but if we run from normal user it prompts for password so i chnaged the owner of script to root and added setuid bit with chmod u+s <script_name> but when i run the script i get following message Warning:... (3 Replies)
Discussion started by: zedex
3 Replies

6. Programming

setuid bit on user + dynamically linked libraries

hi all, i have a critical and specific problem with respect to set uid bit on user and the dll's for a binary, (under the userid A) it needs libraries from /usr/lib and informix libraries from $INFORMIXDIR/lib/esql but this binary should be kicked off from id B, hence s-bit on user is... (5 Replies)
Discussion started by: matrixmadhan
5 Replies

7. Programming

copying or concatinating string from 1st bit, leaving 0th bit

Hello, If i have 2 strings str1 and str2, i would like to copy/concatenate str2 to str1, from 1st bit leaving the 0th bit. How do i do it? (2 Replies)
Discussion started by: jazz
2 Replies

8. UNIX for Advanced & Expert Users

setuid sticky bit

I have a binary. It is having the following permissions rws rws rwx mqm:mqm runmqtrm The same program on another machine is rws rws rwx root: mqm runmqtrm This program is a setuid program. This is what my understanding is. Whatever user the program is started under, it will finally be... (0 Replies)
Discussion started by: bandaru
0 Replies
Login or Register to Ask a Question