Pwnkit: How to exploit and check
- 4 minutes read - 764 wordsPwnkit is a vulnerability that uses a bug in polkit
to elevate permissions to root. This write-up shows how
to reproduce it using Ubuntu and what to do to check whether a system is vulnerable.
What went wrong?
Quoting from the original researchers:
This vulnerability is an attacker’s dream come true:
- pkexec is installed by default on all major Linux distributions;
- pkexec is vulnerable since its creation, in May 2009;
- any unprivileged local user can exploit this vulnerability to obtain full root privileges;
- although this vulnerability is technically a memory corruption, it is exploitable instantly, reliably, in an architecture-independent way;
- and it is exploitable even if the polkit daemon itself is not running.
It doesn’t take long to find a GitHub repository that contains an exploit, and looking through the code, it looks pretty straightforward.
Important Note - always read through the code of any exploit you find on the Internet. If you don’t understand what it’s doing, DO NOT blindly run it.
The repository contains the following:
- README: with some instructions
- Makefile: builds the code
- cve-2021-4043.c: main program for running the exploit
- pwnkit.c: library code
All in all 50 lines of code and build instructions. Sounds very simple.
Trying out the exploit
To try out the exploit, I checked the Ubuntu page for CVE-2021-4034 and found that 18.04 was patched while 21.04 was no longer supported.
So first, I stood up a container and dependencies to build the files for the exploit:
|
|
In the ubuntu docker container I had to install policykit-1
as the docker image was pretty minimal, but it polkit
is pretty standard.
Next I created a standard user:
|
|
Then I logged in as that user
|
|
To build the exploit, get all the files from the above repository, then use make
to build
|
|
And then run it:
|
|
The above is an indication that the exploit didn’t work - pkexec
is patched.
Verify the exploit
To verify that the exploit works, I started Ubuntu 21.04 (no longer supported)
|
|
Then I created the testuser
again and transferred the contents the built exploit onto the system
|
|
And then ran it again:
|
|
Success!
Checking versions
One gotcha I found with this was when I looked for an easy way to check whether polkit
is vulnerable:
|
|
is NOT the right way to do this. I found that when trying a vulnerable image and a patched one, the version came back as the same.
The better way I found was to use (this was ubuntu):
Vulnerable:
|
|
Not vulnerable:
|
|
Compare the version numbers with the information on this page
Conclusion
As this is not a vulnerability that can be remotely triggered, I don’t think this should mean panic stations on log4shell levels, but the public availability of the exploit, the ease of exploiting it and the fact it applies to most distributions should mean only one thing: get patching!
Tags ubuntu securityIf you'd like to find more of my writing, why not follow me on Bluesky or Mastodon?