Explanation for newbies: setuid is a special permission bit that makes an executable run with the permissions of its owner rather than the user executing it. This is often used to let a user run a specific program as root without having sudo
access.
If this sounds like a security nightmare, that’s because it is.
In linux, setuid is slowly being phased out by Capabilities. An example of this is the ping
command which used to need setuid in order to create raw sockets, but now just needs the cap_net_raw
capability. More info: https://unix.stackexchange.com/questions/382771/why-does-ping-need-setuid-permission. Nevertheless, many linux distros still ship with setuid executables, for example passwd
from the shadow-utils
package.
Last time I was tempted to use suid, it was in order to allow an application I’d written to listen on 80 and 443. Fortunately I found the capabilities way of doing that (
setcap 'cap_net_bind_service=+ep' executable
) and that was the first I ever heard of capabilities. I consider myself pretty Linux-savvy, but it was pretty recently that I learned about capabilities.I just run everything as root
What security
Another potential option here is https://www.kernel.org/doc/html/latest/networking/ip-sysctl.html
ip_unprivileged_port_start - INTEGER This is a per-namespace sysctl. It defines the first unprivileged port in the network namespace. Privileged ports require root or CAP_NET_BIND_SERVICE in order to bind to them. To disable all privileged ports, set this to 0. They must not overlap with the ip_local_port_range. Default: 1024
This is also per namespace so you could use it in combination with network namespaces if you really wanted to keep privileged ports.
fork bomb still being possible out of the box in a couple of characters is funny to me
That’s the thing about Linux. The developers generally assume you want to do the thing you’re doing. So they don’t stop you.
ah the parenting toddlers approach
And I am eternally grateful for that. Why, yes, if I am playing with something I don’t understand - what was the last time a fire gently asked anyone “Do you really want to get a burn?”
The
nosuid
mount option disables this behavior per mount. Just be sure you don’t use suid binaries.Example:
sudo
ordoas
. I replaced those with switching to a tty with an already open root account on startup. Generally faster and (for me) more secure (you need physical access to get to the tty).How do you set up the tty method?
All I do is have
agetty --autologin root tty2 linux
run as a service. It launches on startup, and I just hit CTRL + ALT + F2 if I ever need a root shell.All its doing is just auto logging-in as root on TTY2.
Does run0 use suid? From my understanding, it shouldn’t.
From what I’ve read, no. Though it doesn’t solve the fundamental problem of a root process handling untrusted input from a regular user.
The TTY method is IMO better as it ties privileges to a piece of physical hardware, bypassing the complexities of userspace elevation of privileges.
Oops
In linux, setuid is slowly being phased out by
… brittle resume-based non-unix neu tools designed to encourage quiet balkanization and vendor/dev lock-in after being pushed by vendor payola.
See:
- Systemd bag of festering wunderkinder shit,
- networkManager and its 6 different competing manager-manager tools, and
- anything else created in the dark post-mentor ages when “move fast and break things” was dreamed up by people who didn’t give a fuck about must-work tools because must-work wasn’t on their final exam at udemy.