Summary
SSH.NET's SCP download routine trusts file and directory names supplied by a remote server when constructing local paths. A malicious, compromised, or intercepted SSH/SCP endpoint may use traversal sequences or absolute paths to create or overwrite files in locations writable by the client process.
Affected context
The vulnerability occurs when an application uses SSH.NET's ScpClient.Download method to retrieve files from an SCP server and the client process has write access to local filesystem locations outside the intended download directory. Risk depends on whether the remote endpoint, its traffic, or the names it returns can be controlled or altered.
Exploit preconditions
- Attack surface: SCP file and directory download handling in the .NET client
- Required access: Ability to operate, compromise, or influence the remote SCP server or the connection path
- Trigger point: Processing remote file or directory names during
ScpClient.Download - Why exploitation is possible: Returned names are combined with the requested local directory without verifying that the resulting path remains within the intended destination
Why this happens
The underlying bug is insufficient containment validation when converting attacker-influenced remote names into local filesystem paths. Path-combination logic may interpret ../ components or absolute paths as locations outside the requested directory, allowing remote input to control the final write destination. This maps primarily to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, with CWE-73: External Control of File Name or Path also relevant because external data influences local path selection.
Potential impact
- An attacker may create or overwrite files in directories writable by the client process
- Application configuration, credentials, or operational data could be modified
- The client process could be disrupted through destructive file replacement
- Subsequent execution of overwritten files could enable broader compromise, depending on host permissions and application behavior
General mitigation guidance
Mitigation generally focuses on treating all remote filenames as untrusted and enforcing destination containment before any filesystem operation.
Common defensive patterns include:
- Resolve the candidate destination to a canonical path and verify it remains beneath the intended download directory
- Reject absolute paths, parent-directory traversal components, and other ambiguous path forms
- Prefer secure-by-default APIs that accept a fixed destination root and do not expose unrestricted path composition
- Use allowlists for expected filename and directory formats where practical
- Run the client with only the filesystem privileges required for its task
- Store downloaded content in isolated, non-sensitive directories and avoid executing downloaded files
- Protect the SSH connection and server trust configuration to reduce exposure to malicious or intercepted endpoints
How teams detect issues like this
Detection can combine static analysis, code review, runtime monitoring, and policy enforcement.
- Search for filesystem writes whose paths include remote protocol fields or other externally controlled strings
- Review uses of path-combination APIs for canonicalization and containment checks
- Flag acceptance of absolute paths, parent-directory segments, or unusual separator encodings
- Add tests that exercise traversal, rooted, mixed-separator, and normalization edge cases
- Monitor client processes for writes outside approved download roots
- Enforce repository policies requiring path validation before externally influenced file operations
- Automated code-review and security-analysis tools may help identify uncontrolled path construction

