Skip to content
RCE Write-up Intermediate

SSH ProxyCommand == unexpected code execution (CVE-2023-51385)

SSH's ProxyCommand feature does not sanitise hostnames, so a malicious hostname containing shell metacharacters can lead to command execution when a user connects to it. An attacker could craft a hostname that executes arbitrary commands on the victim's machine.

Vin01 Follow

Published on vin01.github.io

SSH’s ProxyCommand is a feature quite widely used to proxy ssh connections by allowing to specify custom commands to be used to connect to the server. Arguments to this directive may contain tokens like %h, %u which refer to hostname and username respectively.

Vin01, on vin01.github.io

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

Impact

An attacker could execute arbitrary commands on a victim's machine when the victim connects to a malicious hostname, though the text only demonstrates a calculator popping up.

What the attacker needed

Victim uses ProxyCommand with %h; victim connects to attacker-controlled hostname

How it was found

  1. Add a ProxyCommand line using %h to your SSH config.
  2. Clone the proof-of-concept repository with submodules.
  3. Connect to the malicious hostname to trigger command execution.

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.

SSH is a tool for securely connecting to other computers. Its ProxyCommand setting lets you run a command to reach a server, and it inserts the server's hostname into that command. If the hostname is controlled by an attacker and contains special characters, those characters can break out of the intended command and run something else on your computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Vin01

View all

3 more disclosed reports, best first.

More from OpenSSH

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.