Skip to content
Memory corruption Write-up Intermediate

Exploiting PwnKit (CVE-2021–4034)

A memory corruption vulnerability in pkexec, a SUID-root program, allows any unprivileged user to gain root privileges. The exploit uses environment variables to load a malicious shared library, resulting in a root shell.

shivam_bathla Follow

Published on medium.com

Let’s explore and exploit a high-impact vulnerability, hiding in the plain sight for 12+ years, enabling privilege escalation to root!

Shivam Bathla, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely an out-of-bounds write when pkexec processes command-line arguments, allowing environment variables to be manipulated to load a malicious library.

What the attacker needed

Local access to a vulnerable Linux system; pkexec version 0.105 installed

The fix

Apply patches for this vulnerability immediately.

How it was found

  1. Check the system information to identify the OS and kernel version.
  2. Find all SUID binaries to locate pkexec.
  3. Check the version of pkexec to confirm it is vulnerable.
  4. Save the exploit code from Packet Storm into three files: Makefile, evil-so.c, and exploit.c.
  5. Compile the exploit using make.
  6. Run the exploit binary to obtain a root shell.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

pkexec is a program that lets users run commands as another user, like sudo. A bug in how it handles certain settings allows a normal user to trick it into running their own code with full administrator rights, giving them complete control of the computer.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by shivam_bathla

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.