Summary
SSH.NET's ScpClient can place attacker-controlled remote paths into the server-side scp command without safely neutralizing every shell metacharacter. When an application passes such a path to a shell-based SSH server, an attacker may execute commands with the privileges of the authenticated SSH user.
Affected context
The vulnerability occurs in applications using SSH.NET's ScpClient to send caller-controlled remote paths to a shell-based SSH server. Risk depends on the active IRemotePathTransformation and the parsing rules of the remote command interpreter; non-shell servers and paths fully neutralized by the selected transformation are generally outside the affected conditions.
Exploit preconditions
- Attack surface: Application functionality that invokes
ScpClientwith a remote path - Required access: Ability to influence or supply the remote path, plus an application-mediated authenticated SSH session
- Trigger point: Construction and execution of the server-side
scpcommand - Why exploitation is possible: The default path transformation may not neutralize all shell metacharacters for the target shell, allowing crafted path content to alter command interpretation
Why this happens
The issue is caused by embedding caller-controlled remote path data into a shell command while relying on a quoting transformation that is not safe for every remote command interpreter. This behavior maps to CWE-78, OS Command Injection, because data intended as a path can be interpreted as shell syntax when it crosses the command-execution boundary.
Potential impact
- An attacker may execute arbitrary commands as the authenticated SSH user.
- The attacker could read, modify, or delete data accessible to that account.
- The compromised account may be used to alter remote application or system state.
- Further compromise could occur if the SSH account has excessive privileges or reusable credentials.
General mitigation guidance
Mitigation generally focuses on preventing untrusted path data from becoming
shell syntax.
Common defensive patterns include:
- Prefer transfer APIs that avoid invoking a remote shell, such as SFTP where suitable.
- Use a shell-specific path transformation that safely quotes paths for the known remote shell.
- Avoid accepting arbitrary remote paths when an application can use fixed directories or allowlisted names.
- Validate paths against an application-defined policy before passing them to the SSH library.
- Use SSH accounts with the least privileges required for file-transfer operations.
- Keep remote shells and command permissions restricted when shell execution is not required.
- Treat quoting as interpreter-specific rather than assuming one transformation works across all server environments.
How teams detect issues like this
Organizations can look for this issue through:
- Static analysis rules identifying caller-controlled values passed to SCP or shell-command construction APIs.
- Code review checks for remote path transformations, especially use of default or interpreter-agnostic quoting.
- Tests covering shell metacharacters and the parsing behavior of each supported server shell, without relying solely on positive-path tests.
- Policy enforcement requiring allowlisted remote paths or shell-free transfer protocols for untrusted inputs.
- Runtime monitoring for unexpected command execution or unusual activity by SSH service accounts.
Automated code review and software composition analysis tools may help identify risky API usage and outdated dependency behavior.

