Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CVE-2025-4138_tarfile_filter_bypass — CVE-2025-4138 - Python Arbitrary file write outside extraction directory | Kitploit
Tools/GitHubGitHub/thefizzyfish/cve-2025-4138_tarfile_filter_bypass
Payload GenerationVulnerability AnalysisExploitationWeb Application ExploitationCTFPenetration Testing
GitHubthefizzyfish/cve-2025-4138_tarfile_filter_bypass

CVE-2025-4138_tarfile_filter_bypass

CVE-2025-4138 - Python Arbitrary file write outside extraction directory

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share
View Repository
36 months agoNot yet reviewed

CVE-2025-4138 — Python tarfile filter="data" Bypass

Arbitrary file write outside the extraction directory via PATH_MAX symlink chain.

Affected Versions

  • Python 3.12.0 – 3.12.10
  • Python 3.13.0 – 3.13.3
  • Fixed in 3.12.11 / 3.13.4

Credit:

Reporter: Caleb Brown (Google)

How It Works

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:

  1. Symlink chain — 16 levels of long directories (247 chars each) with short symlink aliases (a→ddd..., b→ddd...). Inflates the resolved path to ~3968 bytes.
  2. Pivot symlink — ../ × 16 at the end of the chain. realpath() overflows and can't resolve it. Kernel walks back to the extraction root.
  3. Escape symlink — Routes through the pivot, up to /, and down to the target directory.
  4. Payload file — Written through the escape symlink to the target path as root.

Usage

To add/replace authorized_keys for root user

Create SSH key in /tmp

root@kitploit:~
ssh-keygen -t ed25519 -f /tmp/key -N ""

Create evil.tar file

root@kitploit:~
python3 CVE-2025-4138_tarfile_filter_bypass.py \
    -o evil.tar \
    -t /root/.ssh/authorized_keys \
    -p /tmp/key.pub \
    -m 0600
FlagDescription
-o

References

  • NVD — CVE-2025-4138
  • GHSA-hgqp-3mmf-7h8f

For authorized security testing and CTF use only.

Download Tool
Output tar path
-tAbsolute path of file to write on target
-pLocal file to use as payload content
-mOctal file permissions (default: 0644)