text stringlengths 0 1.99k |
|---|
So, after the fork(), we're still able to access that content. |
----[ 6.4 - Other leaks |
Besides leaking /etc/shadow from a libc buffer, another interesting library |
to sneak on is libnss. |
If mod_sftp was loaded, you could poke around libcrypt and retrieve the |
private key. I didn't go through mod_sftp so I don't know if buffers are |
clean/freed. |
Also, ProFTPd likes power and doesn't give it up completely. Based on the |
timeout set during compilation, it runs a routine where it rescues root |
privileges. In this way, ProFTPd switches from a process running as |
"nobody" to "root". This seems to be required due to users login purposes, |
but it might bring some opportunity as well to find some secrets. |
--[ 7 - Ideas for future work |
I think the most reliable approach here would be to find a structure within |
the same memory page and use a partial overwrite, building an exploitation |
strategy from there. The best option is to avoid using /proc/self/maps. |
First, ProFTPd is a program that implements many network functions. |
Therefore, it seems wasteful not to leverage its own code to gain control |
of execution, rather than injecting shellcode. Depending on the loaded |
modules, this method could be quite effective. |
There are a couple of aspects of this exploit that could be improved. |
Typically, an FTP service runs in a chrooted environment, so accessing |
other directories would not be possible. |
The following config is normally turned on production FTP environments: |
# To cause every FTP user to be "jailed" (chrooted) into their home |
# directory, uncomment this line. |
#DefaultRoot ~ |
Second, we should avoid relying on mod_copy to obtain the server's memory |
layout (even though, as mentioned above, downloading /proc/self/maps would |
be impossible if the server is chrooted, even with mod_copy loaded). |
It might be easier to find a leak on the stack than to brute-force the heap |
space. Also, the value of resp_pool is copied onto the stack, so we just |
need to find its offset (though there are many complications, such as |
locating a libc reference). |
It may also be possible to combine the libc stack with ProFTPd's. This may |
extend not only to the stack, but also to the heap, though guessing the |
location would be more difficult. Additionally, depending on compilation |
options, there may be stack canaries and other mitigations to bypass. |
Finally, since the FTP commands we send are executed by the server, there |
is a possibility of using other FTP commands to facilitate exploitation. |
Even though some commands check for an existing connection, some do not. |
--[ 8 - Notes on ProFTPd architecture |
----[ 8.1 - fork() consequences |
There are some consequences of forking from the root process. One could |
read mod_auth_unix.c:502 and redirect error messages to the memory buffer |
used by getspnam(). The idea is to read the cryptograms from /etc/shadow. |
From Phrack 67/7: |
"In case of PIE, it would be feasible to brute force the randomisation as |
ProFTPD fork()s for each client connection. In order to make the most of |
ASLR, ProFTPD would have to fork+execve() itself, or be configured to use |
xinetd/inetd (which would probably be a significant performance problem |
on busy sites). Using fork+execve() would be the best approach as it |
would require least changes by the user except an update to ProFTPd." |
----[ 8.2 - getspnam() underlying issues |
The function getspnam() and its re-entrant counterpart getspnam_r() do not |
clear the contents of allocated memory before returning to the user. |
Apparently, this behavior is intentional, likely as a caching mechanism. |
The problem is that ProFTPd does not wipe the libc heap, resulting in a |
leak of sensitive content. |
From my tests, it does not matter whether the developer uses getspnam_r(), |
which takes a user-controlled buffer, instead of getspnam(), because the |
function allocates its own buffer internally. Apparently, this buffer is |
shared among this family of functions, specifically, the `respbuf` that |
stores file contents. |
I consider this an info leak vulnerability. When ProFTPd starts, it forks |
from a privileged process and calls getspnam(). If there is an exploitable |
vulnerability in a program that uses these functions, the attacker could |
take advantage of this. |
Note that getspnam() is a wrapper around __getspnam_r(). |
libc should free() memory when the user explicitly says that he or she is |
done processing passwords, i.e. when invoking endspent(). I've created a |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.