Questions tagged [setuid]

`setuid` is a file permission flag under Unix-like systems that will run an executable with the file owner's permissions rather than the invoking user's. On some systems (FreeBSD), it further works identically to the related `setgid` flag on directories, causing new files to inherit the directory's permissions rather than the current user's.

setuid
Filter by
Sorted by
Tagged with
56 votes
4 answers
70k views

Run child processes as different user from a long running Python process

I've got a long running, daemonized Python process that uses subprocess to spawn new child processes when certain events occur. The long running process is started by a user with super user privileges....
Peter Parente's user avatar
41 votes
4 answers
33k views

RealUID, Saved UID, Effective UID. What's going on?

This is a set-root-uid program $ls -l -rwsr-sr-x 1 root root 7406 2011-12-13 22:37 ./x* The source code: int main(void) { printf( " UID GID \n" "Real %d ...
Lelouch Lamperouge's user avatar
31 votes
5 answers
47k views

Calling a script from a setuid root C program - script does not run as root

I need to run a bash script as root (passwordless sudo or su not viable) and since you cannot setuid a script in Linux, I thought about calling it from an executable and making it setuid: $ cat ...
user avatar
19 votes
2 answers
74k views

Getting message "sudo: must be setuid root", but sudo IS already owned by root [closed]

I'm trying to run sudo, and it's failing: gregd@david $ sudo ls sudo: must be setuid root gregd@david $ which sudo /usr/bin/sudo gregd@david $ ll /usr/bin/sudo -rwxr-xr-x 1 root root 165K 2012-05-16 ...
Greg Dougherty's user avatar
19 votes
3 answers
26k views

system() vs execve()

Both system() and execve() can be used to execute another command inside a program. Why in set-UID programs, system() is dangerous, while execve() is safe ?
Jake's user avatar
  • 16.5k
17 votes
1 answer
1k views

Using $ORIGIN with setuid application does not fail as expected

I have a librandom.so library and a main exectuable which was compiled as follows: $ clang++ -o main main.o -lrandom -L. -Wl,-rpath,"\$ORIGIN" They are both in the same directory. Since main has $...
Amir Rachum's user avatar
16 votes
4 answers
26k views

Setuid bit on python script : Linux vs Solaris

I am running this small python script on both linux and Solaris as a not privileged user : #!/usr/bin/python import os print 'uid,euid =',os.getuid(),os.geteuid() Before running, the setuid bit is ...
Eric's user avatar
  • 4,971
15 votes
3 answers
10k views

Linux C programming execute as user

I have an program which I run as root. I would like the program to execute another application as a normal user. I tried setgid() and it works, but I can't then go back to root or another user. The ...
Dominik Brzeziński's user avatar
15 votes
1 answer
19k views

What does connecting to own network daemon mean?

i'm currently doing the bandit wargames from overthewire.org (for those of you who don't know it's a website with different tasks that you get to do in order to improve your hacking skills). i did ...
jumpindonuts's user avatar
15 votes
3 answers
7k views

setuid vs seteuid function

What is the difference between setuid and seteuid function. In man page both of the function have similar description. setuid: DESCRIPTION setuid() sets the effective user ID of the calling ...
mohangraj's user avatar
  • 10.5k
15 votes
6 answers
17k views

how do i run valgrind to a process which has super user bit on?

I am running valgrind as follows:- /usr/local/bin/valgrind "process_name" After excecution its giving me following error ==21731== ==21731== Warning: Can't execute setuid/setgid executable: ==...
anish's user avatar
  • 1,035
12 votes
1 answer
9k views

Why do I need setuid(0) within a setuid-root C program that calls an administrative program with system()?

I had to do a dirty Linux hack for somebody so they could start a printer with the cupsenable printername shell command while being a non-root user. I didn't want them to be able to use the entirety ...
JCCyC's user avatar
  • 16.4k
11 votes
4 answers
11k views

How to use setuid() from root to become user, with the possibility of becoming root again later?

I'm trying to do the safe thing, and have a program that needs to runs as root to drop its privileges when it doesn't need them. This works well if I chmod my binary with the SUID bit, and make it ...
Florian's user avatar
  • 1,745
11 votes
5 answers
24k views

LD_PRELOAD with setuid binary

I am trying to use LD_PRELOAD to preload a library with an application that has setuid permissions. Tried LD_PRELOAD at first, and it seemed like it was being ignored with the setuid binary, though it ...
Mark Lobo's user avatar
  • 341
11 votes
2 answers
6k views

Git post-receive hook to update a local clone owned by a different user

I'm trying to set up a git post-receive hook such that when a commit is received, another clone of the repository on the machine gets updated (i.e. does a git pull origin master). I'm using gitosis to ...
Ibrahim's user avatar
  • 1,893
10 votes
2 answers
9k views

Change UID/GID only of one thread in Linux

Is there a way to change UID/GID only of one thread in a multithreaded process? The reason for this is writing a file-serving application - the ACL's and quota are not enforced unless the uid/gid of ...
ondra's user avatar
  • 9,262
9 votes
2 answers
8k views

"Operation not permitted" while dropping privileges using setuid() function

Why this simple programs that use os.setuid()/gid() fails? Is written in python but I think that is not a language relative problem (at the end are all the same posix system call): import os, pwd if ...
Emilio's user avatar
  • 3,951
8 votes
3 answers
12k views

setuid on an executable doesn't seem to work

I wrote a small C utility called killSPR to kill the following processes on my RHEL box. The idea is for anyone who logs into this linux box to be able to use this utility to kill the below mentioned ...
pmn's user avatar
  • 187
7 votes
3 answers
28k views

correct way to run setuid programs in C

I have a process with permissions 4750. Two users exist in my Linux system. The root user and the appz user. The process inherits the permissions of a process manager that runs as "appz" user. I ...
cateof's user avatar
  • 6,668
7 votes
2 answers
7k views

Program can't load after setting the setuid bit on

Consider this scenario in which an executable A.bin uses libY.so and libZ.so. A.c, Y.c and Z.c are all written in C. Z.c and Y.c are compiled into respective .so files. This is the directory ...
Saradhi's user avatar
  • 477
7 votes
1 answer
5k views

How to set permissions recursively, 700 for folders and 600 for files, without using find

I'm trying to figure out a way to set permissions recursively 700 for dirs and subdirs on a specific path and 600 for files. I would use these commands: find /path -type d -print0 | xargs -0 chmod 700 ...
Ichundu's user avatar
  • 173
7 votes
1 answer
3k views

Why ptrace doesn't attach to process after setuid?

I have a problem with my Linux daemon program. It starts with root privileges, does some configuration, then permanently drops privileges by switching to some user and group and continues working. The ...
user3232765's user avatar
7 votes
1 answer
23k views

Why do my setuid root bash shell scripts not work?

I created this simple script to allow the user to remove files created by the web server in his home directory without giving him "su". Both scripts are set with "chmod 4750". The craziest thing is ...
Bob's user avatar
  • 71
6 votes
1 answer
19k views

setgid() fails - operation not permitted

I created a setuid program in C. The executable looks like this: -r-s-r-s--- 1 root users 13073 Jun 15 21:56 server I execute the program as userA/users and try to set the uid/gid to userB/...
multiholle's user avatar
  • 3,090
6 votes
2 answers
7k views

setuid equivalent for non-root users

Does Linux have some C interface similar to setuid, which allows a program to switch to a different user using e.g. the username/password? The problem with setuid is that it can only be used by ...
Jeroen Ooms's user avatar
  • 32.5k
6 votes
1 answer
4k views

Is SetGID/SetUID on a Go[lang] binary safe?

I've written a simple go program using YAML and the MySQL drivers with the intention of providing a simple utility to update a database without exposing the username and password credentials to the ...
Jim Dennis's user avatar
  • 17.3k
6 votes
1 answer
1k views

security issue with set-uid and a relative path for INTERP (dynamic linker) in ELF

The combination of set-uid and a relative path in the INTERP section of an ELF binary is very dangerous. I'm not quite sure how and where this problem should be reported, but it seems to me like a ...
siddhadev's user avatar
  • 16.6k
6 votes
5 answers
18k views

"Operation not permitted" on using os.setuid( ) [python]

I'm trying to build a platform to launch some scripts. This scripts are placed in home folder of each user. Every launch should be done with each user id so, I'm doing, for each user, this: user_id = ...
carlesh's user avatar
  • 537
6 votes
1 answer
2k views

Mac App Store app with elevated privileges

I have a question regarding the Mac App Store. I am planning to release a software with admin privileges to achieve its core functionality, but according to Apple - 2.27 - Apps that request ...
koo's user avatar
  • 2,908
5 votes
3 answers
12k views

Can I setuid a perl script?

I made a perl script to change owner of a file owned by some other user. Script is complete. My administrator save that in /sbin directory and set uid for it using chmod u+s name_of_script. But when I ...
Sumit Rathore's user avatar
5 votes
3 answers
6k views

Golang dropping privileges (v1.7)

I want to make a custom webserver via golang. It needs root to bind to port 80. However I want to drop root as soon as possible. syscall.SetUid() returns "Not supported" as per ticket #1435. I ...
user2089648's user avatar
  • 1,366
5 votes
1 answer
2k views

Is the PAM stack always run as root?

I'm writing a module for Linux PAM, which uses setuid() to drop privileges to the user being authenticated. Of course, this will only work if the EUID is root. So, is the PAM stack always run as root, ...
Robin McCorkell's user avatar
5 votes
1 answer
2k views

can I pass argv from main to execv?

The execv() function expects an array of NULL terminated strings but doesn't take the number of arguments. It uses a sentinel value (NULL pointer) to determine when the array ends. The man page for ...
eric.frederich's user avatar
5 votes
1 answer
5k views

What do getresuid() and setresuid() do?

What do the functions getresuid(&arg1,&arg2,&arg3) and setresuid(arg1,arg2,arg3) do? It would be great if a really basic explanation of these functions were given.
Aswin G's user avatar
  • 371
5 votes
1 answer
6k views

setuid/setgid wrapper for python script

I have a Python script that I wish to be able to be run as the system user guybrush with UID 200 and group guybrush with GID 200. At the moment my Python script (located in /path/to/script.py) looks ...
DanielGibbs's user avatar
5 votes
4 answers
837 views

What's the best way to perform system tasks from Ruby on Rails?

I am building a small system administration web application (think Web-Min, but in RoR) and I need to be able to access system parameters from my Ruby code. For instance, I want to allow the user to ...
Richard Hurt's user avatar
  • 2,059
5 votes
1 answer
625 views

Execute commands as root without root password or sudo

I understand the implications of running a script as root, especially by a web application. However as part of my web application, I need to use curl with tor and this needs resetting the tor ip ...
Joel G Mathew's user avatar
5 votes
4 answers
1k views

running git 'post-receive' hook with setuid fails

I have a git repository that needs to run a post-receive hook as sudo. The binary that I compiled to test this looks like: #include <stdlib.h> #include <unistd.h> #include <stdio.h>...
Blake Chambers's user avatar
5 votes
1 answer
2k views

Considerations for a setuid wrapper

A Python extension I've written requires root access to do a single hardware initialisation call. I'd rather not run the whole script as root just for this one call in my extension, so I would like to ...
detly's user avatar
  • 29.8k
4 votes
3 answers
440 views

Setting root-only permissions on /dev files and build binary

As part of a build process, I want to run the following two commands: sudo chmod a+r /dev/cpu/*/msr sudo setcap cap_sys_rawio=ep ./bench This sets the /dev/cpu/*/msr files exposed by the msr kernel ...
BeeOnRope's user avatar
  • 62.4k
4 votes
2 answers
617 views

Can I run a C program containing setuid() without sudo?

I am trying to execute a C program from multiple users and trying to login as other user within the program to access a file. But I am getting error setuid: Operation not permitted Can I do ...
tarun14110's user avatar
4 votes
1 answer
10k views

seteuid/geteuid: Program always has root id

I'm currently trying to figure out how the SUID-bit and the corresponding functions seteuid and geteuid work. So I wrote this little program: #include <unistd.h> #include <stdlib.h> #...
Chris's user avatar
  • 2,060
4 votes
3 answers
4k views

Can an iPhone App Be Run as Root?

I am thinking about the design of an iPhone app I'd like to create. One possible problem is that this application will have to run as root (to access certain network ports). In a typical UNIX app, I'...
Kristopher Johnson's user avatar
4 votes
1 answer
1k views

Setuid binary to spawn root shell by overriding %n, does not work with exploit but works when exploit is unnecessary

I have a Setuid binary that has a printf format string vulnerability that is supposed to be exploited with "%n" to overwrite the value of the authenticated global variable. The execution of /bin/bash ...
ddaarrkkssttaar's user avatar
4 votes
1 answer
8k views

Debugging a setuid program / "Permission denied" with setuid

This is actually a three-part question, which I'll explain below, but the questions are: Using gdb, how can I run part of a program with root authority, and the rest with normal? Why would I get "...
Dennis 's user avatar
  • 1,087
4 votes
1 answer
3k views

Linux effective, real, saved, filesystem UID manipulation in pseudocode

I have spent some time on a little code in Groovy to make Linux UID manipulation somewhat less confusing to myself and because the man pages are messy. The result is a TestCase which is meant to show ...
David Tonhofer's user avatar
4 votes
2 answers
3k views

JNI + setuid Question

I have a web application that runs as a user www. However at one point it needs to read a file from a Linux filesystem on behalf of users Alice and Bob. One way of doing this would be to launch a ...
Paula's user avatar
  • 41
4 votes
1 answer
9k views

How to successfully run Perl script with setuid() when used as cgi-bin?

I have a Perl script that is called either via Apache or on the command-line. For testing purposes, I pass it the username I want the Perl script to operate with, and use POSIX::setuid to set the uid....
Alex Reynolds's user avatar
4 votes
1 answer
429 views

Dropping process rights under windows

I'm looking for a method to drop process rights for security reasons. I want to start as user with privileges and end as limited user. For example I want my web server to run under restricted user by ...
Artyom's user avatar
  • 31.4k
4 votes
2 answers
2k views

Open a file as root, but drop privileges before reading from it?

TL;DR I am writing a C program. I need to have root privileges to fopen a sysfs file, and I still need root privileges in order to read from it. However, since my program will need to continuously ...
Marco Merlini's user avatar

1
2 3 4 5 6