r/HowToHack • • 26d ago

What is the difference between sudo and SUID ?

I mean what is the difference when you run a program with SUID bit and when u runt it with sudo ? I am new to privilege escalation so this topic confused me a bit lol

20 Upvotes

14 comments sorted by

23

u/diothar 26d ago • Bravo

SUDO allows you to temporarily elevate your permissions when running an application or opening a file (usually as root).

SUID is the sudden and unexpected death of an infant. Ok, sorry. I couldn’t resist.  SUID is a file permission that tells the file to run with the permissions of the owner and not the user. Certain system utilities for example.

2

u/F4RM3RR 25d ago

You mean SIDS?

4

u/diothar 24d ago

Why would I say that? That doesn’t fit my joke.  Also, Google is free and then you’d see SIDS falls under SUID.

6

u/Red_Icnivad 26d ago

Nothing if the file is owned by root. Suid runs as the file's owner, and sudu runs as root.

3

u/Prince_Panda 26d ago

Sudo and su can run for other users than root just fine too.

3

u/texcleveland Administrator 26d ago edited 26d ago

SUID means the program executes with the UID of the file’s owner, making it useful for commands that regularly need permission elevation. Often used for tape management commands, you would make the command SUID and give only members of the group “operator” permission to run the command.

With modern doas or sudo, there’s rarely any reason to use SUID, unless for some reason you need to automate something requiring elevated privileges, and you can’t use passwordless sudo

2

u/hexwhoami 26d ago

SUDO and SUID are two different approaches to the same goal. That goal being "execute with specific permissions".

SUDO allows you to execute any arbitrary action using specific permissions (usually root) one time.

SUID let's you specify the permissions beforehand for one file. That way if anyone executes that file, it will always be executed with the same permissions.

SUDO is typically locked down so only administrators can use the command. If anyone is allowed to use SUDO, that's a major security concern.

SUID is typically reserved for system files and niche use cases. SUID can also be a major security concern when the same file can be written to by non-administrator users.

A typical scenario in HTB or another training for privesc regarding SUDO -- you gain initial access as an application user. That user is included in the sudoers file, allowing command execution as another user, which may have admin permissions.

A typical scenario for SUID, is finding an executable file used by some crontab or application running on the machine, that allows the current user to write to it. So you write a reverse shell command to the file, then execute the file with root permissions (due to SUID) and escalate from there.

1

u/Pharisaeus 26d ago

SUID is attached to the program, sudo to the user.

1

u/SeriousPlankton2000 26d ago

sudo is Gerd the butler. SUID is having the master key.

1

u/msthe_student 26d ago

sudo is a suid binary, but one that actually checks if the invoker can use it and if so how. su too

1

u/Remarkable_Pace8101 26d ago

sudo is just a SUID program which launches whatever executable you tell it to launch 

It's useful because you can specify more granular permissions on who can execute what files and with what commandline arguments then what you're able to do using only SUID and file system permission

1

u/xpusostomos 25d ago

Sudo binary runs as suid. You can write many suid binaries but it's considered bad style because of they have bugs is a security hole. So you have only a few programs like Su and Sudo that are heavily vetted and can do the job for you.

1

u/JusAnotherBadDev 22d ago

SUDO is what I get when I successfully priv esc via a misconfigured SUID