Visual Studio Code Remote Development Extension 1.50 failed to sanitize the host field before using it as an argument of the
ssh command, allowing to inject a
ProxyCommand option which could be used to run arbitray commands.
Visual Studio Code Remote Development allows you to use a container, remote machine, or the Windows Subsystem for Linux (WSL) as a full-featured development environment.
No source code needs to be on your local machine to get these benefits. Each extension in the Remote Development extension pack can run commands and other extensions directly inside a container, in WSL, or on a remote machine so that everything feels like it does when you run locally.
An argument injection is present in the “Remote - SSH” extension, which is used and installed by the “Remote Development” one.
This extension uses the SSH binary of the host to setup the connection with the remote host.
One of the ways to trigger the SSH connection is to use the
vscode:// URI scheme. Specifically, the format is the following:
Once a user browses an URI as the previous one, VSCode is opened and the extension tries to connect to the
While connecting the following command is executed:
ssh -T -D $RANDOM_PORT "$REMOTE_HOST" bash
As no sanitization is performed on the
$REMOTE_HOST user-supplied input it is possible to inject arbitrary arguments to the SSH binary.
SSH has an option called
ProxyCommand, which specifies a command which is executed before performing the actual SSH connection.
Combining all together it is possible to execute arbitrary system commands on the host of a victim by forcing them into opening a malicious link.
vscode://vscode-remote/ssh-remote+-oProxyCommand=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -c msg %username% command_injection" "firstname.lastname@example.org+/a
The same attack can be reproduced on Linux and MacOS by editing the ProxyCommand.
An attacker able to force a victim into visiting a malicious link could execute arbitrary commands on their system.
Upgrade the Visual Studio Code Remote Development Extension to version 1.51 or higher.
Abdel Adim `smaury` Oisfi of Shielder
This advisory was first published on https://www.shielder.com/advisories/remote-command-execution-in-visual-studio-code-remote-development-extension/
24 September 2021