News for hackers. Stuff that matters.
Re:Don't abuse su for dropping user privileges (2015) by kazinator on Friday May 26, 2023 @01:49PM (#36087451)
This article is nonsense. I'm afraid.

Firstly, the su program isn't standardized by POSIX, so everything we say about it is system-dependent.

On the systems where that trick is used, su is documented as having that feature.

When su is executed by root (so that its setuid bit is moot), it knows this, and allows a credentials change to a specified account without prompting for a password. This is a feature and the example cron jobs are using it correctly to obtain their desired effect of impersonating that user.

su is not "dropping privileges"; it's impersonating a specific user, in a command dispatched from a root cron job or other script.

Thus all that might be wrong is the rhetoric used to describe the scripts, not what the scripts are actually doing, and only if we are nitpicky.

"Dropping privileges" has a strict meaning, referring to the situation that some user bob invoked a setuid root executable, which then disrobes itself of the root privilege, changing its effective-root uid to just bob again.

When root changes to another account that is unrelated to the real user ID, nevertheless, that situation fits the description of "dropping privileges" because that account is strictly less privileged than root.

> The right way ... Create a small wrapper binary with C

That's a silly nonstarter.

> The new implementation called fork() and only dropped privileges in the child, retaining a privileged account parent process that could call the PAM "user session" cleanup function once the child exited.

Privileged parents waiting for unprivileged children to terminate is an established pattern in Unix-like systems.

E.g. PID 1 (init or systemd) is privileged and handles the termination of everything that has no parent.

The author is not connecting the dots here: reporting some actual privilege escalation bug in the use of "su bob command ...".

Interactively, when you are root, you can do this:

  root # su bob
  /home/bob$ exit
  root #
This exit back to root is not a security hole, and it is not relevant to the scripted scenario at all. Bob has not actually gained root access. The order of messages on the TTY isn't what determines the security context semantics.
Re:Don't abuse su for dropping user privileges (2015) by TacticalCoder on Friday May 26, 2023 @02:43PM (#36088085)
> This exit back to root is not a security hole

Wait... Doing just "su bob" is vulnerable to a known decades old exploit. You should do either "exec su bob" or "su -P bob" or you just gave bob root rights on every Linux kernel older than 6.2 (and I think on 6.2 and more recent the default is still insecure?).

It's explained here with a simple PoC exploit (I tried the exploit and it works/worked) and it's been frontpage on HN in the past I think:

https://www.errno.fr/TTYPushback.html

Re:Don't abuse su for dropping user privileges (2015) by hulitu on Friday May 26, 2023 @04:54PM (#36089402)
> Consider this python sample and assume it’s automatically being run at logon from the .bashrc of a technical account, such as postgres, to which the root user changes by typing su - postgres

From su man page: "su is mostly designed for unprivileged users, the recommended solution for privileged users (e.g., scripts executed by root) is to use non-set-user-ID command runuser(1) that does not require authentication and provides separate PAM configuration. If the PAM session is not required at all then the recommended solution is to use command setpriv(1)."

Re:Don't abuse su for dropping user privileges (2015) by erik_seaberg on Friday May 26, 2023 @10:31PM (#36091527)
Why does PAM have sessions? I thought it was a layer of indirection over whether you’re using a password file or NIS or LDAP to verify passwords.
Re:Don't abuse su for dropping user privileges (2015) by yrro on Sunday May 28, 2023 @10:02AM (#36104063)
PAM provides authentication, authorization, session management and password changing.
Re:Don't abuse su for dropping user privileges (2015) by kazinator on Friday May 26, 2023 @07:05PM (#36090485)
I think that with that ioctl in place, once root hands the TTY file descriptor to processes in the bob security context, it can no longer trust that TTY object to be secure. Doing an "exec su ..." doesn't necessarily fix it, unless that has the effect of destroying the session (logging out). If root keeps using that TTY and trusting its input, it's a problem.

Say you want to fix the problem, while continuing to support that dubious ioctl. What you need is the ability for the TTY driver to send a SIGKILL to every user bob process that has an open file descriptor to that TTY. After killing all those processes, then restore the original TTY settings before the su command was run using tcsetattr with TCSAFLUSH to throw away any pushed input.

Even then, there could be exploits that use weaknesses in the terminal emulator to reflect input.

Also, social engineering hacks. The same human that operated the root shell is su'd into bob, and malicious software installed by bob can fool that human. For instance, by simulating a system login prompt.