Shift Happens: Uncovering Two Built-In Command Injections In Windows Context Menus
Rémi Gascou (Senior Security Researcher · Specter Ops)
Insomni'hack 2026 · Day 1 · Main Track
Overview
This talk details the discovery and exploitation of two built-in command injection vulnerabilities residing within Windows context menus, specifically targeting the "Open PowerShell window here" functionality. Authored by Rémi Gascou, a senior security researcher at SpecterOps, the research began serendipitously during routine system administration on a fully updated Windows 11 machine when creating a folder triggered an anomalous PowerShell traceback. Rather than dismissing it as a benign UI quirk, Gascou investigated the root cause, uncovering a decade-old architectural flaw in how Windows handles directory path substitution in shell command registry keys.

Key moments
- 0:00 Introduction and discovery of the context menu bug
- 2:00 Overview of Windows context menus and registry keys
- 6:00 Analyzing the PowerShell open-here command line structure
- 9:30 Tokenization and transition to command injection
- 14:00 Exploitation scenarios using folders and shortcuts
- 17:30 Bringing your own payload without backslashes
- 24:00 LLMs trained on vulnerable Stack Overflow code
- 28:15 Audience Q&A and third-party application impact
Shift Happens: Uncovering Two Built-In Command Injections In Windows Context Menus
Speakers: Rémi Gascou (Senior Security Researcher, Specter Ops)
Conference: Insomni'hack
YouTube: https://www.youtube.com/watch?v=MGiZSdLUaBc
Overview
This talk details the discovery and exploitation of two built-in command injection vulnerabilities residing within Windows context menus, specifically targeting the "Open PowerShell window here" functionality. Authored by Rémi Gascou, a senior security researcher at SpecterOps, the research began serendipitously during routine system administration on a fully updated Windows 11 machine when creating a folder triggered an anomalous PowerShell traceback. Rather than dismissing it as a benign UI quirk, Gascou investigated the root cause, uncovering a decade-old architectural flaw in how Windows handles directory path substitution in shell command registry keys.
The significance of these findings extends beyond a simple parameter injection. Gascou demonstrates how Windows shell command invocation patterns, specifically the handling of the -Command argument in PowerShell.exe, permit attackers to break out of intended argument boundaries. By leveraging NTFS naming rules and PowerShell tokenization mechanics, an attacker can elevate a positional parameter error into full arbitrary command or script execution. This security review underscores the latent risks in legacy UI integration patterns, standard administrative features, and the growing ecosystem of AI-generated code that continues to reproduce vulnerable registry command configurations.
Background
▶ Watch: Introduction and discovery of the context menu bug (0:00)
Windows context menus—both standard right-click menus and extended context menus accessed via Shift + right-click—rely heavily on definitions stored within the Windows Registry. For directory backgrounds, paths under Directory\Background\shell define actions such as opening a command prompt or PowerShell instance in the current working directory. To pass the target directory path into the spawned executable, Windows utilizes substitution templates like %V (or %L), which are dynamically replaced with the file system path of the clicked object at runtime.
Historically, Windows 10 utilized registry command templates wrapped in single quotes. However, because NTFS file systems permit single quotes within directory names, user-created folders containing single quotes routinely broke command strings, prompting bug reports across platforms like Stack Overflow for nearly a decade. To mitigate this, Microsoft migrated toward double-quoted templates. Despite this transition, legacy invocation patterns—specifically invoking PowerShell.exe -Command Set-Location -LiteralPath "..."—retained an underlying architectural vulnerability in how PowerShell tokenizes unquoted or concatenated argument lists.
Key Findings
▶ Watch: Analyzing the PowerShell open-here command line structure (6:00)
Gascou identified two distinct command injection vulnerabilities affecting Windows 10 and Windows 11 environments:
- Windows 11 Command Injection (CVE-Adjacent / Uncredited Fix): The Windows 11 "Open PowerShell window here" registry key used double quotes around the
%Vpath substitution parameter inside a-Commandblock. Because PowerShell tokenizes the entire argument string passed after-Commandby concatenating elements and evaluating them as code, an attacker who names a directory with a command separator (such as a semicolon;or subshell parentheses(...)) can inject arbitrary PowerShell instructions. - Windows 10 Single-Quote Injection: Present across all Windows 10 builds for roughly a decade, this variant utilized single quotes around the path template. Attackers could create folders containing single quotes to escape the intended string context and append arbitrary execution directives.
- LLM Training Dataset Poisoning: Because users have queried Stack Overflow about these parameter mismatch errors for ten years, Large Language Models trained on these repositories frequently generate vulnerable registry keys and command-line templates when prompted to create custom context menu extensions, falsely assuring developers that the configurations are secure.
Technical Deep Dive
▶ Watch: Exploitation scenarios using folders and shortcuts (14:00)
The root technical issue lies in how PowerShell.exe parses its command-line arguments when invoked via the registry. The vulnerable Windows 11 registry configuration executed a command line structured similarly to:
When a user triggers "Open PowerShell window here" on a directory whose name contains a command separator (e.g., folder; calc), the substitution engine replaces %V with the literal path:
PowerShell tokenizes arguments following -Command by joining list elements with spaces and evaluating the resulting string as PowerShell code. Consequently, the semicolon acts as a command separator, breaking the execution out of Set-Location and executing calc.exe.
To achieve arbitrary payload execution without violating NTFS restrictions—which forbid characters like backslashes (\) or trailing dots (.) in folder names—Gascou devised a clever variable-assignment technique. By constructing a directory tree containing intermediate folder names that assign a dot to a variable ($e=), an attacker can reconstruct a payload string at runtime:
By leveraging multi-level directory structures, an attacker can embed these variable assignments across parent folders. When the user opens PowerShell in the target working directory, PowerShell evaluates the chained commands, assigns the dot, references the payload via the ampersand execution operator (&), and successfully executes external binaries or bypasses script execution policies (-ep bypass) without raising user suspicion via obvious filename payloads.
Demo / Proof of Concept
▶ Watch: Bringing your own payload without backslashes (17:30)
While no live code execution was demonstrated interactively during the presentation, Gascou detailed end-to-end exploitation scenarios ranging from simple proof-of-concept calculator executions to multi-level project folder structures. In these scenarios, an attacker supplies a zipped development project containing nested directories with specially crafted names. When a victim opens a PowerShell window via the background context menu within the project directory, the nested path structure executes embedded payloads silently.
Defensive Implications
▶ Watch: Audience Q&A and third-party application impact (28:15)
Defenders and system administrators must audit custom context menu registry entries and application configurations to ensure they do not replicate vulnerable legacy patterns. Specific defensive actions include:
- Adopt
-WorkingDir: Microsoft ultimately resolved the built-in vulnerability by abandoning the-Command Set-Locationpattern entirely in favor of PowerShell’s native-WorkingDirectoryflag, which securely initializes the session path without evaluating a preparatory command string:
- Review Custom Shell Extensions: Security teams should audit third-party application registry keys under
HKEY_CLASSES_ROOT\Directory\Background\shelland COM object registrations to ensure path substitution parameters are strictly quoted and avoid executing raw interpreter arguments. - Scrutinize AI-Generated Code: Developers utilizing LLMs to generate registry tweaks or context menu installers must be explicitly trained to reject suggestions that pair PowerShell
-Commandwith unvalidated path variables.
Key Takeaways
- Windows context menus historically relied on registry command templates vulnerable to parameter and command injection via specially crafted directory names containing spaces, semicolons, or parentheses.
- PowerShell's tokenization behavior when processing arguments following
-Commandallows attackers to break out of literal path constraints (-LiteralPath). - NTFS naming limitations (such as the inability to use backslashes) can be bypassed by chaining multi-level directory structures and utilizing PowerShell variable assignment and execution operators (
&). - AI coding assistants frequently reproduce vulnerable registry command lines due to a decade of corrupted Stack Overflow training data.
- Microsoft has patched the built-in Windows 11 vector by switching to the secure
-WorkingDirectoryparameter, though legacy Windows 10 installations remain exposed.
About the Speaker(s)
- Rémi Gascou (Senior Security Researcher, Specter Ops): Rémi Gascou focuses on offensive security research with a strong interest in Windows internals and Active Directory. He created The Manticore Project and is the author or maintainer of several widely used open-source tools including Coercer, LDAPmonitor, FindUncommonShares, and smbclient-ng, among others.