CVE-2026-120361 — FindBin-libs (5.4.0) — CWE-95
FindBin::Bin versions from 4.0.1 before 5.4.0 for Perl execute code from the script's directory name via a string eval. The module defines Bin by interpolating the script's directory, or the current directory for perl -e, into a single-quoted literal inside a string eval, without escaping. A single quote in any directory name ends the literal and the rest of the name is compiled as Perl code. FindBin::Bin is installed only on Perl 5.40 and later, and FindBin::libs loads it. An attacker who can name a directory can run code as any user who runs a script inside it.
FindBin::Bin versions from 4.0.1 before 5.4.0 for Perl execute code from the script's directory name via a string eval. The module defines Bin by interpolating the script's directory, or the current directory for perl -e, into a single-quoted literal inside a string eval, without escaping. A single quote in any directory name ends the literal and the rest of the name is compiled as Perl code. FindBin::Bin is installed only on Perl 5.40 and later, and FindBin::libs loads it. An attacker who can name a directory can run code as any user who runs a script inside it.
🎯 What is this vulnerability?
CWE‑95 – Improper Control of Generation of Code (Code Injection)
The FindBin::libs module (up to version 5.4.0) builds the special variable $FindBin::Bin by interpolating the script’s directory name into a single‑quoted Perl literal that is then passed to eval.
The code looks roughly like this (simplified):
my $dir = $FindBin::RealBin; # e.g. "/tmp/foo'; system('id'); #"
$FindBin::Bin = eval q{ '$dir' }; # eval is executed on the literalBecause the directory name is inserted without any escaping, a single quote (') in the directory name terminates the literal early. The remainder of the directory string is parsed as Perl code and executed by the eval. Thus, an attacker who can create a directory with a crafted name can inject arbitrary Perl code that will run with the privileges of any user who later executes a script that loads FindBin::libs.
The flaw is purely local – it requires the attacker to be able to create a directory that a script will later run from. No network‑based authentication or remote input is involved, which is why the CVSS score is 0/10 (NONE). However, the impact is severe once the local condition is satisfied.
⚡ Attack Chain
Below is a realistic, step‑by‑step chain that demonstrates how an attacker can exploit the flaw on a system running Perl 5.40+ with FindBin::libs ≤ 5.4.0.
| Step | Action | Technical Detail |
|---|---|---|
| 1. Reconnaissance | Identify the target environment. | Scan the system for Perl installations (perl -v) and list installed CPAN modules (perldoc -l FindBin::libs). Confirm the module version ($FindBin::libs::VERSION). |
| 2. Directory creation | Create a malicious directory name. | mkdir "malicious'; system('id'); #" <br> *The directory name contains a single quote, a semicolon, and a comment marker.* |
| 3. Script placement | Place a benign‑looking script inside the directory. | ``bash\ncat > malicious/script.pl <<'EOF'\nuse FindBin::libs;\nprint \"Hello from script\\n\";\nEOF\n` |
| 4. Execution | Run the script as an arbitrary user (e.g., a web‑app worker, cron job, or a normal user). | perl malicious/script.pl |
| 5. Code injection | The FindBin::libs module evaluates the directory name. | The eval sees malicious'; system('id'); # and executes system('id');`. |
| 6. Post‑exploitation | Arbitrary code runs as the script’s owner. | The attacker can spawn a shell, modify files, or perform privilege‑escalation if the script runs as a privileged user. |
Illustrative PoC (local)
# 1. Create malicious directory
mkdir "evil'; system('whoami'); #"
# 2. Create a script that uses FindBin::libs
cat > evil/script.pl <<'EOF'
use FindBin::libs; # Triggers the vulnerable eval
print "Script executed\n";
EOF
# 3. Run the script
perl evil/script.plExpected output
root
Script executedThe whoami command is executed by the eval, demonstrating that arbitrary Perl code can run with the privileges of the user who invoked the script.
Note: The PoC above is illustrative of the vulnerability class. The exact directory name and script contents can vary; the key is that the directory name contains a single quote that breaks out of the quoted string.
🌍 Real World Impact
| Impact | Assessment |
|---|---|
| Confidentiality | High – arbitrary code can read any file the script’s user can access. |
| Integrity | High – attacker can modify files, install backdoors, or tamper with configuration. |
| Availability | Medium – attacker can crash the script or the interpreter, potentially affecting services that rely on the script. |
Because the flaw is local, the vulnerability is most dangerous in environments where:
- Untrusted users can create directories that are later used by scripts (e.g., shared web‑app directories, user‑uploaded content that is executed).
- Scripts run with elevated privileges (e.g., root‑owned cron jobs, system services).
FindBin::libs≤ 5.4.0 (including 5.4.0 itself).- Only relevant on Perl 5.40+ (the module is shipped with Perl 5.40+).
- Upgrade to
FindBin::libs≥ 5.4.1 (or the latest release).
The patch changes the eval to use
In such scenarios, the attacker can achieve remote‑looking impact (e.g., a web‑shell) by simply placing a malicious directory on the server.
🛡️ Remediation & Mitigation
Affected Versions
Patch
quotemeta or a safer construction that escapes single quotes.cpan -U FindBin::libs # or use your distribution’s package managerWorkarounds (if upgrade is not immediately possible)
| Mitigation | How it helps |
|---|---|
| Restrict directory creation | Ensure that only trusted users can create directories that scripts may run from. |
Disable FindBin::libs | Remove or comment out use FindBin::libs; in scripts that do not need it. |
| Use a safer eval | If you control the script, replace the vulnerable line with a safe alternative, e.g.:
$FindBin::Bin = eval { $FindBin::RealBin }; # or use File::Spec::Functions| Audit scripts | Search for FindBin::libs usage and verify that the directory names are sanitized or come from trusted sources. |
Detection
| Indicator | Where to look |
|---|---|
| Unusual directory names | Filesystem listings that contain single quotes or other shell metacharacters (', ;, #). |
| Eval usage | Logs or code analysis tools that flag eval statements with interpolated variables. |
| Unexpected command execution | System logs (/var/log/auth.log, journalctl) showing id, whoami, or other commands executed by a Perl interpreter. |
If your environment uses a web server to run Perl scripts (e.g., CGI), you can add a simple audit rule:
# Bash example: log any Perl script execution that contains a single quote in its path
if [[ "$0" == *"'"* ]]; then
logger -p authpriv.warn "Potential FindBin::libs injection: $0"
fi⚠️ Urgency
| Factor | Assessment |
|---|---|
| CVSS | 0/10 (NONE) – local flaw, no network exposure. |
| CISA KEV | No. |
| Exploit Complexity | Low – requires only the ability to create a directory. |
| Potential Impact | High – arbitrary code execution as the script’s owner. |
| Patch Availability | Yes – patch released in 5.4.1. |
Priority: High for any environment where:
Bottom line:
FindBin::libs ≤ 5.4.0 contains a classic code‑injection flaw that can be triggered by a malicious directory name. The fix is to upgrade to a patched version or remove the vulnerable component. Until patched, restrict directory creation and audit script execution to mitigate the risk.[🤖 CVE Professor AI Security Engine]