text
stringlengths
0
1.99k
|=----------------------------=[ by dukpt ]=----------------------------=|
|=-----------------------------------------------------------------------=|
--[ Table of contents
0 - First words
1 - Introduction
2 - Previous work on ProFTPd
3 - Context and limitations
3.1 - Notes on ProFTPd compilation
4 - Analysis of ProFTPd internals
5 - Vulnerability analysis
5.1 - Exploitation details
5.2 - Defining exploitation strategy
5.3 - Execution and offsets control
5.4 - Leaking memory layout
5.5 - Final RIP control methodology
6 - Other exploitation strategies
6.1 - Kill the Gibson: causing a DoS
6.2 - Using the stack
6.3 - Leaking /etc/shadow
6.4 - Other leaks
7 - Ideas for future work
8 - Notes on ProFTPd architecture
8.1 - fork() consequences
8.2 - getspnam() underlying issues
9 - Conclusion
10 - References
11 - Exploit source code
--[ 0 - First words
This article was originally written four years ago. Well, about 80% of it.
I never got around to finishing it, so it remained unpublished. When I quit
my job and started something new, I finally found the motivation (or time)
to complete it. I hope this time of waiting hasn't dimmed your interest in
this article, and that you'll still discover something intriguing to
contribute to your hacking skills.
--[ 1 - Introduction
ProFTPd is a highly configurable FTP daemon for Unix-like operating systems.
For a long time, it has been the primary choice for FTP servers around the
world, and it is still widely used across many systems. Currently, there is
no support for native execution under Microsoft Windows [1].
In this paper, we're going to discuss a vulnerability in the way ProFTPd
handles memory allocation for the response to the current command being
processed during a data transfer. As we'll see, exploiting this
vulnerability requires certain conditions that may not be commonly found in
production FTP servers, although triggering it is relatively simple.
Credits to Antonio Morales from GitHub Security Lab for discovering both
vulnerabilities: the use-after-free on the heap (CVE-2020-9273) [2], and the
out-of-bounds read in mod_cap.c (CVE-2020-9272) [3]. The reader is also
encouraged to check ProFTPd issue #903 [4] for more details.
In this article, I'll be focusing only on the use-after-free bug, and I'll
avoid the out-of-bounds read during the exploitation phases.
It's also important to mention that this article follows a learning-oriented
approach. I'll try to be as didactic as possible so that readers can
reproduce the steps on their own. This approach might also be interesting
for people who want to get more familiar with gdb. We'll be using the GEF
(GDB Enhanced Features) framework, but I won't be exploring many of GEF's
great features - maybe in a future article :)
--[ 2 - Previous work on ProFTPd
Before going any further, it's important to mention that there's plenty of
work on ProFTPd already. Here I enumerate some of the most interesting:
1) CVE-2003-0831 - heap buffer overflow [5];
2) CVE-2010-4221 - stack-based buffer overflows [6];
3) CVE-2010-4652 - heap buffer overflow [7]; I'd recommend the reader
take some time reading FelineMenace's paper on Phrack issue 67 [8]
on exploiting a heap overflow on mod_sql of ProFTPd. Coincidentally,
we use the same exploitation approach by abusing cleanup structure
(it's probably the best option because we control the parameters and
the function called, so it's perfect for stack pivoting);
4) CVE-2011-4130 - an use-after-free memory corruption [9];
5) CVE-2015-3306 - this infamous vulnerability allows unauthenticated
users to abuse mod_copy by sending SITE CPFR / CPTO commands [10].
It also popped on reddit [11];
6) CVE-2020-9273 - this use-after-free in the heap.
Of course there are more, but these are the ones with more impact IMHO.
--[ 3 - Context and limitations
In this chapter we're going to see the conditions to exploit this
vulnerability and understand some details about ProFTPd. Finally, we'll
analyze how to trigger this bug and draft an exploitation path.
This is a post-auth vulnerability, which means that the attacker must have