Pwnkit: Local Privilege Escalation in polkit's pkexec
qualys.com
qualys.com
for (n = 1; n < (guint) argc; n++)
Usually, after that loop, n equals argc (or could be less than argc if the loop breaks or something). But if argc is 0, then n will equal 1 after. Later on, the program writes to argv[n]. If argc is 0, then argv[n] is argv[1], which is out-of-bounds, but happens to refer to the same place as envp[0] (at least on Linux). This lets the attacker set an arbitrary environment variable, after ld.so(8) already sanitized the environment. In particular, setting the GCONV_PATH environment variable (which is one that would have been removed during sanitization) will cause pkexec to load and execute code from a .so file in an attacker-controlled directory.It seems possible the current exploit authors read this and picked up from there..."what else could we do given that we can't pass options?"
https://gist.github.com/pothos/73dd4f7694acc3b6bbed614438f6e...
Since polkit is used (but not the setuid pkexec, this was the point of this exercise) there is still one setuid binary invoked for the PAM check, though.
> If a command is run as transient scope unit, it will be executed by systemd-run itself as parent process and will thus inherit the execution environment of the caller. (...) This mode is enabled via the --scope switch
By comparison, the manual to doas.conf is pretty short: https://man.openbsd.org/doas.conf.5
It seems like OpenBSD was also stuck on an older version of sudo when it was removed. It's possible they just weren't having all the churn of such a large tool? But then they also missed a bunch of important fixes: https://marc.info/?l=openbsd-bugs&m=142270265216628&w=2
More: https://marc.info/?l=openbsd-ports&m=143465998814989&w=2
> It is also possible to use polkit to execute commands with elevated privileges using the command pkexec followed by the command intended to be executed (with root permission).[7] However, it may be preferable to use sudo, as this command provides more flexibility and security, in addition to being easier to configure.[8]
> A memory corruption vulnerability PwnKit (CVE-2021-4034[10]) discovered in the pkexec command (installed on all major Linux distributions) was announced on January 25, 2022.[11][12] The vulnerability dates back to the original distribution from 2009. The vulnerability received a CVSS score of 7.8 ("High severity") reflecting serious factors involved in a possible exploit: unprivileged users can obtain full root privileges, independent of the underlying machine architecture, regardless of whether the polkit daemon is running or not.
Does a lot of software depend on pkexec? How could it be secured to be recommended over sudo?
If I try to remove polkit here, it would result in the loss of various parts of KDE and Gnome, PCManFM, and virt-manager. I'm not sure if it's a hard dependency, a dependency of a dependency, or what. I'm also not sure if they use pkexec specifically.
`suid` binaries exist for a good reason: they allow users to escalate their privilege in limited ways under control of the system. Good, but obviously risky if the user can subvert that control. The offered solution to that risk is where the problem comes in. Developers of suid binaries are just asked to write them really, really carefully. There are some documents to describe how to do it carefully, but they pretty much assume that code can be developed without bugs, as long as we're careful enough. At least initially, there was no help, no tooling, no verification, no testing, nothing. Just real, real careful.
Unfortunately, instead of seeing the absurdity of that situation, many people have gone all "no true Scotsman" on it. "If you were a real Unix Developer then you wouldn't make mistakes like that." We don't need no stinking tools, we're Real Programmers.
The situation has been improving, but the underlying mechanism is still super popular and here to stay. It's either time to stop pretending that local `root` means anything, or start taking stuff like this much much more seriously. Some people sure are, but it hasn't pervaded the culture yet.
As an example, although one that practically seems to have turned out harder to do than the authors expected, take a look at HiStar: http://www.scs.stanford.edu/histar/
There are lots of ways to improve the current state of security.
That is the problem. Unix, and the 'philosophy'.
I used to like it, but it is over half a century old and as well as everything 'unix-like' it was not designed for security, especially the C programming language. Thus, with everything 'unix-like', they have imported all the mistakes with it. The same with the legacy like X11, allowing root to modify system files, etc.
Unix is dead. Might need to move on from such prehistoric systems to ones that are designed for security that are not 'Unix'.
There's the actual "No True Scotsman", because capability based kernels exist for a long time now. Yet, users want something to work with, actual software that needs to be written, that doesn't even have to be in C.
The expressed sentiment is entirely independent of the domain. You simply need to know what you are doing or things won't move forward. It's only consequential that those whom rely on Unixoid systems for whichever reason do express this sentiment in terms of those systems.
The alternative are walled gardens, where criticizm is impossible. Because with secure boot and the like it would require breaking the system to take control.
But it wasn't available as free tapes for universities to play with, so....
# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 36760 Feb 16 2020 /usr/bin/passwd
The setuid permission on that program allows it to escalate to root for part of it's runtime.Why are we doing this?
I could make a new "passwd" user, and assign it a non-zero UID and GID, setuid to that user instead, making it own this file:
# ll /etc/passwd
-rw-r--r--. 1 root root 3346 Apr 8 2021 /etc/passwd
UNIX in general seems to have a root fixation on setuid. Both passwd and shadow users should exist, with separate roles and privileges, and root users should not be held in either of their databases.> root users should not be held in either of their databases
Where would you propose keeping the information for UID 0?
/etc/passed.root
/etc/shadow.root
/etc/group.root
I don't know if the handling of the "wheel" group should be any different. It's still enforced on OpenBSD for su.Looking at other suids in /bin...
Compromise mount, game over.
Compromise su, game over.
arping? ping? Dunno; they can generating normally-prohibited packets.
umount? Hmmm.... feels like some kind of clever trick lurking here.
As for kernel subsystems, there's very little which cannot lead to full system compromise, either directly or indirectly by tricking a user.
pkexec a program bundled with but not really part of Polkit is suid as the method it uses to gain elevated privileges rather than running a daemon.
The following should be the output of "find / -type f -perm -4000 -o -perm -2000" on a VM. If it is a container, you might need an "su" and/or "sudo" and maybe, if for some reason you are using a cron internal to the container (but why?!), crontab.
/usr/bin/chfn
/usr/bin/chage
/usr/bin/chsh
/usr/bin/sudo
/usr/bin/crontab
/usr/bin/su
/usr/bin/ssh-agent
/usr/bin/newgrp
/usr/bin/passwd