Drag and Pwnd: Leverage ASCII characters to exploit VS Code
Control characters in filenames or run configuration arguments can be interpreted by the terminal emulator as keyboard shortcuts, allowing an attacker to inject and execute arbitrary commands. An attacker could trick a user into dragging a malicious file into VS Code's terminal or opening a crafted configuration, leading to command execution.
portswigger.net
Published on portswigger.net
Control characters like SOH, STX, EOT and ETX were never meant to run your code - but in the world of modern terminal emulators, they sometimes do. In this post, I'll dive into the forgotten mechanics of ASCII’s transport control characters, how they shaped early computing, and how they're now being abused in…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application passes raw bytes from user-controlled input (filenames or arguments) directly to a pseudo-terminal without sanitising control characters, which the terminal interprets as editing commands.
Impact
An attacker could execute arbitrary commands on the victim's machine, but on Windows the risk is mitigated because the filesystem disallows control characters in filenames and VS Code defaults to PowerShell, which does not interpret them.
What the attacker needed
Victim drags a malicious file into terminal; attacker can create a file with control characters in name; VS Code with node-pty on macOS or Linux
The fix
Applications should sanitise or escape control characters before passing user-controlled input to a terminal.
How it was found
- Create a file with a name containing control characters and a command.
- Drag and drop the file into the VS Code terminal window.
- The terminal interprets the control characters, executing the embedded command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Terminals use invisible control characters for editing, like moving the cursor. If a filename contains such characters, the terminal may treat them as commands, so dragging a file into a terminal can run code. This is dangerous because the user only sees a filename, not the hidden commands.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.