Revisiting SSH Pass-Through (Re: Subsystem sftp invoked even though forced command created)

Damien Miller djm at mindrot.org
Thu Nov 12 10:05:37 AEDT 2026


On Tue, 10 Nov 2026, MCMANUS, MICHAEL P via openssh-unix-dev wrote:

> Folks,
> 
> Back in 2023, I started a thread here (reference Message-ID: https://marc.info/?i=CY8PR02MB92013A6E6F52D4F668EDDC9CD0DFA%20()%20CY8PR02MB9201%20!%20namprd02%20!%20prod%20!%20outlook%20!%20com) regarding a Remote Code Execution issue arising from the use of SSH Pass-Through as described in "Secure Automated File Transfer", ;login:, August 2005, pp. 14-17.
> 
> In July 2026, a Red Team exercise at my site drew attention to this issue. The key findings with respect to this issue are as follows:
> 
>   *   The premise of SSH Pass-Through is the use of a forced command to prevent remote execution of any command other than the forced command. This is supposed to disallow the use of other subsystems such as scp and sftp to bypass the forced command.
>   *   Unfortunately, on all Linux distributions (and this appears to be confined to the Linux platform), there appears to be an order of operations problem in which the SFTP subsystem overrides the use of a forced command. This behavior is not replicated on other OS platforms, but as mentioned in the prior thread, it is reproducible even when the OpenSSH source code is re-compiled on a Linux platform from scratch. This indicates (to me at least) that an interaction with glibc or some other fundamental library specific to Linux may be the culprit here.
>   *   The Red Team exercise indicated that the RCE issue stems from the ability of the attacker to misuse the embedded private key from the application package to replace the forced command with an executable of one's choosing via sftp.
>      *   This indicates a possible mitigation is to require the forced command to be:
>      *   outside the home directory of the user tasked with executing the forced command on the remote server,
>      *   owned by a different user ID from the one tasked with the upload, and not writable by the latter user, and/or
>      *   a compiled binary rather than a script (but that often defeats the purpose of SSH pass-through).
>   *   The suggested replacement for SSH pass-through in our current environment is TLS transport with mutual certificate authentication.
> 
> I'm sending this in hopes that the clues provided may be sufficient to salvage this useful transport mechanism if possible, with perhaps a deeper dive into the OpenSSH binary build than is possible for just me and my other priorities.

I'm pretty sure the ForcedCommand/command="" mechanism works as advertised.
We have good regression test coverage for this and I just checked it again
myself (OpenBSD and Debian) for both sftp and command execution sessions.

It's difficult to discern what is happening in your situation. Debug logs
(both client and server) from a perceived bypass of forced commands would
help immensely. It's probably best to do this in the context of a
https://bugzilla.mindrot.org bug so it can be properly tracked.

As a general comment, if a user has a forced command set and they are able
to modify the script or binary that that forced command points to, then
they can execute arbitrary commands. This is a misconfiguration that sshd
cannot solve - forced commands are shell statements and not necessarily
just paths to a script or binary, so sshd can't always inspect their
ownership and permissions.

-d


More information about the openssh-unix-dev mailing list