Skip to content
RCE Write-up Intermediate

Rediscovering CVE-2024–48990 and Crafting My Own Exploit

The needrestart tool on Ubuntu reads the PYTHONPATH environment variable from any running Python process and then launches a new Python interpreter with that variable set, allowing a local attacker to place a malicious importlib module in a controlled directory. When needrestart runs as root (e.g., during package upgrades), the attacker's code executes with root privileges, enabling a reverse shell.

medium.com

Published on medium.com

On November 19th, 2024, Qualys publicly disclosed five local privilege escalation vulnerabilities discovered in the needrestart binary that comes installed by default on Ubuntu Server installations. They disclose the technical details of these here, however, I will be attempting to rediscover CVE-2024-48990 prior to…

Ally Petitt, 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 the needrestart Python interpreter checker copies the PYTHONPATH environment variable from an untrusted process and then launches a new Python interpreter with that variable, allowing library path hijacking.

Impact

A local attacker could execute arbitrary code as root when needrestart is run with elevated privileges, for example during package upgrades.

What the attacker needed

Local access to the system; ability to run a Python process; needrestart runs as root (e.g., via package manager)

How it was found

  1. Create a directory with a fake importlib module containing malicious code in its __init__.py.
  2. Set PYTHONPATH to that directory and start a long-running Python process.
  3. Run needrestart (or trigger it via a package manager) as root.
  4. needrestart scans the attacker's Python process, reads its PYTHONPATH, and launches a new Python interpreter with that variable.
  5. The fake importlib module is imported, executing the attacker's code as root.

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.

needrestart is a program that checks which services need restarting after software updates. It looks at running Python programs and copies their environment settings, including a list of folders to search for Python modules. An attacker can set that list to point to a folder they control, containing a fake module that runs malicious code. When needrestart later runs as root, that code runs as root too.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.