Skip to content
Memory corruption Write-up Advanced

Exploiting A Remote Heap Overflow With A Custom TCP Stack

The Netatalk AFP daemon's DSI layer copied client-controlled data from a look-ahead buffer into a fixed 64KB reply buffer without honouring the size limit, letting an unauthenticated attacker overflow the tail of the connection struct. By corrupting the datalen field the attacker could make the server leak heap memory and, with a custom TCP stack to force the vulnerable path, achieve remote code execution as root.

Etienne Helluy-Lafont Follow

Published on synacktiv.com

Rédigé par Etienne Helluy-Lafont, Luca Moro - 13/02/2023 - dans Exploit - Téléchargement

Etienne Helluy-Lafont, Luca Moro (@johncool__), on synacktiv.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the reply-flush routine used the client-supplied DSI length to decide how many bytes to copy but ignored the destination buffer's size, so a look-ahead buffer larger than the 64KB reply buffer overflowed the inlined data array and the struct fields after it.

Impact

An unauthenticated attacker on the adjacent network could leak heap and binary pointers to defeat ASLR and then corrupt the connection struct to achieve remote code execution as root on the device, though the exploit relies on a custom TCP stack and a same-network position.

What the attacker needed

Attacker on the adjacent network; no authentication needed; custom TCP stack to stall the server; attacker kernel must not send RST packets

How it was found

  1. Open a session by sending a DSI OpenSession request.
  2. Send a large batch of DSI command requests using the logout function so the server enters the reply path.
  3. Advertise a zero TCP window and stop acknowledging the server's replies so its send blocks and it falls into the peek routine.
  4. Send an invalid DSI command whose declared length and payload exceed 64KB so it is buffered by the peek routine.
  5. Send a further raw block larger than 64KB, which is consumed by the flush routine and overflows the reply buffer and struct tail.
  6. Resume acknowledging replies and advertising a normal window so the queued commands are processed and the overflow is triggered.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

The file-sharing service kept a small holding area for incoming network data and, when replying, copied that data into a fixed-size buffer without checking how much would fit. Anything beyond the buffer spilled into neighbouring fields of the program's own bookkeeping structure. An attacker who could make the server hold more than the buffer's size could then control those fields, read back memory and eventually run their own code on the device.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from Western Digital

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.