CVE-2025-59042: PyInstaller - Code Injection & Local Privilege Escalation
- Cve: CVE-2025-59042
- Name: PyInstaller - Code Injection & Local Privilege Escalation
- Description: PyInstaller bundles a Python application and all its dependencies into a single package. Due to a special entry being appended to `sys.path` during the bootstrap process of a PyInstaller-frozen application, and due to the bootstrap script attempting to load an optional module for bytecode decryption while this entry is still present in `sys.path`, an application built with PyInstaller < 6.0.0 may be tricked by an unprivileged attacker into executing arbitrary python code when **all** of the following conditions are met. First, the application is built with PyInstaller < 6.0.0; both onedir and onefile mode are affected. Second, the optional bytecode encryption code feature was not enabled during the application build. Third, the attacker can create files/directories in the same directory where the executable is located. Fourth, the filesystem supports creation of files/directories that contain `?` in their name (i.e., non-Windows systems). Fifth, the attacker is able to determine the offset at which the PYZ archive is embedded in the executable. The attacker can create a directory (or a zip archive) next to the executable, with the name that matches the format used by PyInstaller's bootloader to transmit information about the location of PYZ archive to the bootstrap script. If this directory (or zip archive) contains a python module whose name matches the name used by the optional bytecode encryption feature, this module will be loaded and executed by the bootstrap script (in the absence of the real, built-in module that is available when the bytecode-encryption feature is enabled). This results in arbitrary code execution that requires no modification of the executable itself. If the executable is running with elevated privileges (for example, due to having the `setuid` bit set), the code in the injected module is also executed with the said elevated privileges, resulting in a local privilege escalation. PyInstaller 6.0.0 (f5adf291c8b832d5aff7632844f7e3ddf7ad4923) removed support for bytecode encryption; this effectively removes the described attack vector, due to the bootstrap script not attempting to load the optional module for bytecode-decryption anymore. PyInstaller 6.10.0 (cfd60b510f95f92cb81fc42735c399bb781a4739) reworked the bootstrap process to avoid (ab)using `sys.path` for transmitting location of the PYZ archive, which further eliminates the possibility of described injection procedure. If upgrading PyInstaller is not feasible, this issue can be worked around by ensuring proper permissions on directories containing security-sensitive executables (i.e., executables with `setuid` bit set) should mitigate the issue.
- Impact: Unprivileged attackers can execute arbitrary Python code and escalate privileges locally if the executable runs with elevated rights.
- Remediation: Upgrade to PyInstaller 6.0.0 or later, preferably 6.10.0 or newer.
- Vulnerability impact: remote_code_execution, privilege_escalation
- Requirements: Attacker must create files/directories with specific names next to the executable and determine PYZ archive offset.
- Labels source: projectdiscovery
- Severity: high
- Cvss score: 7
- Cvss vector: CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
- Epss score: 0.00126
- Epss percentile: 0.02243
- Assignee: [email protected]
- Published at: 2025-09-09T23:15:37Z
- Age in days: 441
- Modified at: 2026-10-23T22:10:00Z
- Patch available: yes
- References total: 2
- Products total: 1
- Oss: yes
- Projects total: 1
- Advisory url: https://nvd.nist.gov/vuln/detail/CVE-2025-59042
- Nvd status: deferred
- Checked, none or zero: known exploited entries, nuclei templates, public exploits total, public exploits capped, public exploits, rejected by nvd
- Not known: vulnerability type, requirement type, hackerone
Cwe
| Id | Name |
|---|---|
| CWE-94 | Improper Control of Generation of Code |
References
| Url | Source | Tags |
|---|---|---|
| https://github.com/pyinstaller/pyinstaller/commit/f5adf291c8b832d5aff7632844f7e3ddf7ad4923 | nvd | |
| https://github.com/pyinstaller/pyinstaller/security/advisories/GHSA-p2xp-xx3r-mffc | nvd |
Products
| Product | Affected | Platform bound | Sources | Url |
|---|---|---|---|---|
| pyinstaller:pyinstaller | < 6.0.0 | no | cna_alias_text | /v1/products/pyinstaller/pyinstaller |
Projects
| Repository | Link kinds | Indexed | Url |
|---|---|---|---|
| pyinstaller/pyinstaller | commit, fix, package, security_advisory | yes | /v1/repositories/pyinstaller/pyinstaller |
Index
- Repositories: 65
- Repositories high signal: 52
- Packages: 1
Exploitation
- Authentication required: yes
- Checked, none or zero: known exploited, known exploited by, exploitation seen, public exploit, public exploit count, initial access, remote
- Not known: known exploited since, vulncheck known exploited since, public exploit first date, nuclei template, initial access since, hackerone reports, exposed hosts