PDA

View Full Version : Suid root seems not to work - Getting SUIDcidal ;-)



mvandoornik
07-11-2005, 11:38 AM
Greetings!

As I'm using Kanotix (which doesn't seem to have such an extensive forum) and it's based on Knoppix, I figure I'll post this question here.

For a program which will use the parallel port for digital I/O, I'm trying to get access to the port WITHOUT being root (no sudo, either). For this, I've compiled a simple program in C, but it keeps complaining it has no permissions to access the port (/dev/parport0). Port permissions are as follows:


crw-rw-rw- 1 root root 99, 0 Feb 9 19:40 /dev/parport0


The program has been compiled using gcc -O1 -o test test.c, after which I've issued (as root):


chown root:users test
chmod u+s test


I figured it should work now, but it doesn't. Keeps complaining about permissions.

Furthermore I've tried creating a file foo.txt and done chmod 600 foo.txt. Then made an executable script bar.sh, which just cat's foo.txt. Then:


chown root:users bar.sh
chmod u+s bar.sh

Executing bar.sh also gives permission errors. So in other words: what gives? I'm stumped, but I've probably misunderstood how suid root works. Any help would be greatly appreciated.

Thanks in advance,

Marc.

mvandoornik
07-11-2005, 01:00 PM
Well, that wasn't too hard. After putting my program in a directory in the path, all seems well. OTOH, it doesn't work when it's in a directory that only belongs to my personal path. Does it have to be in the root's path somewhere?

Dave_Bechtel
07-11-2005, 06:26 PM
That's weird, man. :shock:


Well, that wasn't too hard. After putting my program in a directory in the path, all seems well. OTOH, it doesn't work when it's in a directory that only belongs to my personal path. Does it have to be in the root's path somewhere?

markpreston
07-11-2005, 09:14 PM
If Kanotix is similar Knoppix I guess the $PATH variable for root has a different (more restricted) set of paths to a normal user. This is partly for security.
This can be tested by
$PATH followed by <enter> at a terminal window. Do this for root and for a normal user and see if this helps explain what has happened.

Dave_Bechtel
07-12-2005, 12:28 AM
I think you meant:
echo $PATH


If Kanotix is similar Knoppix I guess the $PATH variable for root has a different (more restricted) set of paths to a normal user. This is partly for security.
This can be tested by
$PATH followed by <enter> at a terminal window. Do this for root and for a normal user and see if this helps explain what has happened.

angor
07-12-2005, 05:59 AM
> Executing bar.sh also gives permission errors.

The suid permission bit is ignored for scripts for security reasons. Suid for "true" executables only give the *effective* UID,
not the *real* UID. This can make a difference, e.g. as in cpio.

markpreston
07-12-2005, 08:12 AM
Hi Dave,
$PATH alone works as well for this.
mark@z:~$ $PATH
bash: /home/mark/.dist/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin:/usr/games:.: No such file or directory
mark@z:~$
mark@z:~$ su
Password:
root@z:/home/mark# $PATH
bash: /sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin:/usr/games: No such file or directory
root@z:/home/mark#

I think you meant:
echo $PATH

Dave_Bechtel
07-12-2005, 06:25 PM
--Yes, but it's not proper *nix form to try and _execute_ your PATH variable. Somebody could attack you that way. :twisted:


Hi Dave,
$PATH alone works as well for this.
mark@z:~$ $PATH
bash: /home/mark/.dist/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin:/usr/games:.: No such file or directory
mark@z:~$
mark@z:~$ su
Password:
root@z:/home/mark# $PATH
bash: /sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin:/usr/games: No such file or directory
root@z:/home/mark#

I think you meant:
echo $PATH

markpreston
07-13-2005, 08:20 PM
--Yes, but it's not proper *nix form to try and _execute_ your PATH variable. Somebody could attack you that way. :twisted:

Thanks Dave,
At least I now know what you were concerned about.
Regards,
Mark