CVE-2026-138376 — Ronf Asyncssh — CWE-287
AsyncSSH 1.13.1 before 2.24.2 contains an improper authentication vulnerability in SSHConnection._match_known_hosts that accumulates trusted client host keys across host-based authentication attempts on one connection. With trust_client_host enabled, attackers holding one known client host's private key can retry naming another known host and log in as users authorized only from that host.
AsyncSSH 1.13.1 before 2.24.2 contains an improper authentication vulnerability in SSHConnection._match_known_hosts that accumulates trusted client host keys across host-based authentication attempts on one connection. With trust_client_host enabled, attackers holding one known client host's private key can retry naming another known host and log in as users authorized only from that host.
🎯 What is this vulnerability?
This vulnerability is a logic flaw in host-based authentication state management within the AsyncSSH Python library. Specifically, it affects the SSHConnection._match_known_hosts method.
Technical Flaw:
When trust_client_host is enabled (a feature allowing the server to trust client host keys for authentication), the library fails to properly isolate or reset the set of "trusted" client host keys between different authentication attempts on the same SSH connection.
1. State Accumulation: The method accumulates trusted client host keys. If an attacker presents a valid host key for Host A, that key is added to the internal trusted set for that connection session.
2. Lack of Reset: When the attacker subsequently attempts to authenticate as a different user or claims to be from Host B, the previously trusted key for Host A remains in the trusted set.
3. Bypass Mechanism: If the server's authorized_keys or host-based authentication configuration allows access from Host B, and the attacker can somehow satisfy the host key check for Host B (or if the logic incorrectly allows the accumulated trust from Host A to satisfy the requirement for Host B due to improper scoping), the authentication succeeds.
Essentially, the server confuses "I have seen a valid key for Host A" with "The current connection is from a trusted host," allowing an attacker who possesses the private key for any known client host to potentially authenticate as users authorized only from other known hosts, provided the connection context allows the state to persist.
CWE-287 (Improper Authentication): The system fails to properly verify the identity of the client by relying on accumulated state rather than the specific host key presented in the current authentication attempt.
⚡ Attack Chain
1. Discovery & Reconnaissance
- Target Identification: Identify services running
AsyncSSH(common in Python-based SSH servers, IoT devices, or custom automation frameworks). - Version Check: Use
nmapwith thessh2script or manual banner grabbing to identify theAsyncSSHversion.
nmap -sV -p 22 --script ssh2 <target_ip>
# Look for "SSH-2.0-AsyncSSH_1.13.1" or similartrust_client_host is enabled. This is often a non-default setting, so it requires specific server configuration. An attacker might attempt to connect and observe if host-based authentication is accepted.2. Exploitation
Prerequisites:trust_client_host is enabled on the server.Mechanism:
1. The attacker initiates an SSH connection to the target.
2. The server requests the client host key.
3. The attacker presents the valid private key for Host A.
4. The server verifies Host A's key and adds it to the internal trusted set for this connection.
5. The attacker then attempts to authenticate as a user who is only authorized from Host B.
6. Due to the bug in _match_known_hosts, the server's internal state still considers the connection "trusted" because Host A's key was accepted, or the logic fails to strictly bind the current authentication attempt to the specific host key required for the user's authorization.
7. Authentication succeeds.
Illustrative PoC (Conceptual):
Note: This is a conceptual representation. Actual exploitation requires a custom SSH client that can manipulate the host key presentation sequence or exploit the state accumulation bug. Standard ssh clients do not easily allow presenting multiple host keys in a single authentication flow in this manner.
# Conceptual Python PoC using AsyncSSH client (illustrative)
import asyncio
import asyncssh
async def exploit():
# Attacker has private key for Host A (trusted)
# Target user is only authorized from Host B
# Step 1: Connect and present Host A's key
# In a real attack, the attacker might need to force the server to
# accept Host A's key first, then attempt user auth for a Host B-only user.
# This is highly dependent on the specific implementation of the server's
# authentication flow. The bug implies that once a host key is trusted,
# subsequent auth attempts might bypass strict host matching.
try:
conn = await asyncssh.connect(
'target_ip',
username='victim_user', # User authorized only from Host B
client_keys=['host_a_private_key.pem'], # Presenting Host A's key
known_hosts=None # Disable client-side host verification for testing
)
print("[+] Authentication successful despite host mismatch!")
await conn.close()
except asyncssh.DisconnectError as e:
print(f"[-] Failed: {e}")
asyncio.run(exploit())Important: The exact exploitation may require a custom SSH client that can send multiple host key authentication attempts in a specific sequence to trigger the state accumulation bug. Standard ssh clients typically present one host key per attempt.
3. Post-Exploitation
victim_user.victim_user has sudo privileges or is part of a privileged group, the attacker can escalate to root.🌍 Real World Impact
Practical Consequences:
Bypass of Host-Based Restrictions: Organizations that rely on host-based authentication (e.g., "only allow access from the build server") can be bypassed if an attacker compromises the private key of any* other trusted host.
trust_client_host is enabled and the bug is present.🛡️ Remediation & Mitigation
1. Upgrade
AsyncSSH 1.13.1 prior to 2.24.2.AsyncSSH version 2.24.2 or later.pip install --upgrade asyncssh2. Workarounds
trust_client_host: If host-based authentication is not strictly required, disable trust_client_host in the server configuration. This is the most effective mitigation.# In AsyncSSH server configuration
server = asyncssh.SSHServer(
host_keys=['server_host_key.pem'],
trust_client_host=False # Disable host-based authentication
)iptables or cloud security groups) to limit the attack surface.3. Detection
Accepted publickey for victim_user from 192.168.1.100 port 54321 ssh2: RSA SHA256:HostAKeyFingerprintIf victim_user is only authorized from Host B, this is a potential indicator of exploitation.
⚠️ Urgency
trust_client_host enabled, possession of a trusted host's private key, and knowledge of the bug).Patching Priority: Medium-High
trust_client_host is enabled in your environment, upgrade to AsyncSSH 2.24.2 immediately. The risk is significant if you rely on host-based authentication for access control.trust_client_host is disabled: The risk is low, but upgrading is still recommended as part of regular patch management.FOFA Query