Setuid usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setuid usage
# 1  
Old 11-28-2018
Worked like a charm:

Code:
#include <stdio.h>
#include <stdlib.h>

int main( int argc, char **argv ) { 

   FILE* fp = fopen( "/hi" , "w" );
   fprintf( fp, "%s\n", "hi there" );
   fclose ( fp );
   exit(1);
}

And then:

Code:
$ gcc hi.c
$ mv a.out sayHi
$ sudo chown root sayHi
$ sudo chgrp root sayHi
$ sudo chmod u+s sayHi
$ ls -l sayHi
-rwsr-xr-x 1 root root 8256 Nov 29 06:04 sayHi
$ ./sayHi
$ ls -l /hi
-rw-r--r-- 1 root pi 9 Nov 29 06:06 /hi
$ cat /hi
hi there
$

Alles klar.

------ Post updated at 10:23 PM ------

Quote:
Originally Posted by Don Cragun
You still haven't told us what operating system you're using...

Some operating systems NEVER allow shell scripts to be run set-uid.

Some operating systems NEVER allow a running program to be overwritten.

Some operating systems only allow shells specified in a system file to be used to run set-uid scripts.

All of the above are possible reasons why what you're trying might not work on an unspecified operating system.
I wasn't sure what information was relevant. Originally I thought a shell script could be used to experiment but apparently not.
I'm using Bash v4.4 on a Raspberry Pi running Raspbian, a Debian based Linux distribution. And Bash v4.4 on Kali Linux (Stretch), also Debian based.

I'm actually not trying to overwrite a running program. It may have looked like that because originally I tried to write the string "hello" into a file with filename "hello" and the script was also named hello. My apologies for the confusion.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. UNIX for Dummies Questions & Answers

Restricting Usage of Setuid Programs to the Admin User In MacOsx

This is a quote from the Apple security configuration (you can download it from Apple) " Using ACLs to Restrict Usage of Setuid Programs The ACL feature of Mac OS X can also be used to restrict the execution of setuid programs. Restricting the execution of setuid programs to administrators... (3 Replies)
Discussion started by: Vera
3 Replies

3. Solaris

Need help with setuid.

Hi Gurus, I need your suggestions,to implement setuid. Here is the situation. I have a user xyz on a solaris zone.He needs to install a package using a pkgadd command but i guess only a root can run that .Is there any way I can set the setuid bit on the pkgadd which is in the location... (6 Replies)
Discussion started by: rama krishna
6 Replies

4. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

5. Solaris

setuid and guid

Hi All, Can someone give me some info about setuid or guid topic? Also about sticky bit. Thanks in advance, itik (9 Replies)
Discussion started by: itik
9 Replies

6. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

7. UNIX for Dummies Questions & Answers

setuid

could u plz give me clear idea of spcial permissions setuid,getuid and striky bit . (1 Reply)
Discussion started by: Prem
1 Replies

8. UNIX for Advanced & Expert Users

cc, setuid, and LD_LIBRARY_PATH

Hi, This question deals with Solaris 2.8 and setuid programs. From research I've done so far, setuid programs ignore LD_LIBRARY_PATH; I've proven this and am OK with it. The thing I am not certain of how the C compiler is supposed to behave when it is invoked via a setuid program. Basically,... (0 Replies)
Discussion started by: WolfBoy
0 Replies

9. UNIX for Dummies Questions & Answers

Using setuid and setgid

Hi, I have been looking at setuid and setgid. I understand that setuid determines who owns the file and setgid determines which group of people can access the file... yeah?! But i need to know how to actually use setuid and setgid. I'm guessing chmod will feature somewhere.. Any help... (1 Reply)
Discussion started by: crispy
1 Replies

10. UNIX for Advanced & Expert Users

setuid

I have a C wrapper programme which basically execute a shell script. The shell script has 700 as permission and oracle is owner of the shell script. The C execuatble has 4711 permission so that means that it has setuid bit set and group and others can execute the C executable. The reason why I am... (2 Replies)
Discussion started by: sanjay92
2 Replies
Login or Register to Ask a Question