Details
The crafted packet form is:
```text
SSH_MSG_CHANNEL_REQUEST(98)
recipient_channel = N
request_type = "exec"
command = "protected"
The PoC runs normal controls and exploit cases in one execution.
Allowed control
This proves the protected action works normally when a session channel is opened.
normal client: CHANNEL_OPEN session
normal client: session open confirmed
normal client: exec "protected"
channel_open_session called: 1
exec_request called: 1
protected action executed: 1
channel ever opened/confirmed: true
working recipient channel ids: [2]
Denied control
This proves the application policy denies session channels and a normal client cannot reach the protected action.
normal client: CHANNEL_OPEN session
normal client: session open denied
channel_open_session called: 1
exec_request called: 0
protected action executed: 0
channel ever opened/confirmed: false
working recipient channel ids: none
Main exploit: no channel open
This is the main issue.
The authenticated client does not send SSH_MSG_CHANNEL_OPEN. It sends crafted SSH_MSG_CHANNEL_REQUEST packets for recipient IDs 0..31.
malicious peer: no CHANNEL_OPEN sent
malicious peer: scanning recipient channel ids 0..31
channel_open_session called: 0
exec_request called: 32
protected action executed: 32
channel ever opened/confirmed: false
working recipient channel ids: [0, 1, 2, ..., 31]
This removes the "guessed channel ID" concern. Every scanned recipient ID reached the protected action in the vulnerable run.
Additional variant: denied open
The client asks for a session channel, the handler denies it, and the client then sends the same crafted requests.
malicious peer: CHANNEL_OPEN session
malicious peer: session open denied
channel_open_session called: 1
exec_request called: 32
protected action executed: 32
channel ever opened/confirmed: false
working recipient channel ids: [0, 1, 2, ..., 31]
The denied-open variant is not required for exploitability, but it shows the same state validation gap after an explicit application denial.
Affected code path
Verified at:
f1a0f180a02ccedf48d86f2c5e0361308cf6b7c6
v0.61.1-9-gf1a0f18
The affected logic is in:
russh/src/server/encrypted.rs
The vulnerable area is:
server_read_authenticated
Channel request dispatch decodes a recipient channel ID and calls request-specific handler callbacks without first requiring that the recipient ID exists as a confirmed channel in enc.channels.
The affected request callbacks include:
pty_request
x11_request
env_request
shell_request
agent_request
exec_request
subsystem_request
window_change_request
signal
The same missing established-channel guard affects:
CHANNEL_DATA
CHANNEL_EXTENDED_DATA
CHANNEL_EOF
CHANNEL_CLOSE
A related issue exists in:
server_handle_channel_open
Application channel references should not be retained for denied opens.
Why this belongs in russh
The application cannot reliably enforce the SSH transport channel lifecycle from inside individual callbacks. By the time exec_request is called, the application is already being told that a channel-scoped request exists. The library should not call that handler for a channel ID that does not exist in the confirmed channel table.
This is the same kind of invariant russh already applies for some channel state updates. The missing part is to apply the established-channel check consistently before all channel-scoped callbacks are dispatched.
The safe expectation is simple:
No established channel, no channel-scoped handler callback.
Suggested fix
Before dispatching any channel-scoped callback, require the recipient ChannelId to exist in the encrypted session's established channel table and to be confirmed.
The authoritative check should use enc.channels, not self.channels.
A minimal approach is to add a helper like:
fn ensure_established_channel(&self, channel: ChannelId) -> Result<(), Error> {
if self
.common
.encrypted
.as_ref()
.and_then(|enc| enc.channels.get(&channel))
.is_some_and(|channel| channel.confirmed)
{
Ok(())
} else {
Err(Error::Inconsistent)
}
}
Then call it before dispatching channel-scoped callbacks for:
CHANNEL_REQUEST
CHANNEL_DATA
CHANNEL_EXTENDED_DATA
CHANNEL_EOF
CHANNEL_CLOSE
CHANNEL_WINDOW_ADJUST
For unknown or unconfirmed channels, russh should not call application callbacks. The exact wire response can be request failure, ignore, or disconnect depending on the existing protocol-error handling for that message type.
The channel-open path should also retain application-side channel references only when the open is approved:
let mut result = handler.channel_open_session(channel, self).await;
if let Ok(allowed) = &mut result {
if *allowed {
self.channels.insert(sender_channel, reference);
}
self.finalize_channel_open(&msg, channel_params, *allowed)?;
}
Regression coverage
A regression test should authenticate normally, then verify that callbacks are not reached in these cases:
1. CHANNEL_REQUEST "exec" without prior CHANNEL_OPEN
2. CHANNEL_OPEN "session" denied by the handler, then CHANNEL_REQUEST "exec"
3. CHANNEL_DATA without prior CHANNEL_OPEN
4. CHANNEL_EOF / CHANNEL_CLOSE without prior CHANNEL_OPEN
The test should fail if any channel-scoped callback such as exec_request, shell_request, subsystem_request, data, channel_eof, or channel_close is invoked for a non-established channel.
A positive control should confirm that a normally opened session channel still reaches the expected callbacks.
In the local validation, the targeted regression passed after the patch:
cargo test -p russh --test channel_state_validation
The full workspace also passed:
cargo test --workspace
Duplicate check
I checked existing Eugeny/russh advisories and issue searches for terms related to:
CHANNEL_REQUEST
exec_request
channel_open_session denied
unopened channel
server_handle_channel_open
channel request handler
Existing advisories cover unrelated authentication, parser, allocation, window-adjust, Terrapin, and cryptographic issues. I did not find an existing advisory or issue for channel-scoped callbacks being dispatched for unopened or denied recipient channel IDs.