LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   Local privilege escalation vulnerability in polkit's pkexec (https://www.linuxquestions.org/questions/linux-security-4/local-privilege-escalation-vulnerability-in-polkits-pkexec-4175706953/)

////// 01-25-2022 11:51 PM

Local privilege escalation vulnerability in polkit's pkexec
 
just stumbled onto this one.

https://isc.sans.edu/forums/diary/Lo...0214034/28272/

Quote:

Researchers from Qualys today published an advisory about a local privilege escalation vulnerability in the pkexec tool, that is installed as part of the Polkit (formerly PolicyKit) package.

This package is used for controlling system-wide privileges. The pkexec tool, which is a command line tool, is used to define which authorized user can execute a program as another user. As such, this is a critical tool and, due to requirement to control such privileges is installed as a SUID binary, as shown below:

$ ls -l /usr/bin/pkexec
-rwsr-xr-x 1 root root 31032 May 26 2021 /usr/bin/pkexec

As such, this is, of course, a prime target for an attacker.

syg00 01-26-2022 02:50 AM

Yeah, I've always had a hate-hate relationship with polkit. Yet something else to get in my way ... :shrug:

I saw Redhat had patches, but haven't chased it.

hazel 01-26-2022 03:45 AM

AFAIR pkexec is only used to run legacy programs that aren't "polkit-aware". So if these programs were launched with gksudo or kdesudo instead there wouldn't be a problem, would there? You could deactivate pkexec altogether: take off the exec bit, not the suid bit.

GazL 01-26-2022 05:50 AM

Yikes! they didn't think to check for the case that no args were passed. That's "Argument Parsing 101"!

On a SUID executable that's a pretty shocking omission.


Like syg00, I've always hated the concept of polkit. It's like a really bad version of sudo over dbus with a ugly as hell XML config format: what could possibly go wrong! Wasn't expecting something this basic however.

craigevil 01-26-2022 11:19 AM

Updated in Debian Sid.

suramya 01-26-2022 01:09 PM

The issue was there in Debian unstable and was fixed sometime within the past 6 days. (I had last updated the system 6 days ago and it was vulnerable when I checked). I did a dist-upgrade just now and the vulnerability has been fixed.

vtel57 01-27-2022 01:01 PM

Slackware has patched polkit as of yesterday. :)

shruggy 01-27-2022 01:30 PM

If you want to follow rolling out of updates in different distros, https://lwn.net/Alerts is a good place.

ondoho 01-29-2022 07:11 AM

Quote:

Originally Posted by GazL (Post 6322188)
Yikes! they didn't think to check for the case that no args were passed. That's "Argument Parsing 101"!

On a SUID executable that's a pretty shocking omission.

Indeed - I just entered "pkexec" without a command, it asks for a password, then gives me a root shell! Facepalming so hard right now.

hazel 01-29-2022 09:50 AM

I just tried in AntiX, which I last updated a week ago. pkexec without a command failed, giving the syntax help output. So that's all right then!

boughtonp 01-29-2022 10:49 AM


 
According to the linked blog post:
Quote:

Originally Posted by https://isc.sans.edu/forums/diary/Local+privilege+escalation+vulnerability+in+polkits+pkexec+CVE20214034/28272/
Now, there are three scary things about this vulnerability:

It has been around for 12+ years (!!!) since it was introduced in a commit to pkexec in May 2009
The affected version of pkexec is installed with all popular Linux distributions: Ubuntu, Debian, Fedora and CentOS
It is very simple to create the exploit, and it works 100% reliable

And according to another one:
Quote:

Originally Posted by https://www.gen.net.uk/about-us/news/48-packetstorm/18711-pwnkit-pkexec-local-privilege-escalation-vulnerability-discovered
What versions are vulnerable?

All Polkit versions from 2009 onwards are vulnerable.


But testing a not-yet-updated Debian machine, which reports pkexec as version 0.105 from 2012, it does not give a root shell (it gives the same output as --help does).

Either there is more to this vulnerability than just typing "pkexec" or the above pages are incorrect about what is affected?


////// 01-29-2022 11:48 AM

1 Attachment(s)
it asks for password when i try it.

Arch 5.15.16-hardened

ondoho 01-30-2022 04:58 AM

Quote:

Originally Posted by ////// (Post 6323178)
it asks for password when i try it.

Oh yes, mine too. I think I was a little too enraged in my last post (and edited for clarity now).
However, I can imagine scenarios with keyrings where it wouldn't ask and still give global superuser access.
But TBF, most apps opened with pkexec would also do that (terminal, text editor...).
On second glance it's not a big issue as long as it still asks for the password.

boughtonp 01-30-2022 09:07 AM

Quote:

Originally Posted by boughtonp (Post 6323150)
Either there is more to this vulnerability than just typing "pkexec" or the above pages are incorrect about what is affected?

The answer is that there's more to the vulnerability that just running the command; afaict, neither the --help message nor the password prompt are relevant (though perhaps the latter indicates a patched system? no idea).

Anyway, an attacker needs to create a file, then set a specific environment variable before executing pkexec, which - due to the broken argument parsing - results in it reading that file, and ultimately instructs pkexec to execute a command (e.g. /bin/sh) as root.

That's a bit vague/simplified on purpose, but a complete exploit can be done in less than a screenful of code (i.e. an attacker could potentially type it out in not much time, even if getting a file onto the system is locked down).


The fix is to upgrade polkit/pkexec to version 0.120 or higher - if for any reason you can't, you need to ensure "ls -l /usr/bin/pkexec" reports "-rwxr-xr-x" and not "-rwsr-xr-x"

If you get the latter, run "sudo chmod -s /usr/bin/pkexec" to prevent the exploit until you can get the patched version. (At which point, replace "-s" with "+s" to restore original permissions).


////// 01-30-2022 10:04 AM

Quote:

Originally Posted by boughtonp (Post 6323485)
The fix is to upgrade polkit/pkexec to version 0.120 or higher - if for any reason you can't, you need to ensure "ls -l /usr/bin/pkexec" reports "-rwxr-xr-x" and not "-rwsr-xr-x"

If you get the latter, run "sudo chmod -s /usr/bin/pkexec" to prevent the exploit until you can get the patched version. (At which point, replace "-s" with "+s" to restore original permissions).

uh oh, i were vulnerable.
Code:

[root@arch vile]# ls -l /usr/bin/pkexec
-rwsr-xr-x 1 root root 26456 Jan 25 22:04 /usr/bin/pkexec
[root@arch vile]# chmod -s /usr/bin/pkexec
[root@arch vile]# ls -l /usr/bin/pkexec
-rwxr-xr-x 1 root root 26456 Jan 25 22:04 /usr/bin/pkexec
[root@arch vile]#

thank you for clearing this up.


All times are GMT -5. The time now is 06:08 PM.