OpenSSH 6.6 and earlier SFTP misconfiguration exploit for 64-bit Linux
When OpenSSH's SFTP server is configured with ForceCommand internal-sftp but without ChrootDirectory, a restricted user can still read and write procfs files such as /proc/self/maps and /proc/self/mem. By combining the memory layout with arbitrary memory writes, the user can achieve remote code execution on 64-bit Linux.
seclists.org
Published on seclists.org
// THIS PROGRAM IS NOT DESIGNED TO BE SAFE AGAINST VICTIM MACHINES THAT // TRY TO ATTACK BACK, THE CODE IS SLOPPY! // (In other words, please don't use this against other people's machines.)
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the SFTP server process was not confined to a chroot and was allowed to access procfs, exposing /proc/self/maps and /proc/self/mem to the restricted user.
Impact
A user who should only have SFTP access could execute arbitrary commands on the server; OpenSSH 6.7 added a mitigation that blocks access to /proc/self/mem and /proc/self/maps.
What the attacker needed
SFTP access without ChrootDirectory; Linux kernel 2.6.39 or later; Valid credentials for the SFTP user
The fix
The server should be configured with ChrootDirectory, and OpenSSH 6.7 and later mitigate the issue by preventing sftp-server from accessing /proc/self/mem and /proc/self/maps.
How it was found
- Connect to the target over SSH and authenticate as the restricted SFTP user.
- Start an SFTP session and read /proc/self/maps to find the libc mapping and the stack range.
- Download the mapped libc file and locate the system function and a suitable gadget.
- Open /proc/self/mem for writing and overwrite the stack with shell commands and a small ROP chain.
- Let the corrupted stack return into system to execute the commands.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
SFTP is a way to transfer files over SSH. Administrators sometimes use it to give users file access without a full shell. If the server is not locked into a single folder, the user can reach special system files that describe and even change the running program's memory, which lets them run their own commands.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.